Skip to content

Commit 68e286f

Browse files
matejmatuskapirat89
authored andcommitted
lib/kernel: Fix rt kernel detection on centos
The kernel detection function determine_kernel_type_from_uname() didn't take major-only versions as used for CentOS Stream into account and therefore it misidentified rt kernels as "ordinary" on CentOS Stream systems. The function is modified to use matches_version() from the version lib which already handles the versions comparison for CentOS Stream as. Jira: RHEL-161560
1 parent 83a3b58 commit 68e286f

3 files changed

Lines changed: 49 additions & 17 deletions

File tree

repos/system_upgrade/common/libraries/config/version.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,19 @@ def matches_version(match_list, detected):
171171
"""
172172
Check if the `detected` version meets the criteria specified in `match_list`.
173173
174+
For CentOS Stream (which natively uses only major versions), the match list
175+
and the detected version are automatically adjusted to ensure intuitive evaluation:
176+
177+
- If `match_list` contains only major versions, the comparison is restricted
178+
to the major version component:
179+
version.matches_version(['> 8', '<= 9'], '9.5') # True
180+
181+
- If `match_list` contains major.minor versions but `detected` is a major-only
182+
version, the function resolves the input to its defined "virtual version"
183+
before evaluation:
184+
# e.g., if the virtual version for '9' is defined as '9.5'
185+
version.matches_version(['> 8.10', '<= 9.7'], '9') # True
186+
174187
:param match_list: specification of versions to check against
175188
:type match_list: list or tuple of strings in one of the two following forms:
176189
``['>'|'>='|'<'|'<='] <integer>.<integer>`` form, where elements are ANDed,

repos/system_upgrade/common/libraries/kernel.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import namedtuple
22

33
from leapp.exceptions import StopActorExecutionError
4+
from leapp.libraries.common.config.version import matches_version
45
from leapp.libraries.stdlib import api, CalledProcessError, run
56

67
KernelPkgInfo = namedtuple('KernelPkgInfo', ('name', 'version', 'release', 'arch', 'nevra'))
@@ -14,6 +15,8 @@ class KernelType:
1415
REALTIME = 'realtime'
1516

1617

18+
# TODO: rename rhel_version to something distro agnostic in the new function
19+
# when this is deprecated
1720
def determine_kernel_type_from_uname(rhel_version, kernel_uname_r):
1821
"""
1922
Determine kernel type from given kernel release (uname-r).
@@ -23,12 +26,7 @@ def determine_kernel_type_from_uname(rhel_version, kernel_uname_r):
2326
:returns: Kernel type based on a given uname_r
2427
:rtype: KernelType
2528
"""
26-
version_fragments = rhel_version.split('.')
27-
major_ver = version_fragments[0]
28-
minor_ver = version_fragments[1] if len(version_fragments) > 1 else '0'
29-
rhel_version = (major_ver, minor_ver)
30-
31-
if rhel_version <= ('9', '2'):
29+
if matches_version(['<= 9.2'], rhel_version):
3230
uname_r_infixes = {
3331
'.rt': KernelType.REALTIME
3432
}

repos/system_upgrade/common/libraries/tests/test_kernel_lib.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,44 @@
55
from leapp.exceptions import StopActorExecutionError
66
from leapp.libraries.common import kernel as kernel_lib
77
from leapp.libraries.common.kernel import KernelType
8+
from leapp.libraries.common.testutils import CurrentActorMocked
9+
from leapp.libraries.stdlib import api
810

911

1012
@pytest.mark.parametrize(
11-
('rhel_version', 'uname_r', 'expected_kernel_type'),
13+
('version', 'uname_r', 'expected_kernel_type'),
1214
(
13-
('7.9', '3.10.0-1160.el7.x86_64', KernelType.ORDINARY),
14-
('7.9', '3.10.0-1160.rt56.1131.el7.x86_64', KernelType.REALTIME),
15-
('8.7', '4.18.0-425.3.1.el8.x86_64', KernelType.ORDINARY),
16-
('8.7', '4.18.0-425.3.1.rt7.213.el8.x86_64', KernelType.REALTIME),
17-
('9.2', '5.14.0-284.11.1.el9_2.x86_64', KernelType.ORDINARY),
18-
('9.2', '5.14.0-284.11.1.rt14.296.el9_2.x86_64', KernelType.REALTIME),
19-
('9.3', '5.14.0-354.el9.x86_64', KernelType.ORDINARY),
20-
('9.3', '5.14.0-354.el9.x86_64+rt', KernelType.REALTIME),
15+
# (version, virtual_version)
16+
(('7.9', None), '3.10.0-1160.el7.x86_64', KernelType.ORDINARY),
17+
(('7.9', None), '3.10.0-1160.rt56.1131.el7.x86_64', KernelType.REALTIME),
18+
(('8.7', None), '4.18.0-425.3.1.el8.x86_64', KernelType.ORDINARY),
19+
(('8.7', None), '4.18.0-425.3.1.rt7.213.el8.x86_64', KernelType.REALTIME),
20+
(('9.2', None), '5.14.0-284.11.1.el9_2.x86_64', KernelType.ORDINARY),
21+
(('9.2', None), '5.14.0-284.11.1.rt14.296.el9_2.x86_64', KernelType.REALTIME),
22+
(('9.3', None), '5.14.0-354.el9.x86_64', KernelType.ORDINARY),
23+
(('9.3', None), '5.14.0-354.el9.x86_64+rt', KernelType.REALTIME),
24+
# centos
25+
(('8', '8.7'), '4.18.0-425.3.1.el8.x86_64', KernelType.ORDINARY),
26+
(('8', '8.7'), '4.18.0-425.3.1.rt7.213.el8.x86_64', KernelType.REALTIME),
27+
(('9', '9.2'), '5.14.0-284.11.1.el9_2.x86_64', KernelType.ORDINARY),
28+
(('9', '9.2'), '5.14.0-284.11.1.rt14.296.el9_2.x86_64', KernelType.REALTIME),
29+
(('9', '9.3'), '5.14.0-354.el9.x86_64', KernelType.ORDINARY),
30+
(('9', '9.3'), '5.14.0-354.el9.x86_64+rt', KernelType.REALTIME),
2131
)
2232
)
23-
def test_determine_kernel_type_from_uname(rhel_version, uname_r, expected_kernel_type):
24-
kernel_type = kernel_lib.determine_kernel_type_from_uname(rhel_version, uname_r)
33+
def test_determine_kernel_type_from_uname(monkeypatch, version, uname_r, expected_kernel_type):
34+
real_ver, virtual_ver = version
35+
# needed to for lookups of virtual versions in matches_version
36+
actor_mock = CurrentActorMocked(
37+
release_id='centos' if '.' not in real_ver else 'rhel',
38+
src_ver=real_ver,
39+
dst_ver="irrelevant",
40+
virtual_source_version=virtual_ver or real_ver,
41+
virtual_target_version="irrelevant",
42+
)
43+
monkeypatch.setattr(api, 'current_actor', actor_mock)
44+
45+
kernel_type = kernel_lib.determine_kernel_type_from_uname(real_ver, uname_r)
2546
assert kernel_type == expected_kernel_type
2647

2748

0 commit comments

Comments
 (0)