From a44d5abe4b9776cebc6d782ae86c986bfff58a63 Mon Sep 17 00:00:00 2001 From: David Negreira Date: Fri, 13 Sep 2024 13:11:04 +0000 Subject: [PATCH 1/2] fix debian and Ubuntu version detection This fixes an issue with the Debian version information where it was retrieving a number instead of the codename. This also fixes an issue where the version of Ubuntu was incomplete and it was retrieving only the first part of it, rather than the full version. Signed-off-by: David Negreira --- avocado/utils/distro.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avocado/utils/distro.py b/avocado/utils/distro.py index dcc25942c0..113b71907e 100644 --- a/avocado/utils/distro.py +++ b/avocado/utils/distro.py @@ -387,7 +387,7 @@ class DebianProbe(Probe): CHECK_FILE = "/etc/debian_version" CHECK_FILE_DISTRO_NAME = "debian" - CHECK_VERSION_REGEX = re.compile(r"(\d+)\.(\d+)") + CHECK_VERSION_REGEX = re.compile(r"(.+)/(.+)") class UbuntuProbe(Probe): @@ -399,7 +399,7 @@ class UbuntuProbe(Probe): CHECK_FILE_CONTAINS = "ubuntu" CHECK_FILE_DISTRO_NAME = "Ubuntu" CHECK_VERSION_REGEX = re.compile( - r".*VERSION_ID=\"(\d+)\.(\d+)\".*", re.MULTILINE | re.DOTALL + r".*VERSION_ID=\"(\d+\.\d+)\".*", re.MULTILINE | re.DOTALL ) From eff2add503f662353bf3ec3f54c352b536685248 Mon Sep 17 00:00:00 2001 From: David Negreira Date: Fri, 13 Sep 2024 13:17:27 +0000 Subject: [PATCH 2/2] Improve apt.test_provides unit test The unit test was failing on recent versions of Debian and Ubuntu because the `login` package is no longer installing the binary on `/bin/login` but rather on `/usr/bin/login`. We have added a function which will retrieve the binary path depending on the distro as well. Resolves: #6028 Signed-off-by: David Negreira --- selftests/unit/utils/software_manager.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/selftests/unit/utils/software_manager.py b/selftests/unit/utils/software_manager.py index e034b05ec7..7b21e60e16 100644 --- a/selftests/unit/utils/software_manager.py +++ b/selftests/unit/utils/software_manager.py @@ -13,12 +13,26 @@ def apt_supported_distro(): return distro.detect().name in ["debian", "Ubuntu"] +def login_binary_path(distro_name, distro_version): + """Retrieve the login binary path based on the distro version"""" + if distro_name == "Ubuntu": + if float(distro_version) >= 24.04: + return "/usr/bin/login" + if distro_name == "debian": + if distro_version == "trixie": + return "/usr/bin/login" + return "/bin/login" + + @unittest.skipUnless(os.getuid() == 0, "This test requires root privileges") @unittest.skipUnless(apt_supported_distro(), "Unsupported distro") class Apt(unittest.TestCase): def test_provides(self): sm = manager.SoftwareManager() - self.assertEqual(sm.provides("/bin/login"), "login") + distro_name = distro.detect().name + distro_version = distro.detect().version + login_path = login_binary_path(distro_name, distro_version) + self.assertEqual(sm.provides(login_path), "login") self.assertTrue(isinstance(sm.backend, backends.apt.AptBackend))