diff --git a/pungi/phases/image_build.py b/pungi/phases/image_build.py index 5fd67b33..ac54cef1 100644 --- a/pungi/phases/image_build.py +++ b/pungi/phases/image_build.py @@ -176,7 +176,7 @@ class CreateImageBuildThread(WorkerThread): # avoid race conditions? # Kerberos authentication failed: Permission denied in replay cache code (-1765328215) time.sleep(num * 3) - output = koji_wrapper.run_create_image_cmd(koji_cmd, log_file=log_file) + output = koji_wrapper.run_blocking_cmd(koji_cmd, log_file=log_file) self.pool.log_debug("build-image outputs: %s" % (output)) if output["retcode"] != 0: self.fail(compose, cmd) @@ -185,7 +185,7 @@ class CreateImageBuildThread(WorkerThread): # copy image to images/ image_infos = [] - paths = koji_wrapper.get_image_build_paths(output["task_id"]) + paths = koji_wrapper.get_image_paths(output["task_id"]) for arch, paths in paths.iteritems(): for path in paths: diff --git a/pungi/phases/live_images.py b/pungi/phases/live_images.py index 685bf4f5..3f7225e4 100644 --- a/pungi/phases/live_images.py +++ b/pungi/phases/live_images.py @@ -201,7 +201,7 @@ class CreateLiveImageThread(WorkerThread): # Kerberos authentication failed: Permission denied in replay cache code (-1765328215) time.sleep(num * 3) - output = koji_wrapper.run_create_image_cmd(koji_cmd, log_file=log_file) + output = koji_wrapper.run_blocking_cmd(koji_cmd, log_file=log_file) if output["retcode"] != 0: self.fail(compose, cmd) raise RuntimeError("LiveImage task failed: %s. See %s for more details." % (output["task_id"], log_file)) diff --git a/pungi/wrappers/kojiwrapper.py b/pungi/wrappers/kojiwrapper.py index 62e11751..5b5076b8 100644 --- a/pungi/wrappers/kojiwrapper.py +++ b/pungi/wrappers/kojiwrapper.py @@ -191,8 +191,12 @@ class KojiWrapper(object): return cmd - def run_create_image_cmd(self, command, log_file=None): - # spin-{livecd,appliance} is blocking by default -> you probably want to run it in a thread + def run_blocking_cmd(self, command, log_file=None): + """ + Run a blocking koji command. Returns a dict with output of the command, + its exit code and parsed task id. This method will block until the + command finishes. + """ try: retcode, output = run(command, can_fail=True, logfile=log_file) except RuntimeError, e: @@ -209,7 +213,7 @@ class KojiWrapper(object): } return result - def get_image_build_paths(self, task_id): + def get_image_paths(self, task_id): """ Given an image task in Koji, get a mapping from arches to a list of paths to results of the task. diff --git a/tests/test_imagebuildphase.py b/tests/test_imagebuildphase.py index f468e036..434db753 100755 --- a/tests/test_imagebuildphase.py +++ b/tests/test_imagebuildphase.py @@ -349,12 +349,12 @@ class TestCreateImageBuildThread(unittest.TestCase): "link_type": 'hardlink-or-copy', } koji_wrapper = KojiWrapper.return_value - koji_wrapper.run_create_image_cmd.return_value = { + koji_wrapper.run_blocking_cmd.return_value = { "retcode": 0, "output": None, "task_id": 1234, } - koji_wrapper.get_image_build_paths.return_value = { + koji_wrapper.get_image_paths.return_value = { 'amd64': [ '/koji/task/1235/tdl-amd64.xml', '/koji/task/1235/Fedora-Docker-Base-20160103.amd64.qcow2', @@ -468,7 +468,7 @@ class TestCreateImageBuildThread(unittest.TestCase): "link_type": 'hardlink-or-copy', } koji_wrapper = KojiWrapper.return_value - koji_wrapper.run_create_image_cmd.return_value = { + koji_wrapper.run_blocking_cmd.return_value = { "retcode": 1, "output": None, "task_id": 1234, @@ -520,7 +520,7 @@ class TestCreateImageBuildThread(unittest.TestCase): raise RuntimeError('BOOM') koji_wrapper = KojiWrapper.return_value - koji_wrapper.run_create_image_cmd.side_effect = boom + koji_wrapper.run_blocking_cmd.side_effect = boom t = CreateImageBuildThread(pool) with mock.patch('os.stat') as stat: diff --git a/tests/test_koji_wrapper.py b/tests/test_koji_wrapper.py index 3db3c3e5..f90dcc7d 100755 --- a/tests/test_koji_wrapper.py +++ b/tests/test_koji_wrapper.py @@ -75,7 +75,7 @@ class KojiWrapperTest(unittest.TestCase): mock.call('distro = test-distro\n'), mock.call('\n')]) - def test_get_image_build_paths(self): + def test_get_image_paths(self): # The data for this tests is obtained from the actual Koji build. It # includes lots of fields that are not used, but for the sake of @@ -233,7 +233,7 @@ class KojiWrapperTest(unittest.TestCase): getTaskChildren=mock.Mock(side_effect=lambda task_id, request: getTaskChildren_data.get(task_id)), getTaskResult=mock.Mock(side_effect=lambda task_id: getTaskResult_data.get(task_id)) ) - result = self.koji.get_image_build_paths(12387273) + result = self.koji.get_image_paths(12387273) self.assertItemsEqual(result.keys(), ['i386', 'x86_64']) self.maxDiff = None self.assertItemsEqual(result['i386'], diff --git a/tests/test_liveimagesphase.py b/tests/test_liveimagesphase.py index c403e9e8..ead447c1 100755 --- a/tests/test_liveimagesphase.py +++ b/tests/test_liveimagesphase.py @@ -129,7 +129,7 @@ class TestCreateLiveImageThread(unittest.TestCase): koji_wrapper = KojiWrapper.return_value koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...' - koji_wrapper.run_create_image_cmd.return_value = { + koji_wrapper.run_blocking_cmd.return_value = { 'retcode': 0, 'output': 'some output', 'task_id': 123 @@ -140,7 +140,7 @@ class TestCreateLiveImageThread(unittest.TestCase): with mock.patch('time.sleep'): t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1) - self.assertEqual(koji_wrapper.run_create_image_cmd.mock_calls, + self.assertEqual(koji_wrapper.run_blocking_cmd.mock_calls, [mock.call('koji spin-livecd ...', log_file='/a/b/log/log_file')]) self.assertEqual(koji_wrapper.get_image_path.mock_calls, [mock.call(123)]) self.assertEqual(copy2.mock_calls, @@ -178,7 +178,7 @@ class TestCreateLiveImageThread(unittest.TestCase): koji_wrapper = KojiWrapper.return_value koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...' - koji_wrapper.run_create_image_cmd.return_value = { + koji_wrapper.run_blocking_cmd.return_value = { 'retcode': 1, 'output': 'some output', 'task_id': 123