From e7af6d2ac205e21a1ea8f56e3fb92c7676f3d800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 25 Nov 2020 15:27:20 +0100 Subject: [PATCH] osbuild: Only send release when not empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lubomír Sedlář --- pungi/phases/osbuild.py | 4 +- tests/test_osbuild_phase.py | 119 ++++++++++++++++++++++++++++++++++-- 2 files changed, 118 insertions(+), 5 deletions(-) diff --git a/pungi/phases/osbuild.py b/pungi/phases/osbuild.py index ddd70536..c8322cc4 100644 --- a/pungi/phases/osbuild.py +++ b/pungi/phases/osbuild.py @@ -115,7 +115,9 @@ class RunOSBuildThread(WorkerThread): koji.login() # Start task - opts = {"repo": repo, "release": release} + opts = {"repo": repo} + if release: + opts["release"] = release task_id = koji.koji_proxy.osbuildImage( config["name"], version, diff --git a/tests/test_osbuild_phase.py b/tests/test_osbuild_phase.py index 8fa1f3d1..a81472f5 100644 --- a/tests/test_osbuild_phase.py +++ b/tests/test_osbuild_phase.py @@ -156,6 +156,120 @@ class RunOSBuildThreadTest(helpers.PungiTestCase): ] koji.koji_module.pathinfo = orig_koji.pathinfo + self.t.process( + ( + self.compose, + self.compose.variants["Everything"], + cfg, + ["aarch64", "x86_64"], + "1", # version + "15", # release + "image-target", + [self.topdir + "/compose/Everything/$arch/os"], + ["x86_64"], + ), + 1, + ) + + # Verify two Koji instances were created. + self.assertEqual(len(KojiWrapper.call_args), 2) + print(koji.mock_calls) + # Verify correct calls to Koji + self.assertEqual( + koji.mock_calls, + [ + mock.call.login(), + mock.call.koji_proxy.osbuildImage( + "test-image", + "1", + "rhel-8", + ["qcow2"], + "image-target", + ["aarch64", "x86_64"], + opts={ + "release": "15", + "repo": [self.topdir + "/compose/Everything/$arch/os"], + }, + ), + mock.call.watch_task(1234, mock.ANY), + mock.call.koji_proxy.getBuild("test-image-1-1"), + mock.call.koji_proxy.listArchives(buildID=5678), + ], + ) + + # Assert there are 2 images added to manifest and the arguments are sane + self.assertEqual( + self.compose.im.add.call_args_list, + [ + mock.call(arch="aarch64", variant="Everything", image=mock.ANY), + mock.call(arch="x86_64", variant="Everything", image=mock.ANY), + ], + ) + for call in self.compose.im.add.call_args_list: + _, kwargs = call + image = kwargs["image"] + self.assertEqual(kwargs["variant"], "Everything") + self.assertIn(kwargs["arch"], ("aarch64", "x86_64")) + self.assertEqual(kwargs["arch"], image.arch) + self.assertEqual( + "Everything/%(arch)s/images/disk.%(arch)s.qcow2" % {"arch": image.arch}, + image.path, + ) + self.assertEqual("qcow2", image.format) + self.assertEqual("qcow2", image.type) + self.assertEqual("Everything", image.subvariant) + + self.assertTrue( + os.path.isdir(self.topdir + "/compose/Everything/aarch64/images") + ) + self.assertTrue( + os.path.isdir(self.topdir + "/compose/Everything/x86_64/images") + ) + + self.assertEqual( + Linker.return_value.mock_calls, + [ + mock.call.link( + "/mnt/koji/packages/test-image/1/1/images/disk.%(arch)s.qcow2" + % {"arch": arch}, + self.topdir + + "/compose/Everything/%(arch)s/images/disk.%(arch)s.qcow2" + % {"arch": arch}, + link_type="hardlink-or-copy", + ) + for arch in ["aarch64", "x86_64"] + ], + ) + + @mock.patch("pungi.util.get_file_size", new=lambda fp: 65536) + @mock.patch("pungi.util.get_mtime", new=lambda fp: 1024) + @mock.patch("pungi.phases.osbuild.Linker") + @mock.patch("pungi.phases.osbuild.kojiwrapper.KojiWrapper") + def test_process_without_release(self, KojiWrapper, Linker): + cfg = {"name": "test-image", "distro": "rhel-8", "image_types": ["qcow2"]} + koji = KojiWrapper.return_value + koji.watch_task.side_effect = self.make_fake_watch(0) + koji.koji_proxy.osbuildImage.return_value = 1234 + koji.koji_proxy.getBuild.return_value = { + "build_id": 5678, + "name": "test-image", + "version": "1", + "release": "1", + } + koji.koji_proxy.listArchives.return_value = [ + { + "extra": {"image": {"arch": "aarch64"}}, + "filename": "disk.aarch64.qcow2", + "type_name": "qcow2", + }, + { + "extra": {"image": {"arch": "x86_64"}}, + "filename": "disk.x86_64.qcow2", + "type_name": "qcow2", + }, + ] + koji.koji_module.pathinfo = orig_koji.pathinfo + self.t.process( ( self.compose, @@ -185,10 +299,7 @@ class RunOSBuildThreadTest(helpers.PungiTestCase): ["qcow2"], "image-target", ["aarch64", "x86_64"], - opts={ - "release": None, - "repo": [self.topdir + "/compose/Everything/$arch/os"], - }, + opts={"repo": [self.topdir + "/compose/Everything/$arch/os"]}, ), mock.call.watch_task(1234, mock.ANY), mock.call.koji_proxy.getBuild("test-image-1-1"),