Skip to content

Commit

Permalink
convert dot-less CentOS versions to X.999
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
evgeni committed Feb 19, 2024
1 parent 6421225 commit c272dc7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit c272dc7

Please sign in to comment.