mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Join masters if it is a list
This commit is contained in:
parent
102b93a707
commit
4d52af1336
3 changed files with 73 additions and 8 deletions
2
changelog/64170.fixed.md
Normal file
2
changelog/64170.fixed.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
Fixed issue in salt-cloud so that multiple masters specified in the cloud
|
||||
are written to the minion config properly
|
|
@ -1202,6 +1202,16 @@ def wait_for_passwd(
|
|||
time.sleep(trysleep)
|
||||
|
||||
|
||||
def _format_master_param(master):
|
||||
"""
|
||||
If the master is a list, we need to convert it to a comma delimited string
|
||||
Otherwise, we just return master
|
||||
"""
|
||||
if isinstance(master, list):
|
||||
return ",".join(master)
|
||||
return master
|
||||
|
||||
|
||||
def deploy_windows(
|
||||
host,
|
||||
port=445,
|
||||
|
@ -1337,17 +1347,18 @@ def deploy_windows(
|
|||
conn=smb_conn,
|
||||
)
|
||||
|
||||
cmd = "c:\\salttemp\\{}".format(installer)
|
||||
args = [
|
||||
"/S",
|
||||
"/master={}".format(_format_master_param(master)),
|
||||
"/minion-name={}".format(name),
|
||||
]
|
||||
|
||||
if use_winrm:
|
||||
winrm_cmd(
|
||||
winrm_session,
|
||||
"c:\\salttemp\\{}".format(installer),
|
||||
["/S", "/master={}".format(master), "/minion-name={}".format(name)],
|
||||
)
|
||||
winrm_cmd(winrm_session, cmd, args)
|
||||
else:
|
||||
cmd = "c:\\salttemp\\{}".format(installer)
|
||||
args = "/S /master={} /minion-name={}".format(master, name)
|
||||
stdout, stderr, ret_code = run_psexec_command(
|
||||
cmd, args, host, username, password
|
||||
cmd, " ".join(args), host, username, password
|
||||
)
|
||||
|
||||
if ret_code != 0:
|
||||
|
|
|
@ -605,3 +605,55 @@ def test_deploy_script_ssh_timeout():
|
|||
ssh_kwargs = root_cmd.call_args.kwargs
|
||||
assert "ssh_timeout" in ssh_kwargs
|
||||
assert ssh_kwargs["ssh_timeout"] == 34
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"master,expected",
|
||||
[
|
||||
(None, None),
|
||||
("single_master", "single_master"),
|
||||
(["master1", "master2", "master3"], "master1,master2,master3"),
|
||||
],
|
||||
)
|
||||
def test__format_master_param(master, expected):
|
||||
result = cloud._format_master_param(master)
|
||||
assert result == expected
|
||||
|
||||
|
||||
@pytest.mark.skip_unless_on_windows(reason="Only applicable for Windows.")
|
||||
@pytest.mark.parametrize(
|
||||
"master,expected",
|
||||
[
|
||||
(None, None),
|
||||
("single_master", "single_master"),
|
||||
(["master1", "master2", "master3"], "master1,master2,master3"),
|
||||
],
|
||||
)
|
||||
def test_deploy_windows_master(master, expected):
|
||||
"""
|
||||
Test deploy_windows with master parameter
|
||||
"""
|
||||
mock_true = MagicMock(return_value=True)
|
||||
mock_tuple = MagicMock(return_value=(0, 0, 0))
|
||||
with patch("salt.utils.smb.get_conn", MagicMock()), patch(
|
||||
"salt.utils.smb.mkdirs", MagicMock()
|
||||
), patch("salt.utils.smb.put_file", MagicMock()), patch(
|
||||
"salt.utils.smb.delete_file", MagicMock()
|
||||
), patch(
|
||||
"salt.utils.smb.delete_directory", MagicMock()
|
||||
), patch(
|
||||
"time.sleep", MagicMock()
|
||||
), patch.object(
|
||||
cloud, "wait_for_port", mock_true
|
||||
), patch.object(
|
||||
cloud, "fire_event", MagicMock()
|
||||
), patch.object(
|
||||
cloud, "wait_for_psexecsvc", mock_true
|
||||
), patch.object(
|
||||
cloud, "run_psexec_command", mock_tuple
|
||||
) as mock:
|
||||
cloud.deploy_windows(host="test", win_installer="install.exe", master=master)
|
||||
expected_cmd = "c:\\salttemp\\install.exe"
|
||||
expected_args = "/S /master={} /minion-name=None".format(expected)
|
||||
assert mock.call_args_list[0].args[0] == expected_cmd
|
||||
assert mock.call_args_list[0].args[1] == expected_args
|
||||
|
|
Loading…
Add table
Reference in a new issue