mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Filter out deprecation warnings from reported stderr
This commit is contained in:
parent
5be82ae9fb
commit
2791be62b1
2 changed files with 23 additions and 3 deletions
|
@ -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,
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Reference in a new issue