From fff14cd3f7349c04db0beb1f25dda30abfd88753 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Aug 06 2018 22:11:10 +0000 Subject: compose-has-build: check any epoch for an NVR Prior to this change, if a user specified a build NVR without an epoch to compose-has-build, then compose-has-build would assume an epoch value of "0". If the compose contained the build with a non-zero epoch, then compose-has-build would fail to find it. The problem is that Koji's BuildStateChange messages do not contain the epoch at all. Koji announces builds with plain NVRs, so we don't know what epoch value use. This means we cannot use compose-has-build with Koji's build announcement messages if the build has a non-zero epoch. Make compose-has-build match any epoch value in the compose. --- diff --git a/compose_utils/__init__.py b/compose_utils/__init__.py index 8d8946d..2f0d78a 100644 --- a/compose_utils/__init__.py +++ b/compose_utils/__init__.py @@ -13,14 +13,22 @@ from .copy_compose import copy_compose # noqa def look_for_build(compose, nvr): + """ + Look for a build NVR with any epoch. + """ parts = kobo.rpmlib.parse_nvr(nvr) - parts["epoch"] = parts["epoch"] or "0" - srpm_name = "{name}-{epoch}:{version}-{release}.src".format(**parts) + name = parts['name'] + version = parts['version'] + release = parts['release'] for variant in compose.rpms.rpms: for arch in compose.rpms.rpms[variant]: - if srpm_name in compose.rpms.rpms[variant][arch]: - return True + for srpm_nevra in compose.rpms.rpms[variant][arch]: + srpm = kobo.rpmlib.parse_nvr(srpm_nevra) + if srpm['name'] == name and \ + srpm['version'] == version and \ + srpm['release'] == release + '.src': + return True return False diff --git a/tests/test_has_build.py b/tests/test_has_build.py index 2658b83..01c9297 100644 --- a/tests/test_has_build.py +++ b/tests/test_has_build.py @@ -26,14 +26,6 @@ class LookForBuildTest(unittest.TestCase): compose = get_compose("DP-1.0-20160315.t.0") self.assertFalse(compose_utils.look_for_build(compose, "dummy-bash-4.2.37-1")) - def test_missing_nevr(self): - compose = get_compose("DP-1.0-20160315.t.0") - self.assertFalse(compose_utils.look_for_build(compose, "dummy-bash-0:4.2.37-1")) - - def test_missing_nevr_bad_epoch(self): - compose = get_compose("DP-1.0-20160315.t.0") - self.assertFalse(compose_utils.look_for_build(compose, "dummy-bash-1:4.2.37-6")) - class HasBuildTest(unittest.TestCase): def setUp(self):