def _create_servers(self, port_1, port_2):
        params = {
            'flavor_ref': CONF.compute.flavor_ref,
            'image_ref': CONF.compute.image_ref,
            'key_name': self.keypair['name']
        }
        vms = []
        vms.append(
            self.create_server(networks=[{
                'port': port_1['id']
            }], **params))

        if (CONF.compute.min_compute_nodes > 1 and
                compute.is_scheduler_filter_enabled("DifferentHostFilter")):
            params['scheduler_hints'] = {
                'different_host': [vms[0]['server']['id']]
            }

        vms.append(
            self.create_server(networks=[{
                'port': port_2['id']
            }], **params))

        for vm in vms:
            self.wait_for_server_active(vm['server'])

        return vms
예제 #2
0
    def _create_servers(self, port_1, port_2):
        params = {
            'flavor_ref': CONF.compute.flavor_ref,
            'image_ref': CONF.compute.image_ref,
            'key_name': self.keypair['name']
        }
        vm1 = self.create_server(networks=[{'port': port_1['id']}], **params)

        if (CONF.compute.min_compute_nodes > 1 and
                compute.is_scheduler_filter_enabled("DifferentHostFilter")):
            params['scheduler_hints'] = {
                'different_host': [vm1['server']['id']]
            }

        self.create_server(networks=[{'port': port_2['id']}], **params)
    def resource_setup(cls):
        super(TestSecurityGroupsBasicOps, cls).resource_setup()

        cls.multi_node = CONF.compute.min_compute_nodes > 1 and \
            compute.is_scheduler_filter_enabled("DifferentHostFilter")
        if cls.multi_node:
            LOG.info("Working in Multi Node mode")
        else:
            LOG.info("Working in Single Node mode")

        cls.floating_ips = {}
        cls.tenants = {}
        cls.primary_tenant = cls.TenantProperties(cls.os_primary)
        cls.alt_tenant = cls.TenantProperties(cls.os_alt)
        for tenant in [cls.primary_tenant, cls.alt_tenant]:
            cls.tenants[tenant.creds.tenant_id] = tenant

        cls.floating_ip_access = not CONF.network.public_router_id
예제 #4
0
    def resource_setup(cls):
        super(TestSecurityGroupsBasicOps, cls).resource_setup()

        cls.multi_node = CONF.compute.min_compute_nodes > 1 and \
            compute.is_scheduler_filter_enabled("DifferentHostFilter")
        if cls.multi_node:
            LOG.info("Working in Multi Node mode")
        else:
            LOG.info("Working in Single Node mode")

        cls.floating_ips = {}
        cls.tenants = {}
        cls.primary_tenant = cls.TenantProperties(cls.os_primary)
        cls.alt_tenant = cls.TenantProperties(cls.os_alt)
        for tenant in [cls.primary_tenant, cls.alt_tenant]:
            cls.tenants[tenant.creds.tenant_id] = tenant

        cls.floating_ip_access = not CONF.network.public_router_id
