Ejemplo n.º 1
0
 def test_server_create_op(self):
     keypair = self.create_keypair()
     security_group = self._create_security_group()
     self.md = {'meta1': 'data1', 'meta2': 'data2', 'metaN': 'dataN'}
     self.accessIPv4 = '1.1.1.1'
     self.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
     self.name = data_utils.rand_name(self.__class__.__name__ + '-server')
     self.password = data_utils.rand_password()
     self.instance = self.create_server(
         image_id=self.image_ref,
         flavor=self.flavor_ref,
         key_name=keypair['name'],
         security_groups=[{
             'name': security_group['name']
         }],
         config_drive=CONF.compute_feature_enabled.config_drive,
         metadata=self.md,
         accessIPv4=self.accessIPv4,
         accessIPv6=self.accessIPv6,
         name=self.name,
         adminPass=self.password,
         wait_until='ACTIVE')
     self.verify_list_servers()
     self.verify_list_servers_with_detail()
     self.verify_server_details()
     self.verify_ssh(keypair)
     self.verify_created_server_vcpus()
     self.verify_host_name_is_same_as_server_name()
     self.verify_metadata()
     self.verify_metadata_on_config_drive()
     self.verify_networkdata_on_config_drive()
     self.servers_client.delete_server(self.instance['id'])
     waiters.wait_for_server_termination(self.servers_client,
                                         self.instance['id'],
                                         ignore_error=False)
Ejemplo n.º 2
0
 def _image_create(self,
                   name,
                   fmt,
                   path,
                   disk_format=None,
                   properties=None):
     if properties is None:
         properties = {}
     name = data_utils.rand_name('%s-' % name)
     params = {
         'name': name,
         'container_format': fmt,
         'disk_format': disk_format or fmt,
     }
     if CONF.image_feature_enabled.api_v1:
         params['is_public'] = 'False'
         params['properties'] = properties
         params = {'headers': common_image.image_meta_to_headers(**params)}
     else:
         params['visibility'] = 'private'
         # Additional properties are flattened out in the v2 API.
         params.update(properties)
     body = self.image_client.create_image(**params)
     image = body['image'] if 'image' in body else body
     self.addCleanup(self.image_client.delete_image, image['id'])
     self.assertEqual("queued", image['status'])
     with open(path, 'rb') as image_file:
         if CONF.image_feature_enabled.api_v1:
             self.image_client.update_image(image['id'], data=image_file)
         else:
             self.image_client.store_image_file(image['id'], image_file)
     return image['id']
Ejemplo n.º 3
0
 def create_keypair(self, client=None):
     if not client:
         client = self.keypairs_client
     name = data_utils.rand_name(self.__class__.__name__)
     # We don't need to create a keypair by pubkey in scenario
     body = client.create_keypair(name=name)
     self.addCleanup(client.delete_keypair, name)
     return body['keypair']
Ejemplo n.º 4
0
 def _create_port(self,
                  network_id,
                  client=None,
                  namestart='port-quotatest',
                  **kwargs):
     if not client:
         client = self.ports_client
     name = data_utils.rand_name(namestart)
     result = client.create_port(name=name, network_id=network_id, **kwargs)
     self.assertIsNotNone(result, 'Unable to allocate port')
     port = result['port']
     self.addCleanup(test_utils.call_and_ignore_notfound_exc,
                     client.delete_port, port['id'])
     return port
Ejemplo n.º 5
0
def create_ssh_security_group(os, add_rule=False):
    security_groups_client = os.compute_security_groups_client
    security_group_rules_client = os.compute_security_group_rules_client
    sg_name = data_utils.rand_name('securitygroup-')
    sg_description = data_utils.rand_name('description-')
    security_group = security_groups_client.create_security_group(
        name=sg_name, description=sg_description)['security_group']
    if add_rule:
        if CONF.service_available.neutron:
            _create_neutron_sec_group_rules(os, security_group)
        else:
            security_group_rules_client.create_security_group_rule(
                parent_group_id=security_group['id'],
                ip_protocol='tcp',
                from_port=22,
                to_port=22)
            security_group_rules_client.create_security_group_rule(
                parent_group_id=security_group['id'],
                ip_protocol='icmp',
                from_port=-1,
                to_port=-1)
    LOG.debug("SSH Validation resource security group with tcp and icmp "
              "rules %s created" % sg_name)
    return security_group
