예제 #1
0
        def _create_image():
            params = {
                'name': data_utils.rand_name(cls.__name__ + '-image'),
                'container_format': 'bare',
                'disk_format': 'raw'
            }
            if CONF.image_feature_enabled.api_v1:
                params.update({'is_public': False})
                params = {'headers':
                          common_image.image_meta_to_headers(**params)}
            else:
                params.update({'visibility': 'private'})

            body = cls.glance_client.create_image(**params)
            body = body['image'] if 'image' in body else body
            image_id = body['id']
            cls.addClassResourceCleanup(
                test_utils.call_and_ignore_notfound_exc,
                cls.compute_images_client.delete_image,
                image_id)
            # Wait 1 second between creation and upload to ensure a delta
            # between created_at and updated_at.
            time.sleep(1)
            image_file = six.BytesIO((b'*' * 1024))
            if CONF.image_feature_enabled.api_v1:
                cls.glance_client.update_image(image_id, data=image_file)
            else:
                cls.glance_client.store_image_file(image_id, data=image_file)
            waiters.wait_for_image_status(cls.client, image_id, 'ACTIVE')
            body = cls.client.show_image(image_id)['image']
            return body
예제 #2
0
        def _create_image():
            params = {
                "name": data_utils.rand_name(cls.__name__ + "-image"),
                "container_format": "bare",
                "disk_format": "raw",
            }
            if CONF.image_feature_enabled.api_v1:
                params.update({"is_public": False})
                params = {"headers": common_image.image_meta_to_headers(**params)}
            else:
                params.update({"visibility": "private"})

            body = cls.glance_client.create_image(**params)
            body = body["image"] if "image" in body else body
            image_id = body["id"]
            cls.images.append(image_id)
            # Wait 1 second between creation and upload to ensure a delta
            # between created_at and updated_at.
            time.sleep(1)
            image_file = six.BytesIO((b"*" * 1024))
            if CONF.image_feature_enabled.api_v1:
                cls.glance_client.update_image(image_id, data=image_file)
            else:
                cls.glance_client.store_image_file(image_id, data=image_file)
            waiters.wait_for_image_status(cls.client, image_id, "ACTIVE")
            body = cls.client.show_image(image_id)["image"]
            return body
예제 #3
0
    def resource_setup(cls):
        super(ImagesMetadataTestJSON, cls).resource_setup()
        cls.image_id = None

        params = {
            'name': data_utils.rand_name('image'),
            'container_format': 'bare',
            'disk_format': 'raw'
        }
        if CONF.image_feature_enabled.api_v1:
            params.update({'is_public': False})
            params = {'headers': common_image.image_meta_to_headers(**params)}
        else:
            params.update({'visibility': 'private'})

        body = cls.glance_client.create_image(**params)
        body = body['image'] if 'image' in body else body
        cls.image_id = body['id']
        cls.images.append(cls.image_id)
        image_file = six.BytesIO((b'*' * 1024))
        if CONF.image_feature_enabled.api_v1:
            cls.glance_client.update_image(cls.image_id, data=image_file)
        else:
            cls.glance_client.store_image_file(cls.image_id, data=image_file)
        waiters.wait_for_image_status(cls.client, cls.image_id, 'ACTIVE')
        def _create_image():
            params = {
                'name': data_utils.rand_name(cls.__name__ + '-image'),
                'container_format': 'bare',
                'disk_format': 'raw'
            }
            if CONF.image_feature_enabled.api_v1:
                params.update({'is_public': False})
                params = {
                    'headers': common_image.image_meta_to_headers(**params)
                }
            else:
                params.update({'visibility': 'private'})

            body = cls.glance_client.create_image(**params)
            body = body['image'] if 'image' in body else body
            image_id = body['id']
            cls.images.append(image_id)
            # Wait 1 second between creation and upload to ensure a delta
            # between created_at and updated_at.
            time.sleep(1)
            image_file = six.BytesIO((b'*' * 1024))
            if CONF.image_feature_enabled.api_v1:
                cls.glance_client.update_image(image_id, data=image_file)
            else:
                cls.glance_client.store_image_file(image_id, data=image_file)
            waiters.wait_for_image_status(cls.client, image_id, 'ACTIVE')
            body = cls.client.show_image(image_id)['image']
            return body
