def test_ssh_config(self, mock_partial, mock_ssh_utils, mock_do_op): cmd = mock.Mock() custom.ssh_config(cmd, "path/to/file", "rg", "vm", "ip", "public", "private") mock_partial.assert_called_once_with( mock_ssh_utils.write_ssh_config, "path/to/file", "rg", "vm") mock_do_op.assert_called_once_with( cmd, "rg", "vm", "ip", "public", "private", mock_partial.return_value)
def test_ssh_config(self, mock_ssh_utils, mock_do_op): cmd = mock.Mock() def do_op_side_effect(cmd, resource_group, vm_name, ssh_ip, public_key_file, private_key_file, op_call): op_call(ssh_ip, "username", "cert_file", private_key_file) mock_do_op.side_effect = do_op_side_effect custom.ssh_config(cmd, "path/to/file", "rg", "vm", "ip", "public", "private") mock_ssh_utils.assert_called_once_with("path/to/file", "rg", "vm", "ip", "username", "cert_file", "private") mock_do_op.assert_called_once_with(cmd, "rg", "vm", "ip", "public", "private", mock.ANY)
def test_ssh_config_cred_folder(self, mock_dirname, mock_isdir, mock_info, mock_type, mock_op, mock_assert): cmd = mock.Mock() config_info = mock.Mock() mock_info.return_value = config_info mock_isdir.return_value = True mock_dirname.return_value = "config_folder" custom.ssh_config(cmd, "config", "rg", "vm", "ip", None, None, True, False, "user", "cert", "port", "type", "cred", "proxy", "client") mock_type.assert_called_once_with(cmd, config_info) mock_info.assert_called_once_with("config", "rg", "vm", "ip", None, None, True, False, "user", "cert", "port", "type", "cred", "proxy", "client") mock_assert.assert_called_once_with("rg", "vm", "ip", "type", "cert", "user") mock_op.assert_called_once_with(cmd, config_info, ssh_utils.write_ssh_config)
def test_ssh_config(self, mock_info, mock_join, mock_dirname, mock_isdir, mock_assert, mock_ssh_utils, mock_do_op): cmd = mock.Mock() mock_dirname.return_value = "configdir" mock_isdir.return_value = True mock_join.side_effect = [ 'az_ssh_config/rg-vm', 'path/to/az_ssh_config/rg-vm' ] custom.ssh_config(cmd, "path/to/file", "rg", "vm", "ip", "public", "private", False, False, "username", "cert", "port", None, "client/folder") mock_info.assert_called_once_with("path/to/file", "rg", "vm", "ip", "public", "private", False, False, "username", "cert", "port", "client/folder") mock_assert.assert_called_once_with("rg", "vm", "ip", "cert", "username") mock_do_op.assert_called_once_with(cmd, mock.ANY, 'path/to/az_ssh_config/rg-vm', ssh_utils.write_ssh_config)
def test_ssh_config_no_cred_folder(self, mock_join, mock_info, mock_isdir, mock_dirname, mock_type, mock_do_op, mock_assert): cmd = mock.Mock() config_info = mock.Mock() config_info.ip = "ip" config_info.resource_group_name = "rg" config_info.vm_name = "vm" config_info.credentials_folder = None mock_info.return_value = config_info mock_isdir.return_value = True mock_dirname.return_value = "config_folder" expected_join_calls = [ mock.call("az_ssh_config", "rg-vm"), mock.call("config_folder", "az_ssh_config/rg-vm") ] mock_join.side_effect = [ 'az_ssh_config/rg-vm', 'path/to/az_ssh_config/rg-vm' ] custom.ssh_config(cmd, "config", "rg", "vm", "ip", "pub", "priv", True, False, "user", "cert", "port", "type", None, "proxy", "client") mock_join.assert_has_calls(expected_join_calls) mock_info.assert_called_once_with("config", "rg", "vm", "ip", "pub", "priv", True, False, "user", "cert", "port", "type", None, "proxy", "client") mock_type.assert_called_once_with(cmd, config_info) mock_assert.assert_called_once_with("rg", "vm", "ip", "type", "cert", "user") mock_do_op.assert_called_once_with(cmd, config_info, ssh_utils.write_ssh_config)