Ejemplo n.º 6
0
    def _create_security_group(self):
        # Create security group
        sg_name = data_utils.rand_name(self.__class__.__name__)
        sg_desc = sg_name + " description"
        secgroup = self.compute_security_groups_client.create_security_group(
            name=sg_name, description=sg_desc)['security_group']
        self.assertEqual(secgroup['name'], sg_name)
        self.assertEqual(secgroup['description'], sg_desc)
        self.addCleanup(
            test_utils.call_and_ignore_notfound_exc,
            self.compute_security_groups_client.delete_security_group,
            secgroup['id'])

        # Add rules to the security group
        self._create_loginable_secgroup_rule(secgroup['id'])

        return secgroup
Ejemplo n.º 7
0
    def create_server_snapshot(self, server, name=None):
        # Glance client
        _image_client = self.image_client
        # Compute client
        _images_client = self.compute_images_client
        if name is None:
            name = data_utils.rand_name(self.__class__.__name__ + 'snapshot')
        LOG.debug("Creating a snapshot image for server: %s", server['name'])
        image = _images_client.create_image(server['id'], name=name)
        image_id = image.response['location'].split('images/')[1]
        waiters.wait_for_image_status(_image_client, image_id, 'active')

        self.addCleanup(_image_client.wait_for_resource_deletion, image_id)
        self.addCleanup(test_utils.call_and_ignore_notfound_exc,
                        _image_client.delete_image, image_id)

        if CONF.image_feature_enabled.api_v1:
            # In glance v1 the additional properties are stored in the headers.
            resp = _image_client.check_image(image_id)
            snapshot_image = common_image.get_image_meta_from_headers(resp)
            image_props = snapshot_image.get('properties', {})
        else:
            # In glance v2 the additional properties are flattened.
            snapshot_image = _image_client.show_image(image_id)
            image_props = snapshot_image

        bdm = image_props.get('block_device_mapping')
        if bdm:
            bdm = json.loads(bdm)
            if bdm and 'snapshot_id' in bdm[0]:
                snapshot_id = bdm[0]['snapshot_id']
                self.addCleanup(
                    self.snapshots_client.wait_for_resource_deletion,
                    snapshot_id)
                self.addCleanup(test_utils.call_and_ignore_notfound_exc,
                                self.snapshots_client.delete_snapshot,
                                snapshot_id)
                waiters.wait_for_snapshot_status(self.snapshots_client,
                                                 snapshot_id, 'available')
        image_name = snapshot_image['name']
        self.assertEqual(name, image_name)
        LOG.debug("Created snapshot image %s for server %s", image_name,
                  server['name'])
        return snapshot_image
Ejemplo n.º 8
0
def create_validation_resources(os, validation_resources=None):
    # Create and Return the validation resources required to validate a VM
    validation_data = {}
    if validation_resources:
        if validation_resources['keypair']:
            keypair_name = data_utils.rand_name('keypair')
            validation_data.update(
                os.keypairs_client.create_keypair(name=keypair_name))
            LOG.debug("Validation resource key %s created" % keypair_name)
        add_rule = False
        if validation_resources['security_group']:
            if validation_resources['security_group_rules']:
                add_rule = True
            validation_data['security_group'] = \
                create_ssh_security_group(os, add_rule)
        if validation_resources['floating_ip']:
            floating_client = os.compute_floating_ips_client
            validation_data.update(
                floating_client.create_floating_ip(
                    pool=CONF.network.floating_network_name))
    return validation_data
