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

Handle kernel versions with '_' before build number #15

Merged
merged 1 commit into from
Mar 13, 2024
Merged
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
7 changes: 7 additions & 0 deletions pleskdistup/common/src/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def _extract_with_build(self, version: str) -> None:

self.major, self.minor, self.patch = main_part.split(".")

# Sometimes packages split patch and build with "_", which looks
# really weird.
if "_" in self.patch:
self.patch, self.build = self.patch.split("_")
self.distro, self.arch = secondary_part.split(".")
return

# Short format of kernel version without distro and arch mentioned
if secondary_part.isnumeric():
self.build = secondary_part
Expand Down
10 changes: 10 additions & 0 deletions pleskdistup/common/tests/versiontests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ def test_kernel_start_with_prefix(self):
def test_kernel_start_with_plus_prefix(self):
self._check_parse("kernel-plus-3.10.0-327.36.3.el7.centos.plus.x86_64", "3.10.0-327.36.3.el7.centos.plus.x86_64")

def test_kernel_with_underline(self):
kernel = version.KernelVersion("kernel-3.14.43_1-2.x86_64")
self.assertEqual(str(kernel), "3.14.43-1.2.x86_64")
self.assertEqual(kernel.major, "3")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to expand other tests in the same way later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase before merge.

self.assertEqual(kernel.minor, "14")
self.assertEqual(kernel.patch, "43")
self.assertEqual(kernel.build, "1")
self.assertEqual(kernel.distro, "2")
self.assertEqual(kernel.arch, "x86_64")

def test_kernel_parse_plus(self):
kernel = version.KernelVersion("3.10.0-327.36.3.el7.centos.plus.x86_64")
self.assertEqual(str(kernel), "3.10.0-327.36.3.el7.centos.plus.x86_64")
Expand Down