Exemplo n.º 1
0
    def test__ping_ip_address_linux(self, mock_subprocess, mock_sys):
        ping_process = mock.MagicMock()
        ping_process.returncode = 0
        mock_subprocess.return_value = ping_process
        mock_sys.platform = "linux2"

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

        mock_subprocess.assert_called_once_with(
            ["ping", "-c1", "-w1", host_ip],
            stderr=subprocess.PIPE,
            stdout=subprocess.PIPE)
        ping_process.wait.assert_called_once_with()
Exemplo n.º 2
0
    def test_run_command(self, mock_ssh_class, mock_wait_ping,
                         mock_run_action):
        mock_ssh_instance = mock.MagicMock()
        mock_ssh_class.return_value = mock_ssh_instance

        vm_scenario = utils.VMScenario()
        vm_scenario._context = {"user": {"keypair": {"private": "ssh"}}}
        vm_scenario.run_command("1.2.3.4", 22, "username", "int", "script")

        mock_wait_ping.assert_called_once_with("1.2.3.4")
        mock_ssh_class.assert_called_once_with("username", "1.2.3.4", port=22,
                                               pkey="ssh")
        mock_ssh_instance.wait.assert_called_once_with()
        mock_run_action.assert_called_once_with(mock_ssh_instance,
                                                "int", "script")
Exemplo n.º 3
0
    def get_scenario(self):

        server = mock.Mock(networks={"foo_net": "foo_data"},
                           addresses={"foo_net": [{
                               "addr": "foo_addr"
                           }]},
                           tenant_id="foo_tenant")
        scenario = utils.VMScenario(context={})

        scenario._netwrap = mock.Mock()
        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
Exemplo n.º 4
0
    def test_run_command(self, mock_ssh_class, mock_run_action):
        mock_ssh_instance = mock.MagicMock()
        mock_ssh_class.return_value = mock_ssh_instance
        fake_server = fakes.FakeServer()
        fake_server.addresses = dict(private=[dict(version=4, addr="1.2.3.4")])
        vm_scenario = utils.VMScenario()
        vm_scenario._context = {"user": {"keypair": {"private": "ssh"}}}
        vm_scenario.run_command(fake_server, "username", "private", 22, 4,
                                "int", "script")

        mock_ssh_class.assert_called_once_with("username",
                                               "1.2.3.4",
                                               port=22,
                                               pkey="ssh")
        mock_ssh_instance.wait.assert_called_once_with()
        mock_run_action.assert_called_once_with(mock_ssh_instance, "int",
                                                "script")
Exemplo n.º 5
0
    def test__run_command(self, mock_ssh_class, mock_run_command_over_ssh):
        mock_ssh_instance = mock.MagicMock()
        mock_ssh_class.return_value = mock_ssh_instance

        vm_scenario = utils.VMScenario()
        vm_scenario.context = {"user": {"keypair": {"private": "ssh"}}}
        vm_scenario._run_command("1.2.3.4",
                                 22,
                                 "username",
                                 "password",
                                 "int",
                                 "/path/to/foo/script.sh",
                                 is_file=True)

        mock_ssh_class.assert_called_once_with("username",
                                               "1.2.3.4",
                                               port=22,
                                               pkey="ssh",
                                               password="******")
        mock_ssh_instance.wait.assert_called_once_with()
        mock_run_command_over_ssh.assert_called_once_with(
            mock_ssh_instance, "int", "/path/to/foo/script.sh", True)
Exemplo n.º 6
0
 def test__run_command_inline_script(self, mock_ssh):
     mock_ssh_instance = mock.MagicMock()
     mock_ssh.return_value = mock_ssh_instance
     mock_ssh_instance.execute.return_value = "foobar"
     vm_scenario = utils.VMScenario()
     vm_scenario._wait_for_ssh = mock.Mock()
     vm_scenario.context = {"user": {"keypair": {"private": "foo_pkey"}}}
     result = vm_scenario._run_command("foo_ip",
                                       "foo_port",
                                       "foo_username",
                                       "foo_password",
                                       "foo_interpreter",
                                       "foo_script",
                                       is_file=False)
     mock_ssh.assert_called_once_with("foo_username",
                                      "foo_ip",
                                      port="foo_port",
                                      pkey="foo_pkey",
                                      password="******")
     vm_scenario._wait_for_ssh.assert_called_once_with(mock_ssh_instance)
     mock_ssh_instance.execute.assert_called_once_with("foo_interpreter",
                                                       stdin="foo_script")
     self.assertEqual(result, "foobar")
Exemplo n.º 7
0
 def test__wait_for_ping(self, mock__ping):
     vm_scenario = utils.VMScenario()
     vm_scenario._wait_for_ping("1.2.3.4")
     self.wait_for.mock.assert_called_once_with("1.2.3.4",
                                                is_ready=mock__ping,
                                                timeout=120)
Exemplo n.º 8
0
 def test__wait_for_ssh(self):
     ssh = mock.MagicMock()
     vm_scenario = utils.VMScenario()
     vm_scenario._wait_for_ssh(ssh)
     ssh.wait.assert_called_once_with()
Exemplo n.º 9
0
 def test__run_command_over_ssh_fails(self):
     vm_scenario = utils.VMScenario()
     self.assertRaises(exceptions.ScriptError,
                       vm_scenario._run_command_over_ssh, None,
                       "interpreter", 10)
Exemplo n.º 10
0
 def test__run_command_over_ssh_stringio(self):
     mock_ssh = mock.MagicMock()
     vm_scenario = utils.VMScenario()
     script = six.moves.StringIO("script")
     vm_scenario._run_command_over_ssh(mock_ssh, "interpreter", script)
     mock_ssh.execute.assert_called_once_with("interpreter", stdin=script)
Exemplo n.º 11
0
 def test__run_command_over_ssh(self, mock_open):
     mock_ssh = mock.MagicMock()
     vm_scenario = utils.VMScenario()
     vm_scenario._run_command_over_ssh(mock_ssh, "interpreter", "script")
     mock_ssh.execute.assert_called_once_with("interpreter",
                                              stdin=mock_open.side_effect())