From 80957f5205f871b60f893ca034ffc3607003c92a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 26 Apr 2022 08:02:16 +0200 Subject: [PATCH] kojiwrapper: Ignore warnings before task id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ář --- pungi/wrappers/kojiwrapper.py | 15 ++++++++++----- tests/test_koji_wrapper.py | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/pungi/wrappers/kojiwrapper.py b/pungi/wrappers/kojiwrapper.py index d53da5d9..b1f2459d 100644 --- a/pungi/wrappers/kojiwrapper.py +++ b/pungi/wrappers/kojiwrapper.py @@ -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) diff --git a/tests/test_koji_wrapper.py b/tests/test_koji_wrapper.py index 2a7c2df9..4b943596 100644 --- a/tests/test_koji_wrapper.py +++ b/tests/test_koji_wrapper.py @@ -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")