From a698c7cc0adfae39f30ea656b796f2265b1f73dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 26 Jan 2016 12:46:50 +0100 Subject: [PATCH] [image-build] Allow running image build scratch tasks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue #130 Signed-off-by: Lubomír Sedlář --- doc/configuration.rst | 2 ++ pungi/phases/image_build.py | 6 ++++-- tests/test_imagebuildphase.py | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index 59977bab..3f4f2a08 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -680,6 +680,8 @@ Image Build Settings If ``ksurl`` ends with ``#HEAD``, Pungi will figure out the SHA1 hash of current HEAD and use that instead. + Setting ``scratch`` to ``True`` will run the koji tasks as scratch builds. + Example ------- diff --git a/pungi/phases/image_build.py b/pungi/phases/image_build.py index d950f8ce..def1ecec 100644 --- a/pungi/phases/image_build.py +++ b/pungi/phases/image_build.py @@ -127,7 +127,8 @@ class ImageBuildPhase(PhaseBase): "relative_image_dir": self.compose.paths.compose.image_dir( variant, relative=True ), - "link_type": self.compose.conf.get("link_type", "hardlink-or-copy") + "link_type": self.compose.conf.get("link_type", "hardlink-or-copy"), + "scratch": image_conf.pop('scratch', False), } self.pool.add(CreateImageBuildThread(self.pool)) self.pool.queue_put((self.compose, cmd)) @@ -174,7 +175,8 @@ class CreateImageBuildThread(WorkerThread): self.pool.log_info("Writing image-build config for %s.%s into %s" % ( cmd["image_conf"]["variant"], '-'.join(arches), cmd["conf_file"])) koji_cmd = koji_wrapper.get_image_build_cmd(cmd['image_conf'], - conf_file_dest=cmd["conf_file"]) + conf_file_dest=cmd["conf_file"], + scratch=cmd['scratch']) # avoid race conditions? # Kerberos authentication failed: Permission denied in replay cache code (-1765328215) diff --git a/tests/test_imagebuildphase.py b/tests/test_imagebuildphase.py index f468e036..f3385a1c 100755 --- a/tests/test_imagebuildphase.py +++ b/tests/test_imagebuildphase.py @@ -117,6 +117,7 @@ class TestImageBuildPhase(unittest.TestCase): "image_dir": '/image_dir/Client/%(arch)s', "relative_image_dir": 'image_dir/Client/%(arch)s', "link_type": 'hardlink-or-copy', + "scratch": False, } server_args = { "format": [('docker', 'tar.xz')], @@ -138,6 +139,7 @@ class TestImageBuildPhase(unittest.TestCase): "image_dir": '/image_dir/Server/%(arch)s', "relative_image_dir": 'image_dir/Server/%(arch)s', "link_type": 'hardlink-or-copy', + "scratch": False, } self.assertItemsEqual(phase.pool.queue_put.mock_calls, [mock.call((compose, client_args)), @@ -225,6 +227,7 @@ class TestImageBuildPhase(unittest.TestCase): "image_dir": '/image_dir/Server/%(arch)s', "relative_image_dir": 'image_dir/Server/%(arch)s', "link_type": 'hardlink-or-copy', + "scratch": False, }) @mock.patch('pungi.phases.image_build.ThreadPool') @@ -280,6 +283,7 @@ class TestImageBuildPhase(unittest.TestCase): "image_dir": '/image_dir/Server/%(arch)s', "relative_image_dir": 'image_dir/Server/%(arch)s', "link_type": 'hardlink-or-copy', + "scratch": False, }) @mock.patch('pungi.phases.image_build.ThreadPool') @@ -316,6 +320,39 @@ class TestImageBuildPhase(unittest.TestCase): self.assertEqual(args[0][1].get('image_conf', {}).get('release'), '20151203.0') + @mock.patch('pungi.phases.image_build.ThreadPool') + def test_image_build_scratch_build(self, ThreadPool): + compose = _DummyCompose({ + 'image_build': { + '^Server$': [ + { + 'format': [('docker', 'tar.xz')], + 'name': 'Fedora-Docker-Base', + 'target': 'f24', + 'version': 'Rawhide', + 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', + 'kickstart': "fedora-docker-base.ks", + 'distro': 'Fedora-20', + 'disk_size': 3, + 'arches': ['x86_64'], + 'scratch': True, + } + ] + }, + 'koji_profile': 'koji', + }) + + phase = ImageBuildPhase(compose) + + phase.run() + + # assert at least one thread was started + self.assertTrue(phase.pool.add.called) + + self.assertTrue(phase.pool.queue_put.called_once) + args, kwargs = phase.pool.queue_put.call_args + self.assertTrue(args[0][1].get('scratch')) + class TestCreateImageBuildThread(unittest.TestCase): @@ -347,6 +384,7 @@ class TestCreateImageBuildThread(unittest.TestCase): "image_dir": '/image_dir/Client/%(arch)s', "relative_image_dir": 'image_dir/Client/%(arch)s', "link_type": 'hardlink-or-copy', + "scratch": False, } koji_wrapper = KojiWrapper.return_value koji_wrapper.run_create_image_cmd.return_value = {