예제 #5
0
class ServersOnMultiNodesTest(base.BaseV2ComputeAdminTest):

    @classmethod
    def resource_setup(cls):
        super(ServersOnMultiNodesTest, cls).resource_setup()
        cls.server01 = cls.create_test_server(wait_until='ACTIVE')['id']
        cls.host01 = cls.get_host_for_server(cls.server01)

    @classmethod
    def skip_checks(cls):
        super(ServersOnMultiNodesTest, cls).skip_checks()

        if CONF.compute.min_compute_nodes < 2:
            raise cls.skipException(
                "Less than 2 compute nodes, skipping multi-nodes test.")

    def _create_servers_with_group(self, policy):
        group_id = self.create_test_server_group(policy=[policy])['id']
        hints = {'group': group_id}
        reservation_id = self.create_test_server(
            scheduler_hints=hints, wait_until='ACTIVE', min_count=2,
            return_reservation_id=True)['reservation_id']

        # Get the servers using the reservation_id.
        servers = self.servers_client.list_servers(
            detail=True, reservation_id=reservation_id)['servers']
        self.assertEqual(2, len(servers))

        # Assert the servers are in the group.
        server_group = self.server_groups_client.show_server_group(
            group_id)['server_group']
        hosts = {}
        for server in servers:
            self.assertIn(server['id'], server_group['members'])
            hosts[server['id']] = self.get_host_for_server(server['id'])

        return hosts

    @decorators.idempotent_id('26a9d5df-6890-45f2-abc4-a659290cb130')
    @testtools.skipUnless(
        compute.is_scheduler_filter_enabled("SameHostFilter"),
        'SameHostFilter is not available.')
    def test_create_servers_on_same_host(self):
        hints = {'same_host': self.server01}
        server02 = self.create_test_server(scheduler_hints=hints,
                                           wait_until='ACTIVE')['id']
        host02 = self.get_host_for_server(server02)
        self.assertEqual(self.host01, host02)

    @decorators.idempotent_id('cc7ca884-6e3e-42a3-a92f-c522fcf25e8e')
    @testtools.skipUnless(
        compute.is_scheduler_filter_enabled("DifferentHostFilter"),
        'DifferentHostFilter is not available.')
    def test_create_servers_on_different_hosts(self):
        hints = {'different_host': self.server01}
        server02 = self.create_test_server(scheduler_hints=hints,
                                           wait_until='ACTIVE')['id']
        host02 = self.get_host_for_server(server02)
        self.assertNotEqual(self.host01, host02)

    @decorators.idempotent_id('7869cc84-d661-4e14-9f00-c18cdc89cf57')
    @testtools.skipUnless(
        compute.is_scheduler_filter_enabled("DifferentHostFilter"),
        'DifferentHostFilter is not available.')
    def test_create_servers_on_different_hosts_with_list_of_servers(self):
        # This scheduler-hint supports list of servers also.
        hints = {'different_host': [self.server01]}
        server02 = self.create_test_server(scheduler_hints=hints,
                                           wait_until='ACTIVE')['id']
        host02 = self.get_host_for_server(server02)
        self.assertNotEqual(self.host01, host02)

    @decorators.idempotent_id('f8bd0867-e459-45f5-ba53-59134552fe04')
    @testtools.skipUnless(
        compute.is_scheduler_filter_enabled("ServerGroupAntiAffinityFilter"),
        'ServerGroupAntiAffinityFilter is not available.')
    def test_create_server_with_scheduler_hint_group_anti_affinity(self):
        """Tests the ServerGroupAntiAffinityFilter

        Creates two servers in an anti-affinity server group and
        asserts the servers are in the group and on different hosts.
        """
        hosts = self._create_servers_with_group('anti-affinity')
        hostnames = list(hosts.values())
        self.assertNotEqual(hostnames[0], hostnames[1],
                            'Servers are on the same host: %s' % hosts)

    @decorators.idempotent_id('9d2e924a-baf4-11e7-b856-fa163e65f5ce')
    @testtools.skipUnless(
        compute.is_scheduler_filter_enabled("ServerGroupAffinityFilter"),
        'ServerGroupAffinityFilter is not available.')
    def test_create_server_with_scheduler_hint_group_affinity(self):
        """Tests the ServerGroupAffinityFilter

        Creates two servers in an affinity server group and
        asserts the servers are in the group and on same host.
        """
        hosts = self._create_servers_with_group('affinity')
        hostnames = list(hosts.values())
        self.assertEqual(hostnames[0], hostnames[1],
                         'Servers are on the different hosts: %s' % hosts)
