kojiwrapper: Ignore warnings before task id

When looking for task ID in output of koji runroot command, do not check
just the first line. Instead look for first line that contains just a
number.

Most of the time, this should really be the first line. But if koji
client decides to print any warnings, this patch should skip that.

JIRA: RHELCMP-8944
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2022-04-26 08:02:16 +02:00
parent e8d79e9269
commit 80957f5205
2 changed files with 34 additions and 5 deletions

View File

@ -291,16 +291,21 @@ class KojiWrapper(object):
universal_newlines=True,
)
first_line = output.splitlines()[0]
match = re.search(r"^(\d+)$", first_line)
if not match:
# Look for first line that contains only a number. This is the ID of
# the new task. Usually this should be the first line, but there may be
# warnings before it.
for line in output.splitlines():
match = re.search(r"^(\d+)$", line)
if match:
task_id = int(match.groups()[0])
break
if not task_id:
raise RuntimeError(
"Could not find task ID in output. Command '%s' returned '%s'."
% (" ".join(command), output)
)
task_id = int(match.groups()[0])
self.save_task_id(task_id)
retcode, output = self._wait_for_task(task_id, logfile=log_file)

View File

@ -668,6 +668,30 @@ class RunrootKojiWrapperTest(KojiWrapperBaseTestCase):
],
)
@mock.patch("pungi.wrappers.kojiwrapper.run")
def test_run_runroot_cmd_with_warnings_before_task_id(self, run):
cmd = ["koji", "runroot", "--task-id"]
run.return_value = (0, "DeprecatioNWarning: whatever\n1234\n")
output = "Output ..."
self.koji._wait_for_task = mock.Mock(return_value=(0, output))
result = self.koji.run_runroot_cmd(cmd)
self.assertDictEqual(result, {"retcode": 0, "output": output, "task_id": 1234})
self.assertEqual(
run.call_args_list,
[
mock.call(
cmd,
can_fail=True,
env={"FOO": "BAR", "PYTHONUNBUFFERED": "1"},
buffer_size=-1,
logfile=None,
show_cmd=True,
universal_newlines=True,
)
],
)
@mock.patch("shutil.rmtree")
@mock.patch("tempfile.mkdtemp")
@mock.patch("pungi.wrappers.kojiwrapper.run")