From 1682dd98acc6b9c9af392277ecca03be5419936e Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Sat, 4 Nov 2023 10:05:11 +0100 Subject: [PATCH] convert dot-less CentOS versions to X.999 CentOS Stream doesn't do dot releases, so it always has the major version in the version_id field of os-release. Our code, in multiple places, expects versions in the form X.Y and doesn't cope well when given only X. The value "999" is taken arbitrarily, with the sole assumption that it will be always higher than any RHEL release, as CentOS Stream is ahead of RHEL. See https://issues.redhat.com/browse/CS-1757 for further discussion and alternative numbering options. --- .../libraries/ipuworkflowconfig.py | 8 ++++++-- .../tests/files/os-release-stream8 | 13 +++++++++++++ .../tests/test_ipuworkflowconfig.py | 11 +++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 repos/system_upgrade/common/actors/ipuworkflowconfig/tests/files/os-release-stream8 diff --git a/repos/system_upgrade/common/actors/ipuworkflowconfig/libraries/ipuworkflowconfig.py b/repos/system_upgrade/common/actors/ipuworkflowconfig/libraries/ipuworkflowconfig.py index 9e213f644c..5493119809 100644 --- a/repos/system_upgrade/common/actors/ipuworkflowconfig/libraries/ipuworkflowconfig.py +++ b/repos/system_upgrade/common/actors/ipuworkflowconfig/libraries/ipuworkflowconfig.py @@ -50,12 +50,16 @@ def get_os_release(path): try: with open(path) as f: data = dict(l.strip().split('=', 1) for l in f.readlines() if '=' in l) + release_id = data.get('ID', '').strip('"') + version_id = data.get('VERSION_ID', '').strip('"') + if release_id == 'centos' and '.' not in version_id: + version_id = "{}.999".format(version_id) return OSRelease( - release_id=data.get('ID', '').strip('"'), + release_id=release_id, name=data.get('NAME', '').strip('"'), pretty_name=data.get('PRETTY_NAME', '').strip('"'), version=data.get('VERSION', '').strip('"'), - version_id=data.get('VERSION_ID', '').strip('"'), + version_id=version_id, variant=data.get('VARIANT', '').strip('"') or None, variant_id=data.get('VARIANT_ID', '').strip('"') or None ) diff --git a/repos/system_upgrade/common/actors/ipuworkflowconfig/tests/files/os-release-stream8 b/repos/system_upgrade/common/actors/ipuworkflowconfig/tests/files/os-release-stream8 new file mode 100644 index 0000000000..8948e12f4a --- /dev/null +++ b/repos/system_upgrade/common/actors/ipuworkflowconfig/tests/files/os-release-stream8 @@ -0,0 +1,13 @@ +NAME="CentOS Stream" +VERSION="8" +ID="centos" +ID_LIKE="rhel fedora" +VERSION_ID="8" +PLATFORM_ID="platform:el8" +PRETTY_NAME="CentOS Stream 8" +ANSI_COLOR="0;31" +CPE_NAME="cpe:/o:centos:centos:8" +HOME_URL="https://centos.org/" +BUG_REPORT_URL="https://bugzilla.redhat.com/" +REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux 8" +REDHAT_SUPPORT_PRODUCT_VERSION="CentOS Stream" diff --git a/repos/system_upgrade/common/actors/ipuworkflowconfig/tests/test_ipuworkflowconfig.py b/repos/system_upgrade/common/actors/ipuworkflowconfig/tests/test_ipuworkflowconfig.py index a5e4d03bcd..a9369bedca 100644 --- a/repos/system_upgrade/common/actors/ipuworkflowconfig/tests/test_ipuworkflowconfig.py +++ b/repos/system_upgrade/common/actors/ipuworkflowconfig/tests/test_ipuworkflowconfig.py @@ -63,6 +63,17 @@ def test_get_os_release_info(monkeypatch): ipuworkflowconfig.get_os_release(os.path.join(CUR_DIR, 'files/non-existent-file')) +def test_get_os_release_info_centos_stream(monkeypatch): + expected = OSRelease( + release_id='centos', + name='CentOS Stream', + pretty_name='CentOS Stream 8', + version='8', + version_id='8.999' + ) + assert expected == ipuworkflowconfig.get_os_release(os.path.join(CUR_DIR, 'files/os-release-stream8')) + + def test_get_booted_kernel(monkeypatch): monkeypatch.setattr(ipuworkflowconfig, 'run', lambda x: {'stdout': '4.14.0-100.8.2.el7a.x86_64\n'}) assert ipuworkflowconfig.get_booted_kernel() == '4.14.0-100.8.2.el7a.x86_64'