From d7012c442a69f7c4d3557d807abf8ae0effe6807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 26 Apr 2016 14:41:39 +0200 Subject: [PATCH] [pkgset] Simplify finding RPM in koji buildroot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lubomír Sedlář --- pungi/phases/pkgset/pkgsets.py | 28 +++++++++------------------- tests/test_pkgset_pkgsets.py | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/pungi/phases/pkgset/pkgsets.py b/pungi/phases/pkgset/pkgsets.py index 8091a9d5..83917736 100644 --- a/pungi/phases/pkgset/pkgsets.py +++ b/pungi/phases/pkgset/pkgsets.py @@ -230,8 +230,6 @@ class KojiPackageSet(PackageSetBase): def get_package_path(self, queue_item): rpm_info, build_info = queue_item - rpm_path = None - found = False pathinfo = self.koji_wrapper.koji_module.pathinfo paths = [] for sigkey in self.sigkey_ordering: @@ -242,25 +240,17 @@ class KojiPackageSet(PackageSetBase): rpm_path = os.path.join(pathinfo.build(build_info), pathinfo.signed(rpm_info, sigkey)) paths.append(rpm_path) if os.path.isfile(rpm_path): - found = True - break + return rpm_path - if not found: - if None in self.sigkey_ordering: - # use an unsigned copy (if allowed) - rpm_path = os.path.join(pathinfo.build(build_info), pathinfo.rpm(rpm_info)) - paths.append(rpm_path) - if os.path.isfile(rpm_path): - found = True - else: - # or raise an exception - raise RuntimeError("RPM %s not found for sigs: %s. Paths checked: %s" - % (rpm_info, self.sigkey_ordering, paths)) + if None in self.sigkey_ordering: + # use an unsigned copy (if allowed) + rpm_path = os.path.join(pathinfo.build(build_info), pathinfo.rpm(rpm_info)) + paths.append(rpm_path) + if os.path.isfile(rpm_path): + return rpm_path - if not found: - raise RuntimeError("Package not found: %s. Paths checked: %s" - % (rpm_info, paths)) - return rpm_path + raise RuntimeError("RPM %s not found for sigs: %s. Paths checked: %s" + % (rpm_info, self.sigkey_ordering, paths)) def populate(self, tag, event=None, inherit=True): result_rpms = [] diff --git a/tests/test_pkgset_pkgsets.py b/tests/test_pkgset_pkgsets.py index 4e297473..488bc3e0 100755 --- a/tests/test_pkgset_pkgsets.py +++ b/tests/test_pkgset_pkgsets.py @@ -225,6 +225,32 @@ class TestKojiPkgset(PkgsetCompareMixin, helpers.PungiTestCase): {'x86_64': ['rpms/bash-debuginfo@4.3.42@4.fc24@x86_64', 'signed/cafebabe/bash@4.3.42@4.fc24@x86_64']}) + def test_can_not_find_signed_package(self): + pkgset = pkgsets.KojiPackageSet(self.koji_wrapper, ['cafebabe'], arches=['x86_64']) + + with self.assertRaises(RuntimeError) as ctx: + pkgset.populate('f25') + + self.assertEqual( + self.koji_wrapper.koji_proxy.mock_calls, + [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) + + self.assertRegexpMatches(str(ctx.exception), + r'^RPM .+ not found for sigs: .+ Paths checked: .+$') + + def test_can_not_find_any_package(self): + pkgset = pkgsets.KojiPackageSet(self.koji_wrapper, ['cafebabe', None], arches=['x86_64']) + + with self.assertRaises(RuntimeError) as ctx: + pkgset.populate('f25') + + self.assertEqual( + self.koji_wrapper.koji_proxy.mock_calls, + [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) + + self.assertRegexpMatches(str(ctx.exception), + r'^RPM .+ not found for sigs: .+ Paths checked: .+$') + @mock.patch('kobo.pkgset.FileCache', new=MockFileCache) class TestMergePackageSets(PkgsetCompareMixin, unittest.TestCase):