class LiveMigrationRemoteConsolesV26Test(LiveMigrationTestBase):
    min_microversion = '2.6'
    max_microversion = 'latest'

    @decorators.idempotent_id('6190af80-513e-4f0f-90f2-9714e84955d7')
    @testtools.skipUnless(CONF.compute_feature_enabled.serial_console,
                          'Serial console not supported.')
    @testtools.skipUnless(
        compute.is_scheduler_filter_enabled("DifferentHostFilter"),
        'DifferentHostFilter is not available.')
    def test_live_migration_serial_console(self):
        """Test the live-migration of an instance which has a serial console

        The serial console feature of an instance uses ports on the host.
        These ports need to be updated when they are already in use by
        another instance on the target host. This test checks if this
        update behavior is correctly done, by connecting to the serial
        consoles of the instances before and after the live migration.
        """
        server01_id = self.create_test_server(wait_until='ACTIVE')['id']
        hints = {'different_host': server01_id}
        server02_id = self.create_test_server(scheduler_hints=hints,
                                              wait_until='ACTIVE')['id']
        host01_id = self.get_host_for_server(server01_id)
        host02_id = self.get_host_for_server(server02_id)
        self.assertNotEqual(host01_id, host02_id)

        # At this step we have 2 instances on different hosts, both with
        # serial consoles, both with port 10000 (the default value).
        # https://bugs.launchpad.net/nova/+bug/1455252 describes the issue
        # when live-migrating in such a scenario.

        self._verify_console_interaction(server01_id)
        self._verify_console_interaction(server02_id)

        self._live_migrate(server01_id, host02_id, 'ACTIVE')
        self._verify_console_interaction(server01_id)
        # At this point, both instances have a valid serial console
        # connection, which means the ports got updated.

    def _verify_console_interaction(self, server_id):
        body = self.servers_client.get_remote_console(server_id,
                                                      console_type='serial',
                                                      protocol='serial')
        console_url = body['remote_console']['url']
        data = "test_live_migration_serial_console"
        console_output = ''
        t = 0.0
        interval = 0.1

        ws = compute.create_websocket(console_url)
        try:
            # NOTE (markus_z): It can take a long time until the terminal
            # of the instance is available for interaction. Hence the
            # long timeout value.
            while data not in console_output and t <= 120.0:
                try:
                    ws.send_frame(data)
                    received = ws.receive_frame()
                    console_output += received
                except Exception:
                    # In case we had an issue with send/receive on the
                    # websocket connection, we create a new one.
                    ws = compute.create_websocket(console_url)
                time.sleep(interval)
                t += interval
        finally:
            ws.close()
        self.assertIn(data, console_output)
