Adapt unit tests, report permission denied as before

Also fix an integration test which was broken by a botched
rebase conflict resolution.
This commit is contained in:
jeanluc 2023-06-29 09:29:39 +02:00 committed by Daniel Wozniak
parent 3c804657be
commit 5e559b8449
4 changed files with 21 additions and 5 deletions

View file

@ -887,7 +887,10 @@ class SSH(MultiprocessingStateMixin):
if not isinstance(ret[host], dict):
p_data = {host: ret[host]}
elif "return" not in ret[host]:
p_data = ret
if ret[host].get("_error") == "Permission denied":
p_data = {host: ret[host]["stderr"]}
else:
p_data = ret
else:
outputter = ret[host].get("out", self.opts.get("output", "nested"))
p_data = {host: ret[host].get("return", {})}

View file

@ -220,7 +220,6 @@ 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 ret.data["retcode"] == 1
assert isinstance(ret.data, str)
# This should be the exact output, but some other warnings
# might be printed to stderr.

View file

@ -36,16 +36,30 @@ def test_password_failure(temp_salt_master, tmp_path):
"retcode": 255,
"stderr": "Permission denied (publickey).\r\n",
"stdout": "",
"_error": "Permission denied",
}
},
1,
)
]
key_deploy_ret = (
{
"localhost": {
"retcode": 255,
"stderr": "Permission denied (publickey)",
"stdout": "",
"_error": "Permission denied",
}
},
1,
)
expected = {"localhost": "Permission denied (publickey)"}
display_output = MagicMock()
with patch("salt.roster.get_roster_file", MagicMock(return_value=roster)), patch(
"salt.client.ssh.SSH.handle_ssh", MagicMock(return_value=handle_ssh_ret)
), patch("salt.client.ssh.SSH.key_deploy", MagicMock(return_value=expected)), patch(
), patch(
"salt.client.ssh.SSH.key_deploy", MagicMock(return_value=key_deploy_ret)
), patch(
"salt.output.display_output", display_output
):
client = ssh.SSH(opts)

View file

@ -28,7 +28,7 @@ def test_not_missing_fun_calling_wfuncs(temp_salt_master, tmp_path):
roster = str(tmp_path / "roster")
handle_ssh_ret = [({"localhost": {}}, 0)]
expected = {"localhost": {}}
expected = ({"localhost": {}}, 0)
display_output = MagicMock()
with patch("salt.roster.get_roster_file", MagicMock(return_value=roster)), patch(
"salt.client.ssh.SSH.handle_ssh", MagicMock(return_value=handle_ssh_ret)
@ -41,7 +41,7 @@ def test_not_missing_fun_calling_wfuncs(temp_salt_master, tmp_path):
assert "localhost" in ret
assert "fun" in ret["localhost"]
client.run()
display_output.assert_called_once_with(expected, "nested", opts)
display_output.assert_called_once_with(expected[0], "nested", opts)
assert ret is handle_ssh_ret[0][0]
assert len(client.event.fire_event.call_args_list) == 2
assert "fun" in client.event.fire_event.call_args_list[0][0][0]