예제 #5
0
        def _create_image():
            params = {
                'name': data_utils.rand_name('image'),
                'container_format': 'bare',
                'disk_format': 'raw'
            }
            if CONF.image_feature_enabled.api_v1:
                params.update({'is_public': False})
                params = {'headers':
                          common_image.image_meta_to_headers(**params)}
            else:
                params.update({'visibility': 'private'})

            body = cls.glance_client.create_image(**params)
            body = body['image'] if 'image' in body else body
            image_id = body['id']
            cls.images.append(image_id)
            # Wait 1 second between creation and upload to ensure a delta
            # between created_at and updated_at.
            time.sleep(1)
            image_file = six.StringIO(('*' * 1024))
            if CONF.image_feature_enabled.api_v1:
                cls.glance_client.update_image(image_id, data=image_file)
            else:
                cls.glance_client.store_image_file(image_id, data=image_file)
            waiters.wait_for_image_status(cls.client, image_id, 'ACTIVE')
            body = cls.client.show_image(image_id)['image']
            return body
예제 #6
0
    def resource_setup(cls):
        super(ImagesMetadataTestJSON, cls).resource_setup()
        cls.image_id = None

        params = {
            'name': data_utils.rand_name('image'),
            'container_format': 'bare',
            'disk_format': 'raw'
        }
        if CONF.image_feature_enabled.api_v1:
            params.update({'is_public': False})
            params = {'headers': common_image.image_meta_to_headers(**params)}
        else:
            params.update({'visibility': 'private'})

        body = cls.glance_client.create_image(**params)
        body = body['image'] if 'image' in body else body
        cls.image_id = body['id']
        cls.images.append(cls.image_id)
        image_file = six.BytesIO((b'*' * 1024))
        if CONF.image_feature_enabled.api_v1:
            cls.glance_client.update_image(cls.image_id, data=image_file)
        else:
            cls.glance_client.store_image_file(cls.image_id, data=image_file)
        waiters.wait_for_image_status(cls.client, cls.image_id, 'ACTIVE')
예제 #7
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']
예제 #8
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']
예제 #9
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)

        if CONF.image_feature_enabled.import_image:
            available_stores = []
            try:
                available_stores = self.image_client.info_stores()['stores']
            except exceptions.NotFound:
                pass
            available_import_methods = self.image_client.info_import(
            )['import-methods']['value']
            if ('copy-image' in available_import_methods
                    and len(available_stores) > 1):
                self.image_client.image_import(image['id'],
                                               method='copy-image',
                                               all_stores=True,
                                               all_stores_must_succeed=False)
                failed_stores = waiters.wait_for_image_copied_to_stores(
                    self.image_client, image['id'])
                self.assertEqual(
                    0, len(failed_stores),
                    "Failed to copy the following stores: %s" %
                    str(failed_stores))

        return image['id']
예제 #10
0
    def resource_setup(cls):
        super(ImagesRbacTest, cls).resource_setup()
        params = {'name': data_utils.rand_name(cls.__name__ + '-image')}
        if CONF.image_feature_enabled.api_v1:
            params = {'headers': common_image.image_meta_to_headers(**params)}

        cls.image = cls.glance_image_client.create_image(**params)
        cls.addClassResourceCleanup(
            cls.glance_image_client.wait_for_resource_deletion,
            cls.image['id'])
        cls.addClassResourceCleanup(cls.glance_image_client.delete_image,
                                    cls.image['id'])
