Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update anaconda variables source #6129

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pyanaconda/core/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_product_values():
Order of precedence for the values is:
1) Buildstamp file specified by the PRODBUILDPATH environment variable
2) Buildstamp file /.buildstamp
3) Environment variable ANACONDA_ISFINAL
3) ANACONDA_ISFINAL based on /etc/os-release RELEASE_TYPE field
4) In absence of any data, fall back to "false"

:return: Data about product
Expand All @@ -80,7 +80,16 @@ def get_product_values():
# .buildstamp, environment, stupid last ditch hardcoded defaults.
config = configparser.ConfigParser()
config.add_section("Main")
config.set("Main", "IsFinal", os.environ.get("ANACONDA_ISFINAL", "false"))

# Get IsFinal property from /etc/os-release file
with open('/etc/os-release') as file:
for line in file:
key, value = line.split('=')
value = value.strip()
if key == 'RELEASE_TYPE':
config.set("Main", "IsFinal", str(value in {'release', 'stable'}))
os.environ["ANACONDA_ISFINAL"] = str(value in {'release', 'stable'})

config.set("Main", "Product", os.environ.get("ANACONDA_PRODUCTNAME", "anaconda"))
config.set("Main", "Version", os.environ.get("ANACONDA_PRODUCTVERSION", "bluesky"))

Expand Down
12 changes: 11 additions & 1 deletion tests/unit_tests/pyanaconda_tests/core/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,17 @@ def test_buildstamp_multiple(self, mock_cfp_open):
@patch("pyanaconda.core.product.configparser.open", side_effect=FileNotFoundError)
def test_env(self, mock_cfp_open):
"""Test product values loaded from environment variables."""
values = get_product_values()
# ANACONDA_ISFINAL variable is processed out of /etc/os-release host file
FAKE_OS_RELEASE = ""
FAKE_OS_RELEASE += 'NAME="Fedora Linux"\n'
FAKE_OS_RELEASE += 'VERSION="41 (Workstation Edition)"\n'
FAKE_OS_RELEASE += 'RELEASE_TYPE=stable\n'
FAKE_OS_RELEASE += 'ID=fedora\n'

m = mock_open(read_data=FAKE_OS_RELEASE)
with patch("builtins.open", m):
values = get_product_values()

expected = ProductData(True, "TestProduct", "rawhide", "testproduct")
assert values == expected

Expand Down
Loading