diff --git a/pungi/wrappers/kojiwrapper.py b/pungi/wrappers/kojiwrapper.py index 1400f73b..4a4848dd 100644 --- a/pungi/wrappers/kojiwrapper.py +++ b/pungi/wrappers/kojiwrapper.py @@ -82,7 +82,7 @@ class KojiWrapper(object): task_id = None retcode, output = run(command, can_fail=True, logfile=log_file) - if "--task-id" in command: + if retcode == 0 and "--task-id" in command: task_id = int(output.splitlines()[0]) output_ends_with_eol = output.endswith("\n") output = "\n".join(output.splitlines()[1:]) diff --git a/tests/test_koji_wrapper.py b/tests/test_koji_wrapper.py index bb9a29bd..106c05f9 100755 --- a/tests/test_koji_wrapper.py +++ b/tests/test_koji_wrapper.py @@ -345,8 +345,7 @@ class RunrootKojiWrapperTest(unittest.TestCase): run.return_value = (0, output) result = self.koji.run_runroot_cmd(cmd) - self.assertDictEqual(result, - {'retcode': 0, 'output': output, 'task_id': None}) + self.assertDictEqual(result, {'retcode': 0, 'output': output, 'task_id': None}) @mock.patch('pungi.wrappers.kojiwrapper.run') def test_run_runroot_cmd_with_task_id(self, run): @@ -355,8 +354,16 @@ class RunrootKojiWrapperTest(unittest.TestCase): run.return_value = (0, '1234\n' + output) result = self.koji.run_runroot_cmd(cmd) - self.assertDictEqual(result, - {'retcode': 0, 'output': output, 'task_id': 1234}) + self.assertDictEqual(result, {'retcode': 0, 'output': output, 'task_id': 1234}) + + @mock.patch('pungi.wrappers.kojiwrapper.run') + def test_run_runroot_cmd_with_task_id_and_fail(self, run): + cmd = ['koji', 'runroot', '--task-id'] + output = 'You are not authorized to run this\n' + run.return_value = (1, output) + + result = self.koji.run_runroot_cmd(cmd) + self.assertDictEqual(result, {'retcode': 1, 'output': output, 'task_id': None}) if __name__ == "__main__":