예제 #11
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'])
예제 #12
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'])
예제 #13
0
    def test_boot_with_low_ram(self):
        """Try boot a vm with lower than min ram

        Create an image with min_ram value
        Try to create server with flavor of insufficient ram size from
        that image
        """
        flavor = self.flavors_client.show_flavor(
            CONF.compute.flavor_ref)['flavor']
        min_img_ram = flavor['ram'] + 1
        size = random.randint(1024, 4096)
        image_file = six.BytesIO(data_utils.random_bytes(size))
        params = {
            'name': data_utils.rand_name('image'),
            'container_format': CONF.image.container_formats[0],
            'disk_format': CONF.image.disk_formats[0],
            'min_ram': min_img_ram
        }

        if CONF.image_feature_enabled.api_v1:
            params.update({'is_public': False})
            params = {'headers': common_image.image_meta_to_headers(**params)}
        else:
            params.update({'visibility': 'private'})

        image = self.images_client.create_image(**params)
        image = image['image'] if 'image' in image else image
        self.addCleanup(self.images_client.delete_image, image['id'])

        if CONF.image_feature_enabled.api_v1:
            self.images_client.update_image(image['id'], data=image_file)
        else:
            self.images_client.store_image_file(image['id'], data=image_file)

        self.assertEqual(min_img_ram, image['min_ram'])

        # Try to create server with flavor of insufficient ram size
        self.assertRaisesRegex(lib_exc.BadRequest,
                               "Flavor's memory is too small for "
                               "requested image",
                               self.create_test_server,
                               image_id=image['id'],
                               flavor=flavor['id'])
예제 #14
0
    def test_boot_with_low_ram(self):
        """Try boot a vm with lower than min ram

        Create an image with min_ram value
        Try to create server with flavor of insufficient ram size from
        that image
        """
        flavor = self.flavors_client.show_flavor(
            CONF.compute.flavor_ref)['flavor']
        min_img_ram = flavor['ram'] + 1
        size = random.randint(1024, 4096)
        image_file = six.BytesIO(data_utils.random_bytes(size))
        params = {
            'name': data_utils.rand_name('image'),
            'container_format': CONF.image.container_formats[0],
            'disk_format': CONF.image.disk_formats[0],
            'min_ram': min_img_ram
        }

        if CONF.image_feature_enabled.api_v1:
            params.update({'is_public': False})
            params = {'headers': common_image.image_meta_to_headers(**params)}
        else:
            params.update({'visibility': 'private'})

        image = self.images_client.create_image(**params)
        image = image['image'] if 'image' in image else image
        self.addCleanup(self.images_client.delete_image, image['id'])

        if CONF.image_feature_enabled.api_v1:
            self.images_client.update_image(image['id'], data=image_file)
        else:
            self.images_client.store_image_file(image['id'], data=image_file)

        self.assertEqual(min_img_ram, image['min_ram'])

        # Try to create server with flavor of insufficient ram size
        self.assertRaisesRegex(lib_exc.BadRequest,
                               "Flavor's memory is too small for "
                               "requested image",
                               self.create_test_server,
                               image_id=image['id'],
                               flavor=flavor['id'])
예제 #15
0
    def test_image_meta_to_headers(self):
        observed = image.image_meta_to_headers(
            name='test',
            container_format='wrong',
            disk_format='vhd',
            copy_from='http://localhost/images/10',
            properties={'foo': 'bar'},
            api={'abc': 'def'},
            purge_props=True)

        expected = {
            'x-image-meta-name': 'test',
            'x-image-meta-container_format': 'wrong',
            'x-image-meta-disk_format': 'vhd',
            'x-glance-api-copy-from': 'http://localhost/images/10',
            'x-image-meta-property-foo': 'bar',
            'x-glance-api-property-abc': 'def',
            'x-glance-registry-purge-props': True
        }
        self.assertEqual(expected, observed)
예제 #16
0
    def test_image_meta_to_headers(self):
        observed = image.image_meta_to_headers(
            name='test',
            container_format='wrong',
            disk_format='vhd',
            copy_from='http://localhost/images/10',
            properties={'foo': 'bar'},
            api={'abc': 'def'},
            purge_props=True)

        expected = {
            'x-image-meta-name': 'test',
            'x-image-meta-container_format': 'wrong',
            'x-image-meta-disk_format': 'vhd',
            'x-glance-api-copy-from': 'http://localhost/images/10',
            'x-image-meta-property-foo': 'bar',
            'x-glance-api-property-abc': 'def',
            'x-glance-registry-purge-props': True
        }
        self.assertEqual(expected, observed)
예제 #17
0
파일: base.py 프로젝트: masayukig/tempest
 def _get_create_params(cls, **kwargs):
     return {'headers': common_image.image_meta_to_headers(**kwargs)}
예제 #18
0
 def _get_create_params(cls, **kwargs):
     return {'headers': common_image.image_meta_to_headers(**kwargs)}