From 5bdfc7af5b5f4b8ac65a6cbecab2220ad294b32e Mon Sep 17 00:00:00 2001 From: Mikhail Sandakov Date: Thu, 2 May 2024 11:02:37 +0300 Subject: [PATCH] Added a function to check if the repository endpoint is none Leapp is not able to handle these types of repositories, so we should refrain from adding them. --- pleskdistup/common/src/rpm.py | 14 ++++++++++++++ pleskdistup/common/tests/rpmtests.py | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/pleskdistup/common/src/rpm.py b/pleskdistup/common/src/rpm.py index cba6608..7ade427 100644 --- a/pleskdistup/common/src/rpm.py +++ b/pleskdistup/common/src/rpm.py @@ -216,3 +216,17 @@ def upgrade_packages(pkgs: typing.Optional[typing.List[str]] = None) -> None: def autoremove_outdated_packages() -> None: util.logged_check_call(["/usr/bin/yum", "autoremove", "-y"]) + + +def repository_has_none_link( + id: typing.Optional[str], + name: typing.Optional[str], + url: typing.Optional[str], + metalink: typing.Optional[str], + mirrorlist: typing.Optional[str] +) -> bool: + for link in (url, metalink, mirrorlist): + if link is not None and link.lower() == "none": + return True + + return False diff --git a/pleskdistup/common/tests/rpmtests.py b/pleskdistup/common/tests/rpmtests.py index 2f37919..52c88b6 100644 --- a/pleskdistup/common/tests/rpmtests.py +++ b/pleskdistup/common/tests/rpmtests.py @@ -377,3 +377,23 @@ def test_handle_whole_directory(self): self.assertEqual(open(full_filepath).read(), content) shutil.rmtree(self.test_dir) + + +class repositoryHasNoneLinkTest(unittest.TestCase): + def test_no_link(self): + self.assertFalse(rpm.repository_has_none_link(None, None, None, None, None)) + + def test_url(self): + self.assertTrue(rpm.repository_has_none_link("id", "name", "none", None, None)) + + def test_metalink(self): + self.assertTrue(rpm.repository_has_none_link("id", "name", None, "none", None)) + + def test_mirrorlist(self): + self.assertTrue(rpm.repository_has_none_link("id", "name", None, None, "none")) + + def test_all(self): + self.assertTrue(rpm.repository_has_none_link("id", "name", "none", "none", "none")) + + def test_links_are_fine(self): + self.assertFalse(rpm.repository_has_none_link("id", "name", "url", "metalink", "mirrorlist"))