[koji-wrapper] Only parse output on success
If Koji fails runroot task for some reason, the output will most likely not have the required format and will crash Pungi. Pagure: #140 Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
8e5e893e5c
commit
aec57dc72b
@ -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:])
|
||||
|
@ -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__":
|
||||
|
Loading…
Reference in New Issue
Block a user