diff --git a/salt/client/ssh/wrapper/__init__.py b/salt/client/ssh/wrapper/__init__.py index 0c6bc32d3849..bb60f58cd1ac 100644 --- a/salt/client/ssh/wrapper/__init__.py +++ b/salt/client/ssh/wrapper/__init__.py @@ -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 diff --git a/tests/pytests/integration/ssh/state/test_retcode_state_run_remote_exception.py b/tests/pytests/integration/ssh/state/test_retcode_state_run_remote_exception.py index 60621a2ffe0d..fe9611939d32 100644 --- a/tests/pytests/integration/ssh/state/test_retcode_state_run_remote_exception.py +++ b/tests/pytests/integration/ssh/state/test_retcode_state_run_remote_exception.py @@ -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"] diff --git a/tests/pytests/integration/ssh/test_deploy.py b/tests/pytests/integration/ssh/test_deploy.py index 74d8c8862a7b..157666c3708c 100644 --- a/tests/pytests/integration/ssh/test_deploy.py +++ b/tests/pytests/integration/ssh/test_deploy.py @@ -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): @@ -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") @@ -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") @@ -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