Skip to content

Commit

Permalink
Improved dkms status handling
Browse files Browse the repository at this point in the history
Only try to parse kernel information out of lines that have either
built or installed status
  • Loading branch information
jocave committed Aug 8, 2024
1 parent fd17448 commit 629277a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
13 changes: 8 additions & 5 deletions providers/sru/bin/dkms_build_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ def parse_dkms_status(dkms_status: str, ubuntu_release: str) -> List[Dict]:
kernel_info = []
for line in dkms_status.splitlines():
details, status = line.split(": ")
if version.parse(ubuntu_release) >= version.parse("22.04"):
kernel_ver = details.split(", ")[1]
else:
kernel_ver = details.split(", ")[2]
kernel_info.append({"version": kernel_ver, "status": status})
# will only get comma separated info on two statuses
# https://github.com/dell/dkms/blob/master/dkms.in#L1866
if status in ("built", "installed"):
if version.parse(ubuntu_release) >= version.parse("22.04"):
kernel_ver = details.split(", ")[1]
else:
kernel_ver = details.split(", ")[2]
kernel_info.append({"version": kernel_ver, "status": status})

sorted_kernel_info = sorted(
kernel_info, key=lambda x: parse_version(x["version"])
Expand Down
39 changes: 39 additions & 0 deletions providers/sru/tests/test_dkms_build_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ class TestDKMSValidation(unittest.TestCase):
"fwts/24.01.00, 6.5.0-15-generic, x86_64: installed"
)

# Example output of `dkms status` on machine
# in which efi_test driver is used rather than
# fwts dkms driver
# https://bugs.launchpad.net/fwts/+bug/2066243
dkms_status_efi_test_driver = (
"fwts-efi-runtime-dkms/24.07.00: added\n"
"tp_smapi/0.43, 6.1.0-1028-oem, x86_64: installed\n"
"tp_smapi/0.43, 6.1.0-1032-oem, x86_64: installed\n"
"tp_smapi/0.43, 6.1.0-1033-oem, x86_64: installed\n"
"tp_smapi/0.43, 6.1.0-1034-oem, x86_64: installed\n"
"tp_smapi/0.43, 6.1.0-1035-oem, x86_64: installed\n"
"tp_smapi/0.43, 6.5.0-1020-oem, x86_64: installed\n"
"tp_smapi/0.43, 6.5.0-1022-oem, x86_64: installed\n"
"tp_smapi/0.43, 6.5.0-1023-oem, x86_64: installed\n"
"tp_smapi/0.43, 6.5.0-1024-oem, x86_64: installed\n"
"tp_smapi/0.43, 6.5.0-1026-oem, x86_64: installed\n"
"tp_smapi/0.43, 6.8.0-40-generic, x86_64: installed"
)

sorted_kernel_info = [
{"version": "6.5.0-15-generic", "status": "installed"},
{"version": "6.5.0-17-generic", "status": "installed"},
Expand Down Expand Up @@ -60,6 +79,26 @@ def test_parse_dkms_status(self):
]
self.assertEqual(kernel_info, expected_kernel_info)

def test_parse_dkms_status_efi_test(self):
ubuntu_release = "22.04"
kernel_info = parse_dkms_status(
self.dkms_status_efi_test_driver, ubuntu_release
)
expected_kernel_info = [
{"version": "6.1.0-1028-oem", "status": "installed"},
{"version": "6.1.0-1032-oem", "status": "installed"},
{"version": "6.1.0-1033-oem", "status": "installed"},
{"version": "6.1.0-1034-oem", "status": "installed"},
{"version": "6.1.0-1035-oem", "status": "installed"},
{"version": "6.5.0-1020-oem", "status": "installed"},
{"version": "6.5.0-1022-oem", "status": "installed"},
{"version": "6.5.0-1023-oem", "status": "installed"},
{"version": "6.5.0-1024-oem", "status": "installed"},
{"version": "6.5.0-1026-oem", "status": "installed"},
{"version": "6.8.0-40-generic", "status": "installed"},
]
self.assertEqual(kernel_info, expected_kernel_info)

def test_parse_dkms_status_old(self):
old_dkms_status = (
"fwts, 24.01.00, 6.5.0-17-generic, x86_64: installed\n"
Expand Down

0 comments on commit 629277a

Please sign in to comment.