Ejemplo n.º 9
0
    def create_volume(self,
                      size=None,
                      name=None,
                      snapshot_id=None,
                      imageRef=None,
                      volume_type=None):
        if size is None:
            size = CONF.volume.volume_size
        if imageRef:
            image = self.compute_images_client.show_image(imageRef)['image']
            min_disk = image.get('minDisk')
            size = max(size, min_disk)
        if name is None:
            name = data_utils.rand_name(self.__class__.__name__ + "-volume")
        kwargs = {
            'display_name': name,
            'snapshot_id': snapshot_id,
            'imageRef': imageRef,
            'volume_type': volume_type,
            'size': size
        }
        volume = self.volumes_client.create_volume(**kwargs)['volume']

        self.addCleanup(self.volumes_client.wait_for_resource_deletion,
                        volume['id'])
        self.addCleanup(test_utils.call_and_ignore_notfound_exc,
                        self.volumes_client.delete_volume, volume['id'])

        # NOTE(e0ne): Cinder API v2 uses name instead of display_name
        if 'display_name' in volume:
            self.assertEqual(name, volume['display_name'])
        else:
            self.assertEqual(name, volume['name'])
        waiters.wait_for_volume_status(self.volumes_client, volume['id'],
                                       'available')
        # The volume retrieved on creation has a non-up-to-date status.
        # Retrieval after it becomes active ensures correct details.
        volume = self.volumes_client.show_volume(volume['id'])['volume']
        return volume
Ejemplo n.º 10
0
    def create_server(self,
                      name=None,
                      image_id=None,
                      flavor=None,
                      validatable=False,
                      wait_until=None,
                      clients=None,
                      **kwargs):
        """Wrapper utility that returns a test server.

        This wrapper utility calls the common create test server and
        returns a test server. The purpose of this wrapper is to minimize
        the impact on the code of the tests already using this
        function.
        """

        # NOTE(jlanoux): As a first step, ssh checks in the scenario
        # tests need to be run regardless of the run_validation and
        # validatable parameters and thus until the ssh validation job
        # becomes voting in CI. The test resources management and IP
        # association are taken care of in the scenario tests.
        # Therefore, the validatable parameter is set to false in all
        # those tests. In this way create_server just return a standard
        # server and the scenario tests always perform ssh checks.

        # Needed for the cross_tenant_traffic test:
        if clients is None:
            clients = self.manager

        if name is None:
            name = data_utils.rand_name(self.__class__.__name__ + "-server")

        vnic_type = CONF.network.port_vnic_type

        # If vnic_type is configured create port for
        # every network
        if vnic_type:
            ports = []

            create_port_body = {
                'binding:vnic_type': vnic_type,
                'namestart': 'port-smoke'
            }
            if kwargs:
                # Convert security group names to security group ids
                # to pass to create_port
                if 'security_groups' in kwargs:
                    security_groups =\
                        clients.security_groups_client.list_security_groups(
                        ).get('security_groups')
                    sec_dict = dict([(s['name'], s['id'])
                                     for s in security_groups])

                    sec_groups_names = [
                        s['name'] for s in kwargs.pop('security_groups')
                    ]
                    security_groups_ids = [
                        sec_dict[s] for s in sec_groups_names
                    ]

                    if security_groups_ids:
                        create_port_body[
                            'security_groups'] = security_groups_ids
                networks = kwargs.pop('networks', [])
            else:
                networks = []

            # If there are no networks passed to us we look up
            # for the project's private networks and create a port.
            # The same behaviour as we would expect when passing
            # the call to the clients with no networks
            if not networks:
                networks = clients.networks_client.list_networks(
                    **{
                        'router:external': False,
                        'fields': 'id'
                    })['networks']

            # It's net['uuid'] if networks come from kwargs
            # and net['id'] if they come from
            # clients.networks_client.list_networks
            for net in networks:
                net_id = net.get('uuid', net.get('id'))
                if 'port' not in net:
                    port = self._create_port(network_id=net_id,
                                             client=clients.ports_client,
                                             **create_port_body)
                    ports.append({'port': port['id']})
                else:
                    ports.append({'port': net['port']})
            if ports:
                kwargs['networks'] = ports
            self.ports = ports

        tenant_network = self.get_tenant_network()

        body, servers = compute.create_test_server(
            clients,
            tenant_network=tenant_network,
            wait_until=wait_until,
            name=name,
            flavor=flavor,
            image_id=image_id,
            **kwargs)

        self.addCleanup(waiters.wait_for_server_termination,
                        clients.servers_client, body['id'])
        self.addCleanup(test_utils.call_and_ignore_notfound_exc,
                        clients.servers_client.delete_server, body['id'])
        server = clients.servers_client.show_server(body['id'])['server']
        return server