From bed3a1fc7cb30980360227cb17d45b7b566daad2 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Aug 13 2018 11:34:53 +0000 Subject: [PATCH 1/2] 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 c34ff70..e667a03 100644 --- a/compose_utils/__init__.py +++ b/compose_utils/__init__.py @@ -12,14 +12,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): From 96923fe1c15b35adb40782561f247645902f990f Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Aug 13 2018 11:34:53 +0000 Subject: [PATCH 2/2] compose-has-build: Use epoch if provided If there is no epoch in the given argument, any epoch will match. If epoch is given, it will really be used. Merges: https://pagure.io/compose-utils/pull-request/81 Signed-off-by: Lubomír Sedlář --- diff --git a/compose_utils/__init__.py b/compose_utils/__init__.py index e667a03..f2f40d6 100644 --- a/compose_utils/__init__.py +++ b/compose_utils/__init__.py @@ -13,20 +13,23 @@ from .copy_compose import copy_compose # noqa def look_for_build(compose, nvr): """ - Look for a build NVR with any epoch. + Look for a build NVR. If nvr contains an epoch, it will be used to match. + If epoch is not present, build with any epoch will match. """ parts = kobo.rpmlib.parse_nvr(nvr) name = parts['name'] version = parts['version'] release = parts['release'] + epoch = parts['epoch'] or None for variant in compose.rpms.rpms: for arch in compose.rpms.rpms[variant]: for srpm_nevra in compose.rpms.rpms[variant][arch]: - srpm = kobo.rpmlib.parse_nvr(srpm_nevra) + srpm = kobo.rpmlib.parse_nvra(srpm_nevra) if srpm['name'] == name and \ srpm['version'] == version and \ - srpm['release'] == release + '.src': + srpm['release'] == release and \ + (epoch is None or srpm["epoch"] == epoch): return True return False diff --git a/doc/compose-has-build.1 b/doc/compose-has-build.1 index 11ae14c..d19c2e4 100644 --- a/doc/compose-has-build.1 +++ b/doc/compose-has-build.1 @@ -9,8 +9,8 @@ compose-has-build \- check for existence of a build in a compose .SH DESCRIPTION .B compose-has-build checks metadata in the compose and checks if the given build is present. The -build can be specified either as NVR or as full NEVR. If there is no epoch, 0 -is assumed. +build can be specified either as NVR or as full NEVR. If there is no epoch, a +build with any epoch will match. .SH OPTIONS .TP .BR \-h ", " \-\-help diff --git a/tests/test_has_build.py b/tests/test_has_build.py index 01c9297..490cc7e 100644 --- a/tests/test_has_build.py +++ b/tests/test_has_build.py @@ -40,6 +40,15 @@ class HasBuildTest(unittest.TestCase): mock_out.getvalue(), ) + def test_present_with_epoch(self): + with mock.patch("sys.stdout", new_callable=StringIO) as mock_out: + compose_utils.has_build([self.path, "dummy-bash-0:4.2.37-6"]) + + self.assertEqual( + "Compose DP-1.0-20160315.t.0 has build dummy-bash-0:4.2.37-6\n", + mock_out.getvalue(), + ) + def test_missing(self): with mock.patch("sys.stdout", new_callable=StringIO) as mock_out: with self.assertRaises(SystemExit): @@ -62,3 +71,8 @@ class HasBuildTest(unittest.TestCase): compose_utils.has_build(["-q", self.path, "dummy-bash-4.2.37-1"]) self.assertEqual("", mock_out.getvalue()) + + def test_missing_nevr_bad_epoch(self): + # Build with this NEVR doesn't exist, there's only 0:4.2.37-6 + compose = get_compose("DP-1.0-20160315.t.0") + self.assertFalse(compose_utils.look_for_build(compose, "dummy-bash-1:4.2.37-6"))