예제 #7
0
class ServerGroupTestJSON(base.BaseV2ComputeTest):
    """These tests check for the server-group APIs.

    They create/delete server-groups with different policies.
    policies = affinity/anti-affinity
    It also adds the tests for list and get details of server-groups
    """
    create_default_network = True

    @classmethod
    def skip_checks(cls):
        super(ServerGroupTestJSON, cls).skip_checks()
        if not utils.is_extension_enabled('os-server-groups', 'compute'):
            msg = "os-server-groups extension is not enabled."
            raise cls.skipException(msg)

    @classmethod
    def setup_clients(cls):
        super(ServerGroupTestJSON, cls).setup_clients()
        cls.client = cls.server_groups_client

    @classmethod
    def _set_policy(cls, policy):
        if not cls.is_requested_microversion_compatible('2.63'):
            return policy[0]
        else:
            return policy

    @classmethod
    def resource_setup(cls):
        super(ServerGroupTestJSON, cls).resource_setup()
        if cls.is_requested_microversion_compatible('2.63'):
            cls.policy_field = 'policies'
            cls.policy = ['affinity']
        else:
            cls.policy_field = 'policy'
            cls.policy = 'affinity'

    def setUp(self):
        super(ServerGroupTestJSON, self).setUp()
        # TODO(zhufl): After microversion 2.13 project_id and user_id are
        # added to the body of server_group, and microversion is not used
        # in resource_setup for now, so we should create server group in setUp
        # in order to use the same microversion as in testcases till
        # microversion support in resource_setup is fulfilled.
        if not hasattr(self, 'created_server_group'):
            self.__class__.created_server_group = \
                self.create_test_server_group(policy=self.policy)

    def _create_server_group(self, name, policy):
        # create the test server-group with given policy
        server_group = {'name': name, self.policy_field: policy}
        body = self.create_test_server_group(name, policy)
        for key in ['name', self.policy_field]:
            self.assertEqual(server_group[key], body[key])
        return body

    def _delete_server_group(self, server_group):
        # delete the test server-group
        self.client.delete_server_group(server_group['id'])
        # validation of server-group deletion
        server_group_list = self.client.list_server_groups()['server_groups']
        self.assertNotIn(server_group, server_group_list)

    def _create_delete_server_group(self, policy):
        # Create and Delete the server-group with given policy
        name = data_utils.rand_name('server-group')
        server_group = self._create_server_group(name, policy)
        self._delete_server_group(server_group)

    @decorators.idempotent_id('5dc57eda-35b7-4af7-9e5f-3c2be3d2d68b')
    def test_create_delete_server_group_with_affinity_policy(self):
        """Test Create/Delete the server-group with affinity policy"""
        self._create_delete_server_group(self.policy)

    @decorators.idempotent_id('3645a102-372f-4140-afad-13698d850d23')
    def test_create_delete_server_group_with_anti_affinity_policy(self):
        """Test Create/Delete the server-group with anti-affinity policy"""
        policy = self._set_policy(['anti-affinity'])
        self._create_delete_server_group(policy)

    @decorators.idempotent_id('154dc5a4-a2fe-44b5-b99e-f15806a4a113')
    def test_create_delete_multiple_server_groups_with_same_name_policy(self):
        """Test Create/Delete the server-groups with same name and policy"""
        server_groups = []
        server_group_name = data_utils.rand_name('server-group')
        for _ in range(0, 2):
            server_groups.append(
                self._create_server_group(server_group_name, self.policy))
        for key in ['name', self.policy_field]:
            self.assertEqual(server_groups[0][key], server_groups[1][key])
        self.assertNotEqual(server_groups[0]['id'], server_groups[1]['id'])

        for i in range(0, 2):
            self._delete_server_group(server_groups[i])

    @decorators.idempotent_id('b3545034-dd78-48f0-bdc2-a4adfa6d0ead')
    def test_show_server_group(self):
        """Test getting the server-group detail"""
        body = self.client.show_server_group(
            self.created_server_group['id'])['server_group']
        self.assertEqual(self.created_server_group, body)

    @decorators.idempotent_id('d4874179-27b4-4d7d-80e4-6c560cdfe321')
    def test_list_server_groups(self):
        """Test listing the server-groups"""
        body = self.client.list_server_groups()['server_groups']
        self.assertIn(self.created_server_group, body)

    @decorators.idempotent_id('ed20d3fb-9d1f-4329-b160-543fbd5d9811')
    @testtools.skipUnless(
        compute.is_scheduler_filter_enabled("ServerGroupAffinityFilter"),
        'ServerGroupAffinityFilter is not available.')
    def test_create_server_with_scheduler_hint_group(self):
        """Test creating a server with the scheduler hint 'group'"""
        hints = {'group': self.created_server_group['id']}
        server = self.create_test_server(scheduler_hints=hints,
                                         wait_until='ACTIVE')
        self.addCleanup(self.delete_server, server['id'])

        # Check a server is in the group
        server_group = (self.server_groups_client.show_server_group(
            self.created_server_group['id'])['server_group'])
        self.assertIn(server['id'], server_group['members'])
