From 02314de22b545e3492fcb3fd0532768a4e6fbc28 Mon Sep 17 00:00:00 2001 From: Mikhail Sandakov Date: Wed, 24 Jul 2024 17:05:02 +0300 Subject: [PATCH] support for parsing versions of kernels installed from the Linode repository --- pleskdistup/common/src/version.py | 9 ++++++++- pleskdistup/common/tests/versiontests.py | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pleskdistup/common/src/version.py b/pleskdistup/common/src/version.py index 84d8f42..db167a9 100644 --- a/pleskdistup/common/src/version.py +++ b/pleskdistup/common/src/version.py @@ -53,6 +53,11 @@ def _extract_no_build(self, version: str) -> None: if self.patch == "": self.patch = "0" + def _extract_linode_kernel_version(self, version: str) -> None: + self.build = "" + main_part, self.arch, *_ = version.split("-") + self.major, self.minor, self.patch = main_part.split(".") + def _remove_prefix(self, version: str) -> str: while not version[0].isdigit(): version = version.split("-", 1)[-1] @@ -68,7 +73,9 @@ def __init__(self, version: str): self.arch = "" version = self._remove_prefix(version) - if "-" in version: + if "-linode" in version: + self._extract_linode_kernel_version(version) + elif "-" in version: self._extract_with_build(version) else: self._extract_no_build(version) diff --git a/pleskdistup/common/tests/versiontests.py b/pleskdistup/common/tests/versiontests.py index 88a15ad..44fdd55 100644 --- a/pleskdistup/common/tests/versiontests.py +++ b/pleskdistup/common/tests/versiontests.py @@ -43,6 +43,9 @@ 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_linode_kernel_parse(self): + self._check_parse("6.2.9-x86_64-linode160", "6.2.9.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")