Esempio n. 1
0
    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
Esempio n. 2
0
 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)
Esempio n. 3
0
 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.benchmark.vm_ping_timeout,
         check_interval=CONF.benchmark.vm_ping_poll_interval)
Esempio n. 4
0
 def test__wait_for_ping(self, mock_vm_scenario__ping_ip_address,
                         mock_resource_is):
     vm_scenario = utils.VMScenario()
     vm_scenario._wait_for_ping(netaddr.IPAddress("1.2.3.4"))
     self.wait_for.mock.assert_called_once_with(
         netaddr.IPAddress("1.2.3.4"),
         is_ready=mock_resource_is.return_value,
         timeout=120)
     mock_resource_is.assert_called_once_with(
         "ICMP UP", mock_vm_scenario__ping_ip_address)
Esempio n. 5
0
 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.mock.assert_called_once_with(
         netaddr.IPAddress("1.2.3.4"),
         is_ready=self.mock_resource_is.mock.return_value,
         timeout=CONF.benchmark.vm_ping_timeout,
         check_interval=CONF.benchmark.vm_ping_poll_interval)
     self.mock_resource_is.mock.assert_called_once_with(
         "ICMP UP", vm_scenario._ping_ip_address)
Esempio n. 6
0
    def test__ping_ip_address_other_os_ipv6(self, mock_popen, mock_sys):
        mock_popen.return_value.returncode = 0
        mock_sys.platform = "freebsd10"

        vm_scenario = utils.VMScenario()
        host_ip = netaddr.IPAddress("1ce:c01d:bee2:15:a5:900d:a5:11fe")
        self.assertTrue(vm_scenario._ping_ip_address(host_ip))

        mock_popen.assert_called_once_with(
            ["ping6", "-c1", str(host_ip)],
            stderr=subprocess.PIPE, stdout=subprocess.PIPE)
        mock_popen.return_value.wait.assert_called_once_with()
Esempio n. 7
0
    def test__ping_ip_address_linux(self, mock_popen, mock_sys):
        mock_popen.return_value.returncode = 0
        mock_sys.platform = "linux2"

        vm_scenario = utils.VMScenario()
        host_ip = netaddr.IPAddress("1.2.3.4")
        self.assertTrue(vm_scenario._ping_ip_address(host_ip))

        mock_popen.assert_called_once_with(
            ["ping", "-c1", "-w1", str(host_ip)],
            stderr=subprocess.PIPE, stdout=subprocess.PIPE)
        mock_popen.return_value.wait.assert_called_once_with()
Esempio n. 8
0
 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")
Esempio n. 9
0
 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")
Esempio n. 10
0
 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)
Esempio n. 11
0
    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
Esempio n. 12
0
    def test__run_command(self, mock_sshutils_ssh,
                          mock_vm_scenario__run_command_over_ssh):
        vm_scenario = utils.VMScenario()
        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()
        mock_vm_scenario__run_command_over_ssh.assert_called_once_with(
            mock_sshutils_ssh.return_value,
            {"script_file": "foo", "interpreter": "bar"})
Esempio n. 13
0
 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()
Esempio n. 14
0
 def test__run_command_over_ssh_fails(self):
     vm_scenario = utils.VMScenario(self.context)
     self.assertRaises(ValueError,
                       vm_scenario._run_command_over_ssh,
                       None,
                       command={})