예제 #8
0
class ServersTestJSON(base.BaseV2ComputeTest):
    disk_config = 'AUTO'
    volume_backed = False

    @classmethod
    def setup_credentials(cls):
        cls.prepare_instance_network()
        super(ServersTestJSON, cls).setup_credentials()

    @classmethod
    def setup_clients(cls):
        super(ServersTestJSON, cls).setup_clients()
        cls.client = cls.servers_client

    @classmethod
    def resource_setup(cls):
        cls.set_validation_resources()
        super(ServersTestJSON, cls).resource_setup()
        cls.meta = {'hello': 'world'}
        cls.accessIPv4 = '1.1.1.1'
        cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
        cls.name = data_utils.rand_name(cls.__name__ + '-server')
        cls.password = data_utils.rand_password()
        disk_config = cls.disk_config
        server_initial = cls.create_test_server(
            validatable=True,
            wait_until='ACTIVE',
            name=cls.name,
            metadata=cls.meta,
            accessIPv4=cls.accessIPv4,
            accessIPv6=cls.accessIPv6,
            disk_config=disk_config,
            adminPass=cls.password,
            volume_backed=cls.volume_backed)
        cls.server = (cls.client.show_server(server_initial['id'])
                      ['server'])

    @decorators.attr(type='smoke')
    @decorators.idempotent_id('5de47127-9977-400a-936f-abcfbec1218f')
    def test_verify_server_details(self):
        # Verify the specified server attributes are set correctly
        self.assertEqual(self.accessIPv4, self.server['accessIPv4'])
        # NOTE(maurosr): See http://tools.ietf.org/html/rfc5952 (section 4)
        # Here we compare directly with the canonicalized format.
        self.assertEqual(self.server['accessIPv6'],
                         str(netaddr.IPAddress(self.accessIPv6)))
        self.assertEqual(self.name, self.server['name'])
        if self.volume_backed:
            # Image is an empty string as per documentation
            self.assertEqual("", self.server['image'])
        else:
            self.assertEqual(self.image_ref, self.server['image']['id'])
        self.assertEqual(self.flavor_ref, self.server['flavor']['id'])
        self.assertEqual(self.meta, self.server['metadata'])

    @decorators.attr(type='smoke')
    @decorators.idempotent_id('9a438d88-10c6-4bcd-8b5b-5b6e25e1346f')
    def test_list_servers(self):
        # The created server should be in the list of all servers
        body = self.client.list_servers()
        servers = body['servers']
        found = [i for i in servers if i['id'] == self.server['id']]
        self.assertNotEmpty(found)

    @decorators.idempotent_id('585e934c-448e-43c4-acbf-d06a9b899997')
    def test_list_servers_with_detail(self):
        # The created server should be in the detailed list of all servers
        body = self.client.list_servers(detail=True)
        servers = body['servers']
        found = [i for i in servers if i['id'] == self.server['id']]
        self.assertNotEmpty(found)

    @decorators.idempotent_id('cbc0f52f-05aa-492b-bdc1-84b575ca294b')
    @testtools.skipUnless(CONF.validation.run_validation,
                          'Instance validation tests are disabled.')
    def test_verify_created_server_vcpus(self):
        # Verify that the number of vcpus reported by the instance matches
        # the amount stated by the flavor
        flavor = self.flavors_client.show_flavor(self.flavor_ref)['flavor']
        linux_client = remote_client.RemoteClient(
            self.get_server_ip(self.server),
            self.ssh_user,
            self.password,
            self.validation_resources['keypair']['private_key'],
            server=self.server,
            servers_client=self.client)
        output = linux_client.exec_command('grep -c ^processor /proc/cpuinfo')
        self.assertEqual(flavor['vcpus'], int(output))

    @decorators.idempotent_id('ac1ad47f-984b-4441-9274-c9079b7a0666')
    @testtools.skipUnless(CONF.validation.run_validation,
                          'Instance validation tests are disabled.')
    def test_host_name_is_same_as_server_name(self):
        # Verify the instance host name is the same as the server name
        linux_client = remote_client.RemoteClient(
            self.get_server_ip(self.server),
            self.ssh_user,
            self.password,
            self.validation_resources['keypair']['private_key'],
            server=self.server,
            servers_client=self.client)
        hostname = linux_client.exec_command("hostname").rstrip()
        msg = ('Failed while verifying servername equals hostname. Expected '
               'hostname "%s" but got "%s".' % (self.name, hostname))
        self.assertEqual(self.name.lower(), hostname, msg)

    @decorators.idempotent_id('ed20d3fb-9d1f-4329-b160-543fbd5d9811')
    @testtools.skipUnless(
        compute.is_scheduler_filter_enabled("ServerGroupAffinityFilter"),
        'ServerGroupAffinityFilter is not available.')
    def test_create_server_with_scheduler_hint_group(self):
        # Create a server with the scheduler hint "group".
        group_id = self.create_test_server_group()['id']
        hints = {'group': group_id}
        server = self.create_test_server(scheduler_hints=hints,
                                         wait_until='ACTIVE')

        # Check a server is in the group
        server_group = (self.server_groups_client.show_server_group(group_id)
                        ['server_group'])
        self.assertIn(server['id'], server_group['members'])
