def test_update_image(self): # Updates an image by image_id # Create image image_name = data_utils.rand_name('image') container_format = CONF.image.container_formats[0] disk_format = CONF.image.disk_formats[0] body = self.client.create_image(name=image_name, container_format=container_format, disk_format=disk_format, visibility='private') self.addCleanup(self.client.delete_image, body['id']) self.assertEqual('queued', body['status']) image_id = body['id'] # Now try uploading an image file image_file = moves.cStringIO(data_utils.random_bytes()) self.client.store_image_file(image_id, image_file) # Update Image new_image_name = data_utils.rand_name('new-image') body = self.client.update_image(image_id, [ dict(replace='/name', value=new_image_name)]) # Verifying updating body = self.client.show_image(image_id) self.assertEqual(image_id, body['id']) self.assertEqual(new_image_name, body['name'])
def _create_image(self): image_file = six.BytesIO(data_utils.random_bytes()) image = self.create_image(container_format='bare', disk_format='raw', is_public=False, data=image_file) return image['id']
def _create_image(self): image_file = StringIO.StringIO(data_utils.random_bytes()) resp, image = self.create_image(container_format='bare', disk_format='raw', is_public=False, data=image_file) self.assertEqual(201, resp.status) image_id = image['id'] return image_id
def test_check_glance_v2_notifications(self): body = self.create_image(self.image_client_v2, visibility='private') file_content = data_utils.random_bytes() image_file = six.BytesIO(file_content) self.image_client_v2.store_image_file(body['id'], image_file) self.image_client_v2.show_image_file(body['id']) query = 'resource', 'eq', body['id'] for metric in self.glance_v2_notifications: self.await_samples(metric, query)
def _create_standard_image(cls, name, container_format, disk_format, size): """Create a new standard image and return newly-registered image-id""" image_file = six.BytesIO(data_utils.random_bytes(size)) name = 'New Standard Image %s' % name image = cls.create_image(name=name, container_format=container_format, disk_format=disk_format, is_public=False, data=image_file, properties={'key1': 'value1'}) return image['id']
def _create_standard_image(cls, name, container_format, disk_format, size): """ Create a new standard image and return the ID of the newly-registered image. Note that the size of the new image is a random number between 1024 and 4096 """ image_file = StringIO.StringIO(data_utils.random_bytes(size)) name = "New Standard Image %s" % name image = cls.create_image( name=name, container_format=container_format, disk_format=disk_format, is_public=False, data=image_file ) image_id = image["id"] return image_id
def _create_standard_image(cls, name, container_format, disk_format, size): """Create a new standard image and return newly-registered image-id Note that the size of the new image is a random number between 1024 and 4096 """ image_file = six.BytesIO(data_utils.random_bytes(size)) name = 'New Standard Image %s' % name image = cls.create_image(name=name, container_format=container_format, disk_format=disk_format, is_public=False, data=image_file) return image['id']
def _create_standard_image(cls, container_format, disk_format): """Create a new standard image and return the newly-registered image-id Note that the size of the new image is a random number between 1024 and 4096 """ size = random.randint(1024, 4096) image_file = six.BytesIO(data_utils.random_bytes(size)) image = cls.create_image(container_format=container_format, disk_format=disk_format, visibility='private') cls.client.store_image_file(image['id'], data=image_file) return image['id']
def test_create_object_with_transfer_encoding(self): # create object with transfer_encoding object_name = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes(1024) status, _, resp_headers = self.object_client.put_object_with_chunk( container=self.container_name, name=object_name, contents=data_utils.chunkify(data, 512)) self.assertHeaders(resp_headers, 'Object', 'PUT') # check uploaded content _, body = self.object_client.get_object(self.container_name, object_name) self.assertEqual(data, body)
def test_create_object_with_expect_continue(self): # create object with expect_continue object_name = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes() status, _ = self.object_client.create_object_continue( self.container_name, object_name, data) self.assertEqual(status, 201) # check uploaded content _, body = self.object_client.get_object(self.container_name, object_name) self.assertEqual(data, body)
def test_list_object_metadata(self): # get object metadata object_name = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes() metadata = {'X-Object-Meta-test-meta': 'Meta'} self.object_client.create_object(self.container_name, object_name, data, metadata=metadata) resp, _ = self.object_client.list_object_metadata( self.container_name, object_name) self.assertHeaders(resp, 'Object', 'HEAD') self.assertIn('x-object-meta-test-meta', resp) self.assertEqual(resp['x-object-meta-test-meta'], 'Meta')
def test_get_object_with_range(self): # get object with range object_name = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes(100) self.object_client.create_object(self.container_name, object_name, data, metadata=None) rand_num = random.randint(3, len(data) - 1) metadata = {'Range': 'bytes=%s-%s' % (rand_num - 3, rand_num - 1)} resp, body = self.object_client.get_object(self.container_name, object_name, metadata=metadata) self.assertHeaders(resp, 'Object', 'GET') self.assertEqual(body, data[rand_num - 3:rand_num])
def test_create_object_with_etag(self): # create object with etag object_name = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes() md5 = hashlib.md5(data).hexdigest() metadata = {'Etag': md5} resp, _ = self.object_client.create_object(self.container_name, object_name, data, metadata=metadata) self.assertHeaders(resp, 'Object', 'PUT') # check uploaded content _, body = self.object_client.get_object(self.container_name, object_name) self.assertEqual(data, body)
def test_create_object_with_x_object_metakey(self): # create object with the blank value of metadata object_name = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes() metadata = {'X-Object-Meta-test-meta': ''} resp, _ = self.object_client.create_object(self.container_name, object_name, data, metadata=metadata) self.assertHeaders(resp, 'Object', 'PUT') resp, body = self.object_client.get_object(self.container_name, object_name) self.assertIn('x-object-meta-test-meta', resp) self.assertEqual(resp['x-object-meta-test-meta'], '') self.assertEqual(data, body)
def test_get_object_with_metadata(self): # get object with metadata object_name = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes() metadata = {'X-Object-Meta-test-meta': 'Meta'} self.object_client.create_object(self.container_name, object_name, data, metadata=metadata) resp, body = self.object_client.get_object(self.container_name, object_name, metadata=None) self.assertHeaders(resp, 'Object', 'GET') self.assertIn('x-object-meta-test-meta', resp) self.assertEqual(resp['x-object-meta-test-meta'], 'Meta') self.assertEqual(body, data)
def create_object(cls, container_name, object_name=None, data=None, metadata=None): # wrapper that returns a test object if object_name is None: object_name = data_utils.rand_name(name='TestObject') if data is None: data = data_utils.random_bytes() cls.object_client.create_object(container_name, object_name, data, metadata=metadata) return object_name, data
def _create_standard_image(cls, name, container_format, disk_format, size): """ Create a new standard image and return the ID of the newly-registered image. """ image_file = StringIO.StringIO(data_utils.random_bytes(size)) name = "New Standard Image %s" % name image = cls.create_image( name=name, container_format=container_format, disk_format=disk_format, is_public=False, data=image_file, properties={"key1": "value1"}, ) image_id = image["id"] return image_id
def _create_standard_image(cls, container_format, disk_format): """ Create a new standard image and return the ID of the newly-registered image. Note that the size of the new image is a random number between 1024 and 4096 """ size = random.randint(1024, 4096) image_file = moves.cStringIO(data_utils.random_bytes(size)) name = data_utils.rand_name('image') body = cls.create_image(name=name, container_format=container_format, disk_format=disk_format, visibility='private') image_id = body['id'] cls.client.store_image_file(image_id, data=image_file) return image_id
def _create_standard_image(cls, container_format, disk_format): """Create a new standard image and return the newly-registered image-id Note that the size of the new image is a random number between 1024 and 4096 """ size = random.randint(1024, 4096) image_file = moves.cStringIO(data_utils.random_bytes(size)) name = data_utils.rand_name('image') body = cls.create_image(name=name, container_format=container_format, disk_format=disk_format, visibility='private') image_id = body['id'] cls.client.store_image_file(image_id, data=image_file) return image_id
def test_get_object_with_if_match(self): # get object with if_match object_name = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes(10) create_md5 = hashlib.md5(data).hexdigest() create_metadata = {'Etag': create_md5} self.object_client.create_object(self.container_name, object_name, data, metadata=create_metadata) list_metadata = {'If-Match': create_md5} resp, body = self.object_client.get_object(self.container_name, object_name, metadata=list_metadata) self.assertHeaders(resp, 'Object', 'GET') self.assertEqual(body, data)
def test_get_object_with_if_modified_since(self): # get object with if_modified_since object_name = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes() time_now = time.time() self.object_client.create_object(self.container_name, object_name, data, metadata=None) http_date = time.ctime(time_now - 86400) list_metadata = {'If-Modified-Since': http_date} resp, body = self.object_client.get_object(self.container_name, object_name, metadata=list_metadata) self.assertHeaders(resp, 'Object', 'GET') self.assertEqual(body, data)
def test_create_object_with_content_disposition(self): # create object with content_disposition object_name = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes() metadata = {} metadata['content-disposition'] = 'inline' resp, _ = self.object_client.create_object(self.container_name, object_name, data, metadata=metadata) self.assertHeaders(resp, 'Object', 'PUT') resp, body = self.object_client.get_object(self.container_name, object_name, metadata=None) self.assertIn('content-disposition', resp) self.assertEqual(resp['content-disposition'], 'inline') self.assertEqual(body, data)
def _create_standard_image(cls, container_format, disk_format): """Create a new standard image and return the newly-registered image-id Note that the size of the new image is a random number between 1024 and 4096 """ size = random.randint(1024, 4096) image_file = six.BytesIO(data_utils.random_bytes(size)) tags = [data_utils.rand_name('tag'), data_utils.rand_name('tag')] image = cls.create_image(container_format=container_format, disk_format=disk_format, visibility='private', tags=tags) cls.client.store_image_file(image['id'], data=image_file) # Keep the data of one test image so it can be used to filter lists cls.test_data = image return image['id']
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.assertRaisesRegexp(lib_exc.BadRequest, "Flavor's memory is too small for " "requested image", self.create_test_server, image_id=image['id'], flavor=flavor['id'])
def _create_standard_image(cls, container_format, disk_format): """Create a new standard image and return the newly-registered image-id Note that the size of the new image is a random number between 1024 and 4096 """ size = random.randint(1024, 4096) image_file = six.BytesIO(data_utils.random_bytes(size)) tags = [data_utils.rand_name('tag'), data_utils.rand_name('tag')] image = cls.create_image(container_format=container_format, disk_format=disk_format, visibility='private', tags=tags) cls.client.store_image_file(image['id'], data=image_file) # Keep the data of one test image so it can be used to filter lists cls.test_data = image cls.test_data['size'] = size return image['id']
def test_register_then_upload(self): # Register, then upload an image properties = {"prop1": "val1"} body = self.create_image( name="New Name", container_format="bare", disk_format="raw", is_public=False, properties=properties ) self.assertIn("id", body) image_id = body.get("id") self.assertEqual("New Name", body.get("name")) self.assertFalse(body.get("is_public")) self.assertEqual("queued", body.get("status")) for key, val in properties.items(): self.assertEqual(val, body.get("properties")[key]) # Now try uploading an image file image_file = StringIO.StringIO(data_utils.random_bytes()) body = self.client.update_image(image_id, data=image_file) self.assertIn("size", body) self.assertEqual(1024, body.get("size"))
def test_register_then_upload(self): # Register, then upload an image properties = {'prop1': 'val1'} container_format, disk_format = get_container_and_disk_format() image = self.create_image(name='New Name', container_format=container_format, disk_format=disk_format, is_public=False, properties=properties) self.assertEqual('New Name', image.get('name')) self.assertFalse(image.get('is_public')) self.assertEqual('queued', image.get('status')) for key, val in properties.items(): self.assertEqual(val, image.get('properties')[key]) # Now try uploading an image file image_file = six.BytesIO(data_utils.random_bytes()) body = self.client.update_image(image['id'], data=image_file)['image'] self.assertIn('size', body) self.assertEqual(1024, body.get('size'))
def test_list_images_param_member_status(self): # Create an image to be shared using default visibility image_file = six.BytesIO(data_utils.random_bytes(2048)) container_format = CONF.image.container_formats[0] disk_format = CONF.image.disk_formats[0] image = self.create_image(container_format=container_format, disk_format=disk_format) self.client.store_image_file(image['id'], data=image_file) # Share the image created with the alt user self.image_member_client.create_image_member( image_id=image['id'], member=self.alt_img_client.tenant_id) # As an image consumer you need to provide the member_status parameter # along with the visibility=shared parameter in order for it to show # results params = {'member_status': 'pending', 'visibility': 'shared'} fetched_images = self.alt_img_client.list_images(params)['images'] self.assertEqual(1, len(fetched_images)) self.assertEqual(image['id'], fetched_images[0]['id'])
def test_create_object_with_x_remove_object_meta(self): # create object with x_remove_object_meta object_name = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes() metadata_add = {'X-Object-Meta-test-meta': 'Meta'} self.object_client.create_object(self.container_name, object_name, data, metadata=metadata_add) metadata_remove = {'X-Remove-Object-Meta-test-meta': 'Meta'} resp, _ = self.object_client.create_object(self.container_name, object_name, data, metadata=metadata_remove) self.assertHeaders(resp, 'Object', 'PUT') resp, body = self.object_client.get_object(self.container_name, object_name) self.assertNotIn('x-object-meta-test-meta', resp) self.assertEqual(data, body)
def test_register_upload_get_image_file(self): """Here we test these functionalities Register image, upload the image file, get image and get image file api's """ uuid = '00000000-1111-2222-3333-444455556666' image_name = data_utils.rand_name('image') container_format = CONF.image.container_formats[0] disk_format = CONF.image.disk_formats[0] body = self.create_image(name=image_name, container_format=container_format, disk_format=disk_format, visibility='private', ramdisk_id=uuid) self.assertIn('id', body) image_id = body.get('id') self.assertIn('name', body) self.assertEqual(image_name, body['name']) self.assertIn('visibility', body) self.assertEqual('private', body['visibility']) self.assertIn('status', body) self.assertEqual('queued', body['status']) # Now try uploading an image file file_content = data_utils.random_bytes() image_file = six.BytesIO(file_content) self.client.store_image_file(image_id, image_file) # Now try to get image details body = self.client.show_image(image_id) self.assertEqual(image_id, body['id']) self.assertEqual(image_name, body['name']) self.assertEqual(uuid, body['ramdisk_id']) self.assertIn('size', body) self.assertEqual(1024, body.get('size')) # Now try get image file body = self.client.show_image_file(image_id) self.assertEqual(file_content, body.data)
def test_register_upload_get_image_file(self): """Here we test these functionalities Register image, upload the image file, get image and get image file api's """ uuid = '00000000-1111-2222-3333-444455556666' image_name = data_utils.rand_name('image') container_format = CONF.image.container_formats[0] disk_format = CONF.image.disk_formats[0] body = self.create_image(name=image_name, container_format=container_format, disk_format=disk_format, visibility='private', ramdisk_id=uuid) self.assertIn('id', body) image_id = body.get('id') self.assertIn('name', body) self.assertEqual(image_name, body['name']) self.assertIn('visibility', body) self.assertEqual('private', body['visibility']) self.assertIn('status', body) self.assertEqual('queued', body['status']) # Now try uploading an image file file_content = data_utils.random_bytes() image_file = moves.cStringIO(file_content) self.client.store_image_file(image_id, image_file) # Now try to get image details body = self.client.show_image(image_id) self.assertEqual(image_id, body['id']) self.assertEqual(image_name, body['name']) self.assertEqual(uuid, body['ramdisk_id']) self.assertIn('size', body) self.assertEqual(1024, body.get('size')) # Now try get image file body = self.client.show_image_file(image_id) self.assertEqual(file_content, body.data)
def test_update_object_metadata_with_remove_metadata(self): # update object metadata with remove metadata object_name = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes() create_metadata = {'X-Object-Meta-test-meta1': 'Meta1'} self.object_client.create_object(self.container_name, object_name, data, metadata=create_metadata) update_metadata = {'X-Remove-Object-Meta-test-meta1': 'Meta1'} resp, _ = self.object_client.update_object_metadata( self.container_name, object_name, update_metadata, metadata_prefix='') self.assertHeaders(resp, 'Object', 'POST') resp, _ = self.object_client.list_object_metadata( self.container_name, object_name) self.assertNotIn('x-object-meta-test-meta1', resp)
def test_register_then_upload(self): # Register, then upload an image properties = {'prop1': 'val1'} _, body = self.create_image(name='New Name', container_format='bare', disk_format='raw', is_public=False, properties=properties) self.assertIn('id', body) image_id = body.get('id') self.assertEqual('New Name', body.get('name')) self.assertFalse(body.get('is_public')) self.assertEqual('queued', body.get('status')) for key, val in properties.items(): self.assertEqual(val, body.get('properties')[key]) # Now try uploading an image file image_file = StringIO.StringIO(data_utils.random_bytes()) _, body = self.client.update_image(image_id, data=image_file) self.assertIn('size', body) self.assertEqual(1024, body.get('size'))
def test_put_object_using_temp_url(self): new_data = data_utils.random_bytes(size=len(self.object_name)) expires = self._get_expiry_date() url = self._get_temp_url(self.container_name, self.object_name, "PUT", expires, self.key) # trying to put random data in the object using temp url resp, body = self.object_client.put(url, new_data, None) self.assertHeaders(resp, 'Object', 'PUT') # Testing a HEAD on this Temp URL resp, body = self.object_client.head(url) self.assertHeaders(resp, 'Object', 'HEAD') # Validate that the content of the object has been modified url = self._get_temp_url(self.container_name, self.object_name, "GET", expires, self.key) _, body = self.object_client.get(url) self.assertEqual(body, new_data)
def test_create_object_with_x_fresh_metadata(self): # create object with x_fresh_metadata object_name_base = data_utils.rand_name(name='TestObject') data = data_utils.random_bytes() metadata_1 = {'X-Object-Meta-test-meta': 'Meta'} self.object_client.create_object(self.container_name, object_name_base, data, metadata=metadata_1) object_name = data_utils.rand_name(name='TestObject') metadata_2 = { 'X-Copy-From': '%s/%s' % (self.container_name, object_name_base), 'X-Fresh-Metadata': 'true' } resp, _ = self.object_client.create_object(self.container_name, object_name, '', metadata=metadata_2) self.assertHeaders(resp, 'Object', 'PUT') resp, body = self.object_client.get_object(self.container_name, object_name) self.assertNotIn('x-object-meta-test-meta', resp) self.assertEqual(data, body)