def test__run_command_over_ssh_remote_path(self): mock_ssh = mock.MagicMock() vm_scenario = utils.VMScenario(self.context) vm_scenario._run_command_over_ssh(mock_ssh, { "remote_path": ["foo", "bar"], "command_args": ["arg1", "arg2"] }) mock_ssh.execute.assert_called_once_with( ["foo", "bar", "arg1", "arg2"], stdin=None)
def test__wait_for_ping(self): vm_scenario = utils.VMScenario(self.context) vm_scenario._ping_ip_address = mock.Mock(return_value=True) vm_scenario._wait_for_ping(netaddr.IPAddress("1.2.3.4")) self.mock_wait_for_status.mock.assert_called_once_with( utils.Host("1.2.3.4"), ready_statuses=[utils.Host.ICMP_UP_STATUS], update_resource=utils.Host.update_status, timeout=CONF.openstack.vm_ping_timeout, check_interval=CONF.openstack.vm_ping_poll_interval)
def test__run_command_over_ssh_script_inline(self, mock_string_io): mock_ssh = mock.MagicMock() vm_scenario = utils.VMScenario(self.context) vm_scenario._run_command_over_ssh( mock_ssh, { "script_inline": "foobar", "interpreter": ["interpreter", "interpreter_arg"], "command_args": ["arg1", "arg2"] }) mock_ssh.execute.assert_called_once_with( ["interpreter", "interpreter_arg", "arg1", "arg2"], stdin=mock_string_io.return_value) mock_string_io.assert_called_once_with("foobar")
def test__run_command_over_ssh_script_file(self, mock_open): mock_ssh = mock.MagicMock() vm_scenario = utils.VMScenario(self.context) vm_scenario._run_command_over_ssh( mock_ssh, { "script_file": "foobar", "interpreter": ["interpreter", "interpreter_arg"], "command_args": ["arg1", "arg2"] }) mock_ssh.execute.assert_called_once_with( ["interpreter", "interpreter_arg", "arg1", "arg2"], stdin=mock_open.side_effect()) mock_open.assert_called_once_with("foobar", "rb")
def test__run_command_over_ssh_remote_path_copy(self): mock_ssh = mock.MagicMock() vm_scenario = utils.VMScenario(self.context) vm_scenario._run_command_over_ssh( mock_ssh, { "remote_path": ["foo", "bar"], "local_path": "/bin/false", "command_args": ["arg1", "arg2"] }) mock_ssh.put_file.assert_called_once_with("/bin/false", "bar", mode=0o755) mock_ssh.execute.assert_called_once_with( ["foo", "bar", "arg1", "arg2"], stdin=None)
def get_scenario(self): server = mock.Mock(networks={"foo_net": "foo_data"}, addresses={"foo_net": [{ "addr": "foo_ip" }]}, tenant_id="foo_tenant") scenario = utils.VMScenario(self.context) scenario._boot_server = mock.Mock(return_value=server) scenario._delete_server = mock.Mock() scenario._associate_floating_ip = mock.Mock() scenario._wait_for_ping = mock.Mock() return scenario, server
def _customize_image(self, server, fip, user): code, out, err = vm_utils.VMScenario(self.context)._run_command( fip["ip"], self.config["port"], self.config["username"], self.config.get("password"), command=self.config["command"], pkey=user["keypair"]["private"]) if code: raise exceptions.ScriptError( message="Command `%(command)s' execution failed," " code %(code)d:\n" "STDOUT:\n============================\n" "%(out)s\n" "STDERR:\n============================\n" "%(err)s\n" "============================\n" % {"command": self.config["command"], "code": code, "out": out, "err": err}) return code, out, err
def test__run_command(self, mock_sshutils_ssh, mock_vm_scenario__run_command_over_ssh): vm_scenario = utils.VMScenario(self.context) vm_scenario.context = {"user": {"keypair": {"private": "ssh"}}} vm_scenario._run_command("1.2.3.4", 22, "username", "password", command={ "script_file": "foo", "interpreter": "bar" }) mock_sshutils_ssh.assert_called_once_with("username", "1.2.3.4", port=22, pkey="ssh", password="******") mock_sshutils_ssh.return_value.wait.assert_called_once_with(120, 1) mock_vm_scenario__run_command_over_ssh.assert_called_once_with( mock_sshutils_ssh.return_value, { "script_file": "foo", "interpreter": "bar" })
def test__wait_for_ssh(self): ssh = mock.MagicMock() vm_scenario = utils.VMScenario(self.context) vm_scenario._wait_for_ssh(ssh) ssh.wait.assert_called_once_with(120, 1)