예제 #9
0
class ServerGroupTestJSON(base.BaseV2ComputeTest):
    """These tests check for the server-group APIs.

    They create/delete server-groups with different policies.
    policies = affinity/anti-affinity
    It also adds the tests for list and get details of server-groups
    """
    @classmethod
    def skip_checks(cls):
        super(ServerGroupTestJSON, cls).skip_checks()
        if not utils.is_extension_enabled('os-server-groups', 'compute'):
            msg = "os-server-groups extension is not enabled."
            raise cls.skipException(msg)

    @classmethod
    def setup_clients(cls):
        super(ServerGroupTestJSON, cls).setup_clients()
        cls.client = cls.server_groups_client

    @classmethod
    def resource_setup(cls):
        super(ServerGroupTestJSON, cls).resource_setup()
        cls.policy = ['affinity']

        cls.created_server_group = cls.create_test_server_group(
            policy=cls.policy)

    def _create_server_group(self, name, policy):
        # create the test server-group with given policy
        server_group = {'name': name, 'policies': policy}
        body = self.create_test_server_group(name, policy)
        for key in ['name', 'policies']:
            self.assertEqual(server_group[key], body[key])
        return body

    def _delete_server_group(self, server_group):
        # delete the test server-group
        self.client.delete_server_group(server_group['id'])
        # validation of server-group deletion
        server_group_list = self.client.list_server_groups()['server_groups']
        self.assertNotIn(server_group, server_group_list)

    def _create_delete_server_group(self, policy):
        # Create and Delete the server-group with given policy
        name = data_utils.rand_name('server-group')
        server_group = self._create_server_group(name, policy)
        self._delete_server_group(server_group)

    @decorators.idempotent_id('5dc57eda-35b7-4af7-9e5f-3c2be3d2d68b')
    def test_create_delete_server_group_with_affinity_policy(self):
        # Create and Delete the server-group with affinity policy
        self._create_delete_server_group(self.policy)

    @decorators.idempotent_id('3645a102-372f-4140-afad-13698d850d23')
    def test_create_delete_server_group_with_anti_affinity_policy(self):
        # Create and Delete the server-group with anti-affinity policy
        policy = ['anti-affinity']
        self._create_delete_server_group(policy)

    @decorators.idempotent_id('154dc5a4-a2fe-44b5-b99e-f15806a4a113')
    def test_create_delete_multiple_server_groups_with_same_name_policy(self):
        # Create and Delete the server-groups with same name and same policy
        server_groups = []
        server_group_name = data_utils.rand_name('server-group')
        for _ in range(0, 2):
            server_groups.append(
                self._create_server_group(server_group_name, self.policy))
        for key in ['name', 'policies']:
            self.assertEqual(server_groups[0][key], server_groups[1][key])
        self.assertNotEqual(server_groups[0]['id'], server_groups[1]['id'])

        for i in range(0, 2):
            self._delete_server_group(server_groups[i])

    @decorators.idempotent_id('b3545034-dd78-48f0-bdc2-a4adfa6d0ead')
    def test_show_server_group(self):
        # Get the server-group
        body = self.client.show_server_group(
            self.created_server_group['id'])['server_group']
        self.assertEqual(self.created_server_group, body)

    @decorators.idempotent_id('d4874179-27b4-4d7d-80e4-6c560cdfe321')
    def test_list_server_groups(self):
        # List the server-group
        body = self.client.list_server_groups()['server_groups']
        self.assertIn(self.created_server_group, body)

    @decorators.idempotent_id('ed20d3fb-9d1f-4329-b160-543fbd5d9811')
    @testtools.skipUnless(
        compute.is_scheduler_filter_enabled("ServerGroupAffinityFilter"),
        'ServerGroupAffinityFilter is not available.')
    def test_create_server_with_scheduler_hint_group(self):
        # Create a server with the scheduler hint "group".
        hints = {'group': self.created_server_group['id']}
        server = self.create_test_server(scheduler_hints=hints,
                                         wait_until='ACTIVE')
        self.addCleanup(self.delete_server, server['id'])

        # Check a server is in the group
        server_group = (self.server_groups_client.show_server_group(
            self.created_server_group['id'])['server_group'])
        self.assertIn(server['id'], server_group['members'])