Skip to content

Commit

Permalink
Fix more ssh tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Dec 29, 2023
1 parent 6f5c0ac commit d53a8c7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions salt/client/ssh/wrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def to_ret(self):

def __str__(self):
ret = self.to_ret()
if isinstance(ret, str):
return f"{self._error}: {ret}"
if self.retcode > 0:
return f"{self._error}: {self.stderr or self.stdout}"
return self._error


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ def test_it(salt_ssh_cli, args):

assert ret.returncode == EX_AGGREGATE
assert ret.data
assert isinstance(ret.data, str)
assert "ComplianceError: 'Outlaw detected'" in ret.data
assert isinstance(ret.data, dict)
assert "ComplianceError: 'Outlaw detected'" in ret.data["stderr"]
19 changes: 11 additions & 8 deletions tests/pytests/integration/ssh/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ 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, str)
assert isinstance(ret.data, dict)
# 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
assert "Error running 'file.touch': No such file or directory" in ret.data["stderr"]


def test_retcode_exe_run_exception(salt_ssh_cli):
Expand All @@ -233,8 +233,8 @@ def test_retcode_exe_run_exception(salt_ssh_cli):
"""
ret = salt_ssh_cli.run("salttest.jinja_error")
assert ret.returncode == EX_AGGREGATE
assert isinstance(ret.data, str)
assert ret.data.endswith("Exception: hehehe")
assert isinstance(ret.data, dict)
assert ret.data["stderr"].endswith("Exception: hehehe")


@pytest.mark.usefixtures("invalid_json_exe_mod")
Expand Down Expand Up @@ -276,10 +276,13 @@ def test_wrapper_unwrapped_command_exception(salt_ssh_cli):
"""
ret = salt_ssh_cli.run("check_exception.failure")
assert ret.returncode == EX_AGGREGATE
assert isinstance(ret.data, str)
assert isinstance(ret.data, dict)
assert ret.data
assert "Probably got garbage" not in ret.data
assert "Error running 'disk.usage': Invalid flag passed to disk.usage" in ret.data
assert "Probably got garbage" not in ret.data["stderr"]
assert (
"Error running 'disk.usage': Invalid flag passed to disk.usage"
in ret.data["stderr"]
)


@pytest.mark.usefixtures("remote_parsing_failure_wrap_mod", "invalid_json_exe_mod")
Expand All @@ -290,7 +293,7 @@ def test_wrapper_unwrapped_command_parsing_failure(salt_ssh_cli):
ret = salt_ssh_cli.run("check_parsing.failure", "whoops")
assert ret.returncode == EX_AGGREGATE
assert ret.data
assert "Probably got garbage" not in ret.data
assert "Probably got garbage" not in ret.data["stderr"]
assert isinstance(ret.data, dict)
assert ret.data["_error"] == "Failed to return clean data"
assert ret.data["retcode"] == 0
Expand Down

0 comments on commit d53a8c7

Please sign in to comment.