Exemple #1
0
 def test_update_image_metadata(self):
     # The metadata for the image should match the updated values
     req_metadata = {'key1': 'alt1', 'key2': 'value2'}
     resp = self.client.check_image(self.image_id)
     metadata = common_image.get_image_meta_from_headers(resp)
     self.assertEqual(metadata['properties'], {'key1': 'value1'})
     metadata['properties'].update(req_metadata)
     headers = common_image.image_meta_to_headers(
         properties=metadata['properties'])
     self.client.update_image(self.image_id, headers=headers)
     resp = self.client.check_image(self.image_id)
     resp_metadata = common_image.get_image_meta_from_headers(resp)
     self.assertEqual(req_metadata, resp_metadata['properties'])
Exemple #2
0
 def test_update_image_metadata(self):
     # The metadata for the image should match the updated values
     req_metadata = {'key1': 'alt1', 'key2': 'value2'}
     resp = self.client.check_image(self.image_id)
     metadata = common_image.get_image_meta_from_headers(resp)
     self.assertEqual(metadata['properties'], {'key1': 'value1'})
     metadata['properties'].update(req_metadata)
     headers = common_image.image_meta_to_headers(
         properties=metadata['properties'])
     self.client.update_image(self.image_id, headers=headers)
     resp = self.client.check_image(self.image_id)
     resp_metadata = common_image.get_image_meta_from_headers(resp)
     self.assertEqual(req_metadata, resp_metadata['properties'])
Exemple #3
0
 def test_list_image_metadata(self):
     """Test listing image metadata"""
     # All metadata key/value pairs for an image should be returned
     resp = self.client.check_image(self.image_id)
     resp_metadata = common_image.get_image_meta_from_headers(resp)
     expected = {'key1': 'value1'}
     self.assertEqual(expected, resp_metadata['properties'])
Exemple #4
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: {}"
                  .format(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_volume_resource_status(self.snapshots_client,
                                                        snapshot_id,
                                                        'available')
        image_name = snapshot_image['name']
        self.assertEqual(name, image_name)
        LOG.debug("Created snapshot image {} for server {}"
                  .format(image_name, server['name']))
        return snapshot_image
Exemple #5
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: {}"
                  .format(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_volume_resource_status(self.snapshots_client,
                                                        snapshot_id,
                                                        'available')
        image_name = snapshot_image['name']
        self.assertEqual(name, image_name)
        LOG.debug("Created snapshot image {} for server {}"
                  .format(image_name, server['name']))
        return snapshot_image
    def test_get_image_meta_from_headers(self):
        resp = {
            'x-image-meta-id': 'ea30c926-0629-4400-bb6e-f8a8da6a4e56',
            'x-image-meta-owner': '8f421f9470e645b1b10f5d2db7804924',
            'x-image-meta-status': 'queued',
            'x-image-meta-name': 'New Http Image'
        }
        respbody = rest_client.ResponseBody(resp)
        observed = image.get_image_meta_from_headers(respbody)

        expected = {
            'properties': {},
            'id': 'ea30c926-0629-4400-bb6e-f8a8da6a4e56',
            'owner': '8f421f9470e645b1b10f5d2db7804924',
            'status': 'queued',
            'name': 'New Http Image'
        }
        self.assertEqual(expected, observed)
Exemple #7
0
    def test_get_image_meta_from_headers(self):
        resp = {
            'x-image-meta-id': 'ea30c926-0629-4400-bb6e-f8a8da6a4e56',
            'x-image-meta-owner': '8f421f9470e645b1b10f5d2db7804924',
            'x-image-meta-status': 'queued',
            'x-image-meta-name': 'New Http Image'
        }
        respbody = rest_client.ResponseBody(resp)
        observed = image.get_image_meta_from_headers(respbody)

        expected = {
            'properties': {},
            'id': 'ea30c926-0629-4400-bb6e-f8a8da6a4e56',
            'owner': '8f421f9470e645b1b10f5d2db7804924',
            'status': 'queued',
            'name': 'New Http Image'
        }
        self.assertEqual(expected, observed)
Exemple #8
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:
            if CONF.image_feature_enabled.api_v1:
                resp = self.image_client.check_image(imageRef)
                image = common_image.get_image_meta_from_headers(resp)
            else:
                image = self.image_client.show_image(imageRef)
            min_disk = image.get('min_disk')
            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'])
        self.assertEqual(name, volume['name'])
        waiters.wait_for_volume_resource_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
    def create_volume(self,
                      name=None,
                      imageRef=None,
                      size=1,
                      volume_type=None,
                      clients=None):

        if clients is None:
            clients = self.os_primary

        if imageRef:
            if CONF.image_feature_enabled.api_v1:
                resp = self.image_client.check_image(imageRef)
                image = common_image.get_image_meta_from_headers(resp)
            else:
                image = self.image_client.show_image(imageRef)
            min_disk = image.get('min_disk')
            size = max(size, min_disk)

        if name is None:
            name = data_utils.rand_name(self.__class__.__name__ + "-volume")
        volumes_client = clients.volumes_client_latest
        params = {
            'name': name,
            'imageRef': imageRef,
            'volume_type': volume_type,
            'size': size or CONF.volume.volume_size
        }
        volume = volumes_client.create_volume(**params)['volume']
        self.addCleanup(volumes_client.wait_for_resource_deletion,
                        volume['id'])
        self.addCleanup(test_utils.call_and_ignore_notfound_exc,
                        volumes_client.delete_volume, volume['id'])
        self.assertEqual(name, volume['name'])
        waiters.wait_for_volume_resource_status(volumes_client, volume['id'],
                                                'available')
        volume = volumes_client.show_volume(volume['id'])['volume']
        return volume
Exemple #10
0
 def test_list_image_metadata(self):
     # All metadata key/value pairs for an image should be returned
     resp = self.client.check_image(self.image_id)
     resp_metadata = common_image.get_image_meta_from_headers(resp)
     expected = {'key1': 'value1'}
     self.assertEqual(expected, resp_metadata['properties'])
Exemple #11
0
 def _show_image_v1(image_id):
     resp = client.check_image(image_id)
     return common_image.get_image_meta_from_headers(resp)
Exemple #12
0
 def _show_image_v1(image_id):
     resp = client.check_image(image_id)
     return common_image.get_image_meta_from_headers(resp)