From 2791be62b1bb5c178dc66614cb9a32c579f9a8d3 Mon Sep 17 00:00:00 2001 From: jeanluc Date: Sun, 25 Jun 2023 23:14:36 +0200 Subject: [PATCH] Filter out deprecation warnings from reported stderr --- salt/client/ssh/wrapper/__init__.py | 20 +++++++++++++++++++- tests/pytests/integration/ssh/test_deploy.py | 6 ++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/salt/client/ssh/wrapper/__init__.py b/salt/client/ssh/wrapper/__init__.py index 3771f7a8b3a..d4c47c2195b 100644 --- a/salt/client/ssh/wrapper/__init__.py +++ b/salt/client/ssh/wrapper/__init__.py @@ -31,13 +31,31 @@ class SSHException(SaltException): ): super().__init__(stderr, *args, **kwargs) self.stdout = stdout - self.stderr = stderr + self.stderr = self._filter_stderr(stderr) self.result = result self.data = data self.retcode = retcode if args: self._error = args.pop(0) + def _filter_stderr(self, stderr): + stderr_lines = [] + skip_next = False + for line in stderr.splitlines(): + if skip_next: + skip_next = False + continue + # Filter out deprecation warnings from stderr to the best of + # our ability since they are irrelevant to the command output and cause noise. + parts = line.split(":") + if len(parts) > 2 and "DeprecationWarning" in parts[2]: + # DeprecationWarnings print two lines, the second one being the + # line that caused the warning. + skip_next = True + continue + stderr_lines.append(line) + return "\n".join(stderr_lines) + def to_ret(self): ret = { "stdout": self.stdout, diff --git a/tests/pytests/integration/ssh/test_deploy.py b/tests/pytests/integration/ssh/test_deploy.py index 208bb0a11c6..169439d9c7e 100644 --- a/tests/pytests/integration/ssh/test_deploy.py +++ b/tests/pytests/integration/ssh/test_deploy.py @@ -220,9 +220,11 @@ def test_retcode_exe_run_fail(salt_ssh_cli): """ ret = salt_ssh_cli.run("file.touch", "/tmp/non/ex/is/tent") assert ret.returncode == EX_AGGREGATE - assert isinstance(ret.data, dict) - assert "Error running 'file.touch': No such file or directory" in ret.data["stderr"] assert ret.data["retcode"] == 1 + assert isinstance(ret.data, str) + # This should be the exact output, but some other warnings + # might be printed to stderr. + assert "Error running 'file.touch': No such file or directory" in ret.data def test_retcode_exe_run_exception(salt_ssh_cli):