示例#1
0
    def _verify_boot_server(self, mock_choice, mock_osclients, mock_boot,
                            mock_random_name, nic=None, assert_nic=False):
        assert_nic = nic or assert_nic
        kwargs = {'fakearg': 'f'}
        expected_kwargs = {'fakearg': 'f'}

        fc = test_utils.FakeClients()
        mock_osclients.Clients.return_value = fc
        nova = test_utils.FakeNovaClient()
        fc.get_nova_client = lambda: nova

        temp_keys = ["username", "password", "tenant_name", "uri"]
        users_endpoints = [dict(zip(temp_keys, temp_keys))]
        servers.NovaServers._clients = butils._create_openstack_clients(
                                                users_endpoints, temp_keys)[0]

        mock_boot.return_value = object()
        mock_random_name.return_value = "random_name"
        if nic:
            kwargs['nics'] = nic
        if assert_nic:
            nova.networks.create('net-1')
            network = nova.networks.create('net-2')
            mock_choice.return_value = network
            expected_kwargs['nics'] = nic or [{'net-id': 'net-2'}]
        servers.NovaServers.boot_server("img", 0, **kwargs)

        mock_boot.assert_called_once_with("random_name", "img", 0,
                                          **expected_kwargs)
示例#2
0
    def test_cleanup_failed(self):
        with mock.patch(self.osclients) as mock_osclients:
            fc = FakeClients()
            mock_osclients.Clients.return_value = fc
            failed_nova = FakeNovaClient(failed_server_manager=True)
            fc.get_nova_client = lambda: failed_nova

            temp_keys = ["username", "password", "tenant_name", "uri"]
            users_endpoints = [dict(zip(temp_keys, temp_keys))]
            utils.NovaScenario._clients = butils._create_openstack_clients(users_endpoints, temp_keys)[0]

            with mock.patch(self.sleep):
                # NOTE(boden): verify failed server cleanup
                self.assertRaises(rally_exceptions.GetResourceFailure, utils.NovaScenario._boot_server, "fails", 0, 1)
            self.assertEquals(len(failed_nova.servers.list()), 1, "Server not created")
            utils.NovaScenario.cleanup()
            self.assertEquals(len(failed_nova.servers.list()), 0, "Servers not purged")
示例#3
0
    def test_cleanup(self):
        with mock.patch(self.osclients) as mock_osclients:
            fc = FakeClients()
            mock_osclients.Clients.return_value = fc
            fake_nova = FakeNovaClient()
            fc.get_nova_client = lambda: fake_nova

            temp_keys = ["username", "password", "tenant_name", "uri"]
            users_endpoints = [dict(zip(temp_keys, temp_keys))]
            utils.NovaScenario._clients = butils._create_openstack_clients(users_endpoints, temp_keys)[0]

            # NOTE(boden): verify active server cleanup
            with mock.patch(self.sleep):
                for i in range(5):
                    utils.NovaScenario._boot_server("server-%s" % i, 0, 1)
            self.assertEquals(len(fake_nova.servers.list()), 5, "Server not created")
            utils.NovaScenario.cleanup()
            self.assertEquals(len(fake_nova.servers.list()), 0, "Servers not purged")
示例#4
0
    def test_server_helper_methods(self):
        with mock.patch(self.rally_utils) as mock_rally_utils:
            with mock.patch(self.utils_resource_is) as mock_resource_is:
                mock_resource_is.return_value = {}
                with mock.patch(self.osclients) as mock_osclients:
                    fc = FakeClients()
                    mock_osclients.Clients.return_value = fc
                    fake_nova = FakeNovaClient()
                    fc.get_nova_client = lambda: fake_nova
                    fsm = FakeServerManager()
                    fake_server = fsm.create("s1", "i1", 1)
                    fsm.create = lambda name, iid, fid: fake_server
                    fake_nova.servers = fsm

                    temp_keys = ["username", "password", "tenant_name", "uri"]
                    users_endpoints = [dict(zip(temp_keys, temp_keys))]
                    utils.NovaScenario._clients = butils._create_openstack_clients(users_endpoints, temp_keys)[0]

                    with mock.patch(self.sleep):
                        utils.NovaScenario._boot_server("s1", "i1", 1)
                        utils.NovaScenario._create_image(fake_server)
                        utils.NovaScenario._suspend_server(fake_server)
                        utils.NovaScenario._delete_server(fake_server)

        expected = [
            mock.call.wait_for(
                fake_server, is_ready={}, update_resource=utils._get_from_manager, timeout=600, check_interval=3
            ),
            mock.call.wait_for(
                "img_uuid", is_ready={}, update_resource=utils._get_from_manager, timeout=600, check_interval=3
            ),
            mock.call.wait_for(
                fake_server, is_ready={}, update_resource=utils._get_from_manager, timeout=600, check_interval=3
            ),
            mock.call.wait_for(
                fake_server,
                is_ready=utils._false,
                update_resource=utils._get_from_manager,
                timeout=600,
                check_interval=3,
            ),
        ]

        self.assertEqual(mock_rally_utils.mock_calls, expected)