def test_is_image_visible(self): TENANT1 = uuidutils.generate_uuid() TENANT2 = uuidutils.generate_uuid() ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, owner_is_tenant=True) ctxt2 = context.RequestContext(is_admin=False, user=TENANT2, owner_is_tenant=False) UUIDX = uuidutils.generate_uuid() #we need private image and context.owner should not match image owner image = self.db_api.image_create(ctxt1, {'id': UUIDX, 'status': 'queued', 'is_public': False, 'owner': TENANT1}) values = {'image_id': UUIDX, 'member': TENANT2, 'can_share': False} self.db_api.image_member_create(ctxt1, values) result = self.db_api.is_image_visible(ctxt2, image) self.assertTrue(result) # image should not be visible for a deleted memeber members = self.db_api.image_member_find(ctxt1, image_id=UUIDX) self.db_api.image_member_delete(ctxt1, members[0]['id']) result = self.db_api.is_image_visible(ctxt2, image) self.assertFalse(result)
def test_image_get_not_owned(self): TENANT1 = uuidutils.generate_uuid() TENANT2 = uuidutils.generate_uuid() ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1) ctxt2 = context.RequestContext(is_admin=False, tenant=TENANT2) image = self.db_api.image_create(ctxt1, {"status": "queued", "owner": TENANT1}) self.assertRaises(exception.Forbidden, self.db_api.image_get, ctxt2, image["id"])
def test_image_member_find(self): TENANT1 = uuidutils.generate_uuid() TENANT2 = uuidutils.generate_uuid() fixtures = [ {'member': TENANT1, 'image_id': UUID1}, {'member': TENANT1, 'image_id': UUID2}, {'member': TENANT2, 'image_id': UUID1}, ] for f in fixtures: self.db_api.image_member_create(self.context, copy.deepcopy(f)) def _simplify(output): return def _assertMemberListMatch(list1, list2): _simple = lambda x: set([(o['member'], o['image_id']) for o in x]) self.assertEqual(_simple(list1), _simple(list2)) output = self.db_api.image_member_find(self.context, member=TENANT1) _assertMemberListMatch([fixtures[0], fixtures[1]], output) output = self.db_api.image_member_find(self.context, image_id=UUID1) _assertMemberListMatch([fixtures[0], fixtures[2]], output) output = self.db_api.image_member_find(self.context, member=TENANT2, image_id=UUID1) _assertMemberListMatch([fixtures[2]], output) image_id = uuidutils.generate_uuid() output = self.db_api.image_member_find(self.context, member=TENANT2, image_id=image_id) _assertMemberListMatch([], output)
def test_is_image_visible(self): TENANT1 = uuidutils.generate_uuid() TENANT2 = uuidutils.generate_uuid() ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, owner_is_tenant=True) ctxt2 = context.RequestContext(is_admin=False, user=TENANT2, owner_is_tenant=False) UUIDX = uuidutils.generate_uuid() #we need private image and context.owner should not match image owner image = self.db_api.image_create(ctxt1, { 'id': UUIDX, 'status': 'queued', 'is_public': False, 'owner': TENANT1 }) values = {'image_id': UUIDX, 'member': TENANT2, 'can_share': False} self.db_api.image_member_create(ctxt1, values) result = self.db_api.is_image_visible(ctxt2, image) self.assertTrue(result) # image should not be visible for a deleted memeber members = self.db_api.image_member_find(ctxt1, image_id=UUIDX) self.db_api.image_member_delete(ctxt1, members[0]['id']) result = self.db_api.is_image_visible(ctxt2, image) self.assertFalse(result)
def test_image_member_find(self): TENANT1 = uuidutils.generate_uuid() TENANT2 = uuidutils.generate_uuid() fixtures = [ { 'member': TENANT1, 'image_id': UUID1 }, { 'member': TENANT1, 'image_id': UUID2, 'status': 'rejected' }, { 'member': TENANT2, 'image_id': UUID1, 'status': 'accepted' }, ] for f in fixtures: self.db_api.image_member_create(self.context, copy.deepcopy(f)) def _simplify(output): return def _assertMemberListMatch(list1, list2): _simple = lambda x: set([(o['member'], o['image_id']) for o in x]) self.assertEqual(_simple(list1), _simple(list2)) output = self.db_api.image_member_find(self.context, member=TENANT1) _assertMemberListMatch([fixtures[0], fixtures[1]], output) output = self.db_api.image_member_find(self.context, image_id=UUID1) _assertMemberListMatch([fixtures[0], fixtures[2]], output) output = self.db_api.image_member_find(self.context, member=TENANT2, image_id=UUID1) _assertMemberListMatch([fixtures[2]], output) output = self.db_api.image_member_find(self.context, status='accepted') _assertMemberListMatch([fixtures[2]], output) output = self.db_api.image_member_find(self.context, status='rejected') _assertMemberListMatch([fixtures[1]], output) output = self.db_api.image_member_find(self.context, status='pending') _assertMemberListMatch([fixtures[0]], output) output = self.db_api.image_member_find(self.context, status='pending', image_id=UUID2) _assertMemberListMatch([], output) image_id = uuidutils.generate_uuid() output = self.db_api.image_member_find(self.context, member=TENANT2, image_id=image_id) _assertMemberListMatch([], output)
def test_multitenant(self): """Ensure an image is properly configured when using multitenancy.""" fake_swift_admin = 'd2f68325-8e2c-4fb1-8c8b-89de2f3d9c4a' self.config( swift_store_multi_tenant=True, ) swift_store_user = self.swift_config['swift_store_user'] tenant_name, username = swift_store_user.split(':') tenant_id, auth_token, service_catalog = keystone_authenticate( self.swift_config['swift_store_auth_address'], self.swift_config['swift_store_auth_version'], tenant_name, username, self.swift_config['swift_store_key']) context = glance.context.RequestContext( tenant=tenant_id, service_catalog=service_catalog, auth_tok=auth_token) store = self.get_store(context=context) image_id = uuidutils.generate_uuid() image_data = StringIO.StringIO('XXX') uri, _, _, _ = store.add(image_id, image_data, 3) location = glance.store.location.Location( self.store_name, store.get_store_location_class(), uri=uri, image_id=image_id) read_tenant = uuidutils.generate_uuid() write_tenant = uuidutils.generate_uuid() store.set_acls(location, public=False, read_tenants=[read_tenant], write_tenants=[write_tenant]) container_name = location.store_location.container container, _ = swift_get_container(self.swift_client, container_name) self.assertEqual(read_tenant + ':*', container.get('x-container-read')) self.assertEqual(write_tenant + ':*', container.get('x-container-write')) store.set_acls(location, public=True, read_tenants=[read_tenant]) container_name = location.store_location.container container, _ = swift_get_container(self.swift_client, container_name) self.assertEqual('.r:*,.rlistings', container.get('x-container-read')) self.assertEqual('', container.get('x-container-write', '')) (get_iter, get_size) = store.get(location) self.assertEqual(3, get_size) self.assertEqual('XXX', ''.join(get_iter)) store.delete(location)
def test_multitenant(self): """Ensure an image is properly configured when using multitenancy.""" fake_swift_admin = 'd2f68325-8e2c-4fb1-8c8b-89de2f3d9c4a' self.config( swift_store_multi_tenant=True, ) swift_store_user = self.swift_config['swift_store_user'] tenant_name, username = swift_store_user.split(':') tenant_id, auth_token, service_catalog = keystone_authenticate( self.swift_config['swift_store_auth_address'], self.swift_config['swift_store_auth_version'], tenant_name, username, self.swift_config['swift_store_key']) context = glance.context.RequestContext( tenant=tenant_id, service_catalog=service_catalog, auth_tok=auth_token) store = self.get_store(context=context) image_id = uuidutils.generate_uuid() image_data = StringIO.StringIO('XXX') uri, _, _ = store.add(image_id, image_data, 3) location = glance.store.location.Location( self.store_name, store.get_store_location_class(), uri=uri, image_id=image_id) read_tenant = uuidutils.generate_uuid() write_tenant = uuidutils.generate_uuid() store.set_acls(location, public=False, read_tenants=[read_tenant], write_tenants=[write_tenant]) container_name = location.store_location.container container, _ = swift_get_container(self.swift_client, container_name) self.assertEqual(read_tenant, container.get('x-container-read')) self.assertEqual(write_tenant, container.get('x-container-write')) store.set_acls(location, public=True, read_tenants=[read_tenant]) container_name = location.store_location.container container, _ = swift_get_container(self.swift_client, container_name) self.assertEqual('.r:*', container.get('x-container-read')) self.assertEqual('', container.get('x-container-write', '')) (get_iter, get_size) = store.get(location) self.assertEqual(3, get_size) self.assertEqual('XXX', ''.join(get_iter)) store.delete(location)
def test_image_get_multiple_members(self): TENANT1 = uuidutils.generate_uuid() TENANT2 = uuidutils.generate_uuid() ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, owner_is_tenant=True) ctxt2 = context.RequestContext(is_admin=False, user=TENANT2, owner_is_tenant=False) UUIDX = uuidutils.generate_uuid() #we need private image and context.owner should not match image owner self.db_api.image_create(ctxt1, { 'id': UUIDX, 'status': 'queued', 'is_public': False, 'owner': TENANT1 }) values = {'image_id': UUIDX, 'member': TENANT2, 'can_share': False} self.db_api.image_member_create(ctxt1, values) image = self.db_api.image_get(ctxt2, UUIDX) self.assertEquals(UUIDX, image['id']) # by default get_all displays only images with status 'accepted' images = self.db_api.image_get_all(ctxt2) self.assertEquals(3, len(images)) # filter by rejected images = self.db_api.image_get_all(ctxt2, member_status='rejected') self.assertEquals(3, len(images)) # filter by visibility images = self.db_api.image_get_all(ctxt2, filters={'visibility': 'shared'}) self.assertEquals(0, len(images)) # filter by visibility images = self.db_api.image_get_all(ctxt2, member_status='pending', filters={'visibility': 'shared'}) self.assertEquals(1, len(images)) # filter by visibility images = self.db_api.image_get_all(ctxt2, member_status='all', filters={'visibility': 'shared'}) self.assertEquals(1, len(images)) # filter by status pending images = self.db_api.image_get_all(ctxt2, member_status='pending') self.assertEquals(4, len(images)) # filter by status all images = self.db_api.image_get_all(ctxt2, member_status='all') self.assertEquals(4, len(images))
def test_image_get_not_owned(self): TENANT1 = uuidutils.generate_uuid() TENANT2 = uuidutils.generate_uuid() ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1) ctxt2 = context.RequestContext(is_admin=False, tenant=TENANT2) image = self.db_api.image_create(ctxt1, { 'status': 'queued', 'owner': TENANT1 }) self.assertRaises(exception.Forbidden, self.db_api.image_get, ctxt2, image['id'])
def test_image_get_multiple_members(self): TENANT1 = uuidutils.generate_uuid() TENANT2 = uuidutils.generate_uuid() ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, owner_is_tenant=True) ctxt2 = context.RequestContext(is_admin=False, user=TENANT2, owner_is_tenant=False) UUIDX = uuidutils.generate_uuid() #we need private image and context.owner should not match image owner self.db_api.image_create(ctxt1, {'id': UUIDX, 'status': 'queued', 'is_public': False, 'owner': TENANT1}) values = {'image_id': UUIDX, 'member': TENANT2, 'can_share': False} self.db_api.image_member_create(ctxt1, values) image = self.db_api.image_get(ctxt2, UUIDX) self.assertEquals(UUIDX, image['id']) # by default get_all displays only images with status 'accepted' images = self.db_api.image_get_all(ctxt2) self.assertEquals(3, len(images)) # filter by rejected images = self.db_api.image_get_all(ctxt2, member_status='rejected') self.assertEquals(3, len(images)) # filter by visibility images = self.db_api.image_get_all(ctxt2, filters={'visibility': 'shared'}) self.assertEquals(0, len(images)) # filter by visibility images = self.db_api.image_get_all(ctxt2, member_status='pending', filters={'visibility': 'shared'}) self.assertEquals(1, len(images)) # filter by visibility images = self.db_api.image_get_all(ctxt2, member_status='all', filters={'visibility': 'shared'}) self.assertEquals(1, len(images)) # filter by status pending images = self.db_api.image_get_all(ctxt2, member_status='pending') self.assertEquals(4, len(images)) # filter by status all images = self.db_api.image_get_all(ctxt2, member_status='all') self.assertEquals(4, len(images))
def test_image_get_all_marker_null_container_format_asc(self): """Check an image with container_format null is handled Check an image with container_format null is handled when marker is specified and order is ascending """ TENANT1 = uuidutils.generate_uuid() ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1) UUIDX = uuidutils.generate_uuid() self.db_api.image_create(ctxt1, {"id": UUIDX, "status": "queued", "container_format": None, "owner": TENANT1}) images = self.db_api.image_get_all(ctxt1, marker=UUIDX, sort_key="container_format", sort_dir="asc") image_ids = [image["id"] for image in images] expected = [UUID3, UUID2, UUID1] self.assertEqual(sorted(expected), sorted(image_ids))
def test_image_get_all_owned(self): TENANT1 = uuidutils.generate_uuid() ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1) UUIDX = uuidutils.generate_uuid() self.db_api.image_create(ctxt1, {"id": UUIDX, "status": "queued", "owner": TENANT1}) TENANT2 = uuidutils.generate_uuid() ctxt2 = context.RequestContext(is_admin=False, tenant=TENANT2) UUIDY = uuidutils.generate_uuid() self.db_api.image_create(ctxt2, {"id": UUIDY, "status": "queued", "owner": TENANT2}) images = self.db_api.image_get_all(ctxt1) image_ids = [image["id"] for image in images] expected = [UUIDX, UUID3, UUID2, UUID1] self.assertEqual(sorted(expected), sorted(image_ids))
def image_create(context, image_values): global DATA image_id = image_values.get('id', uuidutils.generate_uuid()) if image_id in DATA['images']: raise exception.Duplicate() if 'status' not in image_values: raise exception.Invalid('status is a required attribute') allowed_keys = set([ 'id', 'name', 'status', 'min_ram', 'min_disk', 'size', 'checksum', 'locations', 'owner', 'protected', 'is_public', 'container_format', 'disk_format', 'created_at', 'updated_at', 'deleted_at', 'deleted', 'properties', 'tags' ]) incorrect_keys = set(image_values.keys()) - allowed_keys if incorrect_keys: raise exception.Invalid('The keys %s are not valid' % str(incorrect_keys)) image = _image_format(image_id, **image_values) DATA['images'][image_id] = image location_data = image_values.get('locations', None) if location_data is not None: _image_locations_set(image_id, location_data) DATA['tags'][image_id] = image.pop('tags', []) return _normalize_locations(copy.deepcopy(image))
def test_lifecycle(self): """Add, get and delete an image""" store = self.get_store() image_id = uuidutils.generate_uuid() image_data = StringIO.StringIO('XXX') image_checksum = 'bc9189406be84ec297464a514221406d' try: uri, add_size, add_checksum = store.add(image_id, image_data, 3) except NotImplementedError: msg = 'Configured store can not add images' self.skipTest(msg) self.assertEqual(3, add_size) self.assertEqual(image_checksum, add_checksum) store = self.get_store() location = glance.store.location.Location( self.store_name, store.get_store_location_class(), uri=uri, image_id=image_id) (get_iter, get_size) = store.get(location) self.assertEqual(3, get_size) self.assertEqual('XXX', ''.join(get_iter)) image_size = store.get_size(location) self.assertEqual(3, image_size) store.delete(location) self.assertRaises(exception.NotFound, store.get, location)
def test_remove_image_not_found(self): fake_uuid = uuidutils.generate_uuid() image = self.image_repo.get(UUID1) image.image_id = fake_uuid exc = self.assertRaises(exception.NotFound, self.image_repo.remove, image) self.assertTrue(fake_uuid in unicode(exc))
def _update_all_ids_to_uuids(t_images, t_image_members, t_image_properties): """Transition from INTEGER id to VARCHAR(36) id.""" images = list(t_images.select().execute()) for image in images: old_id = image["id"] new_id = uuidutils.generate_uuid() t_images.update().\ where(t_images.c.id == old_id).\ values(id=new_id).execute() t_image_members.update().\ where(t_image_members.c.image_id == old_id).\ values(image_id=new_id).execute() t_image_properties.update().\ where(t_image_properties.c.image_id == old_id).\ values(image_id=new_id).execute() t_image_properties.update().\ where(and_(or_(t_image_properties.c.name == 'kernel_id', t_image_properties.c.name == 'ramdisk_id'), t_image_properties.c.value == old_id)).\ values(value=new_id).execute()
def test_image_member_update_status(self): TENANT1 = uuidutils.generate_uuid() member = self.db_api.image_member_create(self.context, {"member": TENANT1, "image_id": UUID1}) member_id = member.pop("id") member.pop("created_at") member.pop("updated_at") expected = {"member": TENANT1, "image_id": UUID1, "status": "pending", "can_share": False} self.assertEqual(expected, member) member = self.db_api.image_member_update(self.context, member_id, {"status": "accepted"}) self.assertNotEqual(member["created_at"], member["updated_at"]) member.pop("id") member.pop("created_at") member.pop("updated_at") expected = {"member": TENANT1, "image_id": UUID1, "status": "accepted", "can_share": False} self.assertEqual(expected, member) members = self.db_api.image_member_find(self.context, member=TENANT1, image_id=UUID1) member = members[0] member.pop("id") member.pop("created_at") member.pop("updated_at") self.assertEqual(expected, member)
def __init__(self, auth_tok=None, user=None, tenant=None, roles=None, is_admin=False, read_only=False, show_deleted=False, owner_is_tenant=True, service_catalog=None, policy_enforcer=None): self.auth_tok = auth_tok self.user = user self.tenant = tenant self.roles = roles or [] self.read_only = read_only self._show_deleted = show_deleted self.owner_is_tenant = owner_is_tenant self.request_id = uuidutils.generate_uuid() self.service_catalog = service_catalog self.policy_enforcer = policy_enforcer or policy.Enforcer() self.is_admin = is_admin if not self.is_admin: self.is_admin = \ self.policy_enforcer.check_is_admin(self) if not hasattr(local.store, 'context'): self.update_store()
def test_add_saves_and_reraises_and_not_uses_wildcard_raise(self): image_id = uuidutils.generate_uuid() swift_size = self.store.large_object_size = 1024 loc = 'swift+https://%s:key@localhost:8080/glance/%s' swift_contents = "*" * swift_size connection = mock.Mock() def fake_delete_chunk(connection, container, chunks): try: raise Exception() except Exception: pass image_swift = StringIO.StringIO(swift_contents) connection.put_object.side_effect = exception.ClientConnectionError self.store._delete_stale_chunks = fake_delete_chunk self.assertRaises(exception.ClientConnectionError, self.store.add, image_id, image_swift, swift_size, connection)
def test_image_member_delete(self): TENANT1 = uuidutils.generate_uuid() fixture = {"member": TENANT1, "image_id": UUID1, "can_share": True} member = self.db_api.image_member_create(self.context, fixture) self.assertEqual(1, len(self.db_api.image_member_find(self.context))) member = self.db_api.image_member_delete(self.context, member["id"]) self.assertEqual(0, len(self.db_api.image_member_find(self.context)))
def test_add(self): """Test that we can add an image via the filesystem backend""" ChunkedFile.CHUNKSIZE = 1024 expected_image_id = uuidutils.generate_uuid() expected_file_size = 1024 * 5 # 5K expected_file_contents = "*" * expected_file_size expected_checksum = hashlib.md5(expected_file_contents).hexdigest() expected_location = "file://%s/%s" % (self.test_dir, expected_image_id) image_file = StringIO.StringIO(expected_file_contents) location, size, checksum = self.store.add(expected_image_id, image_file, expected_file_size) self.assertEquals(expected_location, location) self.assertEquals(expected_file_size, size) self.assertEquals(expected_checksum, checksum) uri = "file:///%s/%s" % (self.test_dir, expected_image_id) loc = get_location_from_uri(uri) (new_image_file, new_image_size) = self.store.get(loc) new_image_contents = "" new_image_file_size = 0 for chunk in new_image_file: new_image_file_size += len(chunk) new_image_contents += chunk self.assertEquals(expected_file_contents, new_image_contents) self.assertEquals(expected_file_size, new_image_file_size)
def test_image_member_update(self): TENANT1 = uuidutils.generate_uuid() member = self.db_api.image_member_create(self.context, {'member': TENANT1, 'image_id': UUID1}) member_id = member.pop('id') member.pop('created_at') member.pop('updated_at') expected = {'member': TENANT1, 'image_id': UUID1, 'can_share': False} self.assertEqual(expected, member) member = self.db_api.image_member_update(self.context, member_id, {'can_share': True}) self.assertNotEqual(member['created_at'], member['updated_at']) member.pop('id') member.pop('created_at') member.pop('updated_at') expected = {'member': TENANT1, 'image_id': UUID1, 'can_share': True} self.assertEqual(expected, member) members = self.db_api.image_member_find(self.context, member=TENANT1, image_id=UUID1) member = members[0] member.pop('id') member.pop('created_at') member.pop('updated_at') self.assertEqual(expected, member)
def test_image_member_create(self): timeutils.set_time_override() memberships = self.db_api.image_member_find(self.context) self.assertEqual([], memberships) create_time = timeutils.utcnow() TENANT1 = uuidutils.generate_uuid() self.db_api.image_member_create(self.context, {'member': TENANT1, 'image_id': UUID1}) memberships = self.db_api.image_member_find(self.context) self.assertEqual(1, len(memberships)) actual = memberships[0] self.assertEqual(actual['created_at'], create_time) self.assertEqual(actual['updated_at'], create_time) actual.pop('id') actual.pop('created_at') actual.pop('updated_at') expected = { 'member': TENANT1, 'image_id': UUID1, 'can_share': False, 'status': 'pending', } self.assertEqual(expected, actual)
def test_lifecycle(self): """Add, get and delete an image""" store = self.get_store() image_id = uuidutils.generate_uuid() image_data = StringIO.StringIO('XXX') image_checksum = 'bc9189406be84ec297464a514221406d' try: uri, add_size, add_checksum = store.add(image_id, image_data, 3) except NotImplementedError: msg = 'Configured store can not add images' raise nose.SkipTest(msg) self.assertEqual(3, add_size) self.assertEqual(image_checksum, add_checksum) store = self.get_store() location = glance.store.location.Location( self.store_name, store.get_store_location_class(), uri=uri, image_id=image_id) (get_iter, get_size) = store.get(location) self.assertEqual(3, get_size) self.assertEqual('XXX', ''.join(get_iter)) store.delete(location) self.assertRaises(exception.NotFound, store.get, location)
def test_image_member_delete(self): TENANT1 = uuidutils.generate_uuid() fixture = {'member': TENANT1, 'image_id': UUID1, 'can_share': True} member = self.db_api.image_member_create(self.context, fixture) self.assertEqual(1, len(self.db_api.image_member_find(self.context))) member = self.db_api.image_member_delete(self.context, member['id']) self.assertEqual(0, len(self.db_api.image_member_find(self.context)))
def test_get(self): """Test a "normal" retrieval of an image in chunks""" # First add an image... image_id = uuidutils.generate_uuid() file_contents = "chunk00000remainder" image_file = StringIO.StringIO(file_contents) location, size, checksum = self.store.add(image_id, image_file, len(file_contents)) # Now read it back... uri = "file:///%s/%s" % (self.test_dir, image_id) loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) expected_data = "chunk00000remainder" expected_num_chunks = 2 data = "" num_chunks = 0 for chunk in image_file: num_chunks += 1 data += chunk self.assertEqual(expected_data, data) self.assertEqual(expected_num_chunks, num_chunks)
def test_add_no_container_no_create(self): """ Tests that adding an image with a non-existing container raises an appropriate exception """ self.config(swift_store_create_container_on_put=False, swift_store_container='noexist') self.store = Store() image_swift = StringIO.StringIO("nevergonnamakeit") global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 # We check the exception text to ensure the container # missing text is found in it, otherwise, we would have # simply used self.assertRaises here exception_caught = False try: self.store.add(uuidutils.generate_uuid(), image_swift, 0) except BackendException as e: exception_caught = True self.assertTrue("container noexist does not exist " "in Swift" in str(e)) self.assertTrue(exception_caught) self.assertEquals(SWIFT_PUT_OBJECT_CALLS, 0)
def test_image_member_create(self): timeutils.set_time_override() memberships = self.db_api.image_member_find(self.context) self.assertEqual([], memberships) create_time = timeutils.utcnow() TENANT1 = uuidutils.generate_uuid() self.db_api.image_member_create(self.context, { 'member': TENANT1, 'image_id': UUID1 }) memberships = self.db_api.image_member_find(self.context) self.assertEqual(1, len(memberships)) actual = memberships[0] self.assertEqual(actual['created_at'], create_time) self.assertEqual(actual['updated_at'], create_time) actual.pop('id') actual.pop('created_at') actual.pop('updated_at') expected = { 'member': TENANT1, 'image_id': UUID1, 'can_share': False, 'status': 'pending', } self.assertEqual(expected, actual)
def image_create(context, image_values): global DATA image_id = image_values.get('id', uuidutils.generate_uuid()) if image_id in DATA['images']: raise exception.Duplicate() if 'status' not in image_values: raise exception.Invalid('status is a required attribute') allowed_keys = set(['id', 'name', 'status', 'min_ram', 'min_disk', 'size', 'checksum', 'locations', 'owner', 'protected', 'is_public', 'container_format', 'disk_format', 'created_at', 'updated_at', 'deleted_at', 'deleted', 'properties', 'tags']) incorrect_keys = set(image_values.keys()) - allowed_keys if incorrect_keys: raise exception.Invalid( 'The keys %s are not valid' % str(incorrect_keys)) image = _image_format(image_id, **image_values) DATA['images'][image_id] = image location_data = image_values.get('locations', None) if location_data is not None: _image_locations_set(image_id, location_data) DATA['tags'][image_id] = image.pop('tags', []) return _normalize_locations(copy.deepcopy(image))
def test_add_no_container_no_create(self): """ Tests that adding an image with a non-existing container raises an appropriate exception """ self.config(swift_store_create_container_on_put=False, swift_store_container='noexist') self.store = Store() image_swift = StringIO.StringIO("nevergonnamakeit") global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 # We check the exception text to ensure the container # missing text is found in it, otherwise, we would have # simply used self.assertRaises here exception_caught = False try: self.store.add(uuidutils.generate_uuid(), image_swift, 0) except BackendException as e: exception_caught = True self.assertTrue("container noexist does not exist " "in Swift" in str(e)) self.assertTrue(exception_caught) self.assertEqual(SWIFT_PUT_OBJECT_CALLS, 0)
def test_add_no_container_and_create(self): """ Tests that adding an image with a non-existing container creates the container automatically if flag is set """ expected_swift_size = FIVE_KB expected_swift_contents = "*" * expected_swift_size expected_checksum = hashlib.md5(expected_swift_contents).hexdigest() expected_image_id = uuidutils.generate_uuid() loc = 'swift+https://%s:key@localhost:8080/noexist/%s' expected_location = loc % (self.swift_store_user, expected_image_id) image_swift = StringIO.StringIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 self.config(swift_store_create_container_on_put=True, swift_store_container='noexist') self.store = Store() location, size, checksum, _ = self.store.add(expected_image_id, image_swift, expected_swift_size) self.assertEqual(expected_location, location) self.assertEqual(expected_swift_size, size) self.assertEqual(expected_checksum, checksum) self.assertEqual(SWIFT_PUT_OBJECT_CALLS, 1) loc = get_location_from_uri(expected_location) (new_image_swift, new_image_size) = self.store.get(loc) new_image_contents = new_image_swift.getvalue() new_image_swift_size = len(new_image_swift) self.assertEqual(expected_swift_contents, new_image_contents) self.assertEqual(expected_swift_size, new_image_swift_size)
def task_create(context, values): """Create a task object""" global DATA task_values = copy.deepcopy(values) task_id = task_values.get('id', uuidutils.generate_uuid()) required_attributes = ['type', 'status', 'input'] allowed_attributes = ['id', 'type', 'status', 'input', 'result', 'owner', 'message', 'expires_at', 'created_at', 'updated_at', 'deleted_at', 'deleted'] if task_id in DATA['tasks']: raise exception.Duplicate() for key in required_attributes: if key not in task_values: raise exception.Invalid('%s is a required attribute' % key) incorrect_keys = set(task_values.keys()) - set(allowed_attributes) if incorrect_keys: raise exception.Invalid( 'The keys %s are not valid' % str(incorrect_keys)) task_info_values = _pop_task_info_values(task_values) task = _task_format(task_id, **task_values) DATA['tasks'][task_id] = task task_info = _task_info_create(task['id'], task_info_values) return _format_task_from_db(task, task_info)
def test_add(self): """Test that we can add an image via the swift backend""" expected_swift_size = FIVE_KB expected_swift_contents = "*" * expected_swift_size expected_checksum = hashlib.md5(expected_swift_contents).hexdigest() expected_image_id = uuidutils.generate_uuid() loc = 'swift+https://%s:key@localhost:8080/glance/%s' expected_location = loc % (self.swift_store_user, expected_image_id) image_swift = StringIO.StringIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 location, size, checksum, _ = self.store.add(expected_image_id, image_swift, expected_swift_size) self.assertEqual(expected_location, location) self.assertEqual(expected_swift_size, size) self.assertEqual(expected_checksum, checksum) # Expecting a single object to be created on Swift i.e. no chunking. self.assertEqual(SWIFT_PUT_OBJECT_CALLS, 1) loc = get_location_from_uri(expected_location) (new_image_swift, new_image_size) = self.store.get(loc) new_image_contents = new_image_swift.getvalue() new_image_swift_size = len(new_image_swift) self.assertEqual(expected_swift_contents, new_image_contents) self.assertEqual(expected_swift_size, new_image_swift_size)
def task_create(context, task_values): """Create a task object""" global DATA task_id = task_values.get('id', uuidutils.generate_uuid()) required_attributes = ['type', 'status', 'input'] allowed_attributes = [ 'id', 'type', 'status', 'input', 'result', 'owner', 'message', 'expires_at', 'created_at', 'updated_at', 'deleted_at', 'deleted' ] if task_id in DATA['tasks']: raise exception.Duplicate() for key in required_attributes: if key not in task_values: raise exception.Invalid('%s is a required attribute' % key) incorrect_keys = set(task_values.keys()) - set(allowed_attributes) if incorrect_keys: raise exception.Invalid('The keys %s are not valid' % str(incorrect_keys)) task = _task_format(task_id, **task_values) DATA['tasks'][task_id] = task return copy.deepcopy(task)
def test_add(self): """Test that we can add an image via the s3 backend""" expected_image_id = uuidutils.generate_uuid() expected_s3_size = FIVE_KB expected_s3_contents = "*" * expected_s3_size expected_checksum = hashlib.md5(expected_s3_contents).hexdigest() expected_location = format_s3_location( S3_CONF['s3_store_access_key'], S3_CONF['s3_store_secret_key'], S3_CONF['s3_store_host'], S3_CONF['s3_store_bucket'], expected_image_id) image_s3 = StringIO.StringIO(expected_s3_contents) location, size, checksum, _ = self.store.add(expected_image_id, image_s3, expected_s3_size) self.assertEquals(expected_location, location) self.assertEquals(expected_s3_size, size) self.assertEquals(expected_checksum, checksum) loc = get_location_from_uri(expected_location) (new_image_s3, new_image_size) = self.store.get(loc) new_image_contents = StringIO.StringIO() for chunk in new_image_s3: new_image_contents.write(chunk) new_image_s3_size = new_image_contents.len self.assertEquals(expected_s3_contents, new_image_contents.getvalue()) self.assertEquals(expected_s3_size, new_image_s3_size)
def _image_member_format(image_id, tenant_id, can_share): return { 'id': uuidutils.generate_uuid(), 'image_id': image_id, 'member': tenant_id, 'can_share': can_share, }
def test_get(self): """Test a "normal" retrieval of an image in chunks""" # First add an image... image_id = uuidutils.generate_uuid() file_contents = "chunk00000remainder" location = "file://%s/%s" % (self.test_dir, image_id) image_file = StringIO.StringIO(file_contents) location, size, checksum = self.store.add(image_id, image_file, len(file_contents)) # Now read it back... uri = "file:///%s/%s" % (self.test_dir, image_id) loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) expected_data = "chunk00000remainder" expected_num_chunks = 2 data = "" num_chunks = 0 for chunk in image_file: num_chunks += 1 data += chunk self.assertEqual(expected_data, data) self.assertEqual(expected_num_chunks, num_chunks)
def _prerun_017(self, engine): metadata_encryption_key = "a" * 16 self.config(metadata_encryption_key=metadata_encryption_key) images = get_table(engine, "images") unquoted = "swift://*****:*****@example.com/container/obj-id" encrypted_unquoted = crypt.urlsafe_encrypt(metadata_encryption_key, unquoted, 64) data = [] now = datetime.datetime.now() temp = dict( deleted=False, created_at=now, updated_at=now, status="active", is_public=True, min_disk=0, min_ram=0, location=encrypted_unquoted, id="fakeid1", ) images.insert().values(temp).execute() locations = ["file://ab", "file://abc", "swift://acct3A%foobar:[email protected]/container/obj-id2"] now = datetime.datetime.now() temp = dict( deleted=False, created_at=now, updated_at=now, status="active", is_public=True, min_disk=0, min_ram=0 ) for i, location in enumerate(locations): temp.update(location=location, id=uuidutils.generate_uuid()) data.append(temp) images.insert().values(temp).execute() return data
def test_add(self): """Test that we can add an image via the swift backend""" expected_swift_size = FIVE_KB expected_swift_contents = "*" * expected_swift_size expected_checksum = hashlib.md5(expected_swift_contents).hexdigest() expected_image_id = uuidutils.generate_uuid() loc = 'swift+https://%s:key@localhost:8080/glance/%s' expected_location = loc % (self.swift_store_user, expected_image_id) image_swift = StringIO.StringIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 location, size, checksum = self.store.add(expected_image_id, image_swift, expected_swift_size) self.assertEquals(expected_location, location) self.assertEquals(expected_swift_size, size) self.assertEquals(expected_checksum, checksum) # Expecting a single object to be created on Swift i.e. no chunking. self.assertEquals(SWIFT_PUT_OBJECT_CALLS, 1) loc = get_location_from_uri(expected_location) (new_image_swift, new_image_size) = self.store.get(loc) new_image_contents = new_image_swift.getvalue() new_image_swift_size = len(new_image_swift) self.assertEquals(expected_swift_contents, new_image_contents) self.assertEquals(expected_swift_size, new_image_swift_size)
def test_unicode(self): # librbd does not handle unicode, so make sure # all paths through the rbd store convert a unicode image id # and uri to ascii before passing it to librbd. store = self.get_store() image_id = unicode(uuidutils.generate_uuid()) image_size = 300 image_data = StringIO.StringIO('X' * image_size) image_checksum = '41757066eaff7c4c6c965556b4d3c6c5' uri, add_size, add_checksum = store.add(image_id, image_data, image_size) uri = unicode(uri) self.assertEqual(image_size, add_size) self.assertEqual(image_checksum, add_checksum) location = glance.store.location.Location( self.store_name, store.get_store_location_class(), uri=uri, image_id=image_id) self.assertEqual(image_size, store.get_size(location)) get_iter, get_size = store.get(location) self.assertEqual(image_size, get_size) self.assertEqual('X' * image_size, ''.join(get_iter)) store.delete(location) self.assertRaises(exception.NotFound, store.get, location)
def test_add(self): """Test that we can add an image via the s3 backend""" expected_image_id = uuidutils.generate_uuid() expected_s3_size = FIVE_KB expected_s3_contents = "*" * expected_s3_size expected_checksum = hashlib.md5(expected_s3_contents).hexdigest() expected_location = format_s3_location(S3_CONF['s3_store_access_key'], S3_CONF['s3_store_secret_key'], S3_CONF['s3_store_host'], S3_CONF['s3_store_bucket'], expected_image_id) image_s3 = StringIO.StringIO(expected_s3_contents) location, size, checksum = self.store.add(expected_image_id, image_s3, expected_s3_size) self.assertEquals(expected_location, location) self.assertEquals(expected_s3_size, size) self.assertEquals(expected_checksum, checksum) loc = get_location_from_uri(expected_location) (new_image_s3, new_image_size) = self.store.get(loc) new_image_contents = StringIO.StringIO() for chunk in new_image_s3: new_image_contents.write(chunk) new_image_s3_size = new_image_contents.len self.assertEquals(expected_s3_contents, new_image_contents.getvalue()) self.assertEquals(expected_s3_size, new_image_s3_size)
def test_add_large_object_zero_size(self): """ Tests that adding an image to Swift which has both an unknown size and exceeds Swift's maximum limit of 5GB is correctly uploaded. We avoid the overhead of creating a 5GB object for this test by temporarily setting MAX_SWIFT_OBJECT_SIZE to 1KB, and then adding an object of 5KB. Bug lp:891738 """ # Set up a 'large' image of 5KB expected_swift_size = FIVE_KB expected_swift_contents = "*" * expected_swift_size expected_checksum = hashlib.md5(expected_swift_contents).hexdigest() expected_image_id = uuidutils.generate_uuid() loc = 'swift+https://%s:key@localhost:8080/glance/%s' expected_location = loc % (self.swift_store_user, expected_image_id) image_swift = StringIO.StringIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 # Temporarily set Swift MAX_SWIFT_OBJECT_SIZE to 1KB and add our image, # explicitly setting the image_length to 0 self.config(swift_store_container='glance') self.store = Store() orig_max_size = self.store.large_object_size orig_temp_size = self.store.large_object_chunk_size global MAX_SWIFT_OBJECT_SIZE orig_max_swift_object_size = MAX_SWIFT_OBJECT_SIZE try: MAX_SWIFT_OBJECT_SIZE = 1024 self.store.large_object_size = 1024 self.store.large_object_chunk_size = 1024 location, size, checksum = self.store.add(expected_image_id, image_swift, 0) finally: self.store.large_object_chunk_size = orig_temp_size self.store.large_object_size = orig_max_size MAX_SWIFT_OBJECT_SIZE = orig_max_swift_object_size self.assertEquals(expected_location, location) self.assertEquals(expected_swift_size, size) self.assertEquals(expected_checksum, checksum) # Expecting 7 calls to put_object -- 5 chunks, a zero chunk which is # then deleted, and the manifest. Note the difference with above # where the image_size is specified in advance (there's no zero chunk # in that case). self.assertEquals(SWIFT_PUT_OBJECT_CALLS, 7) loc = get_location_from_uri(expected_location) (new_image_swift, new_image_size) = self.store.get(loc) new_image_contents = new_image_swift.getvalue() new_image_swift_size = len(new_image_swift) self.assertEquals(expected_swift_contents, new_image_contents) self.assertEquals(expected_swift_size, new_image_swift_size)
def test_add_large_object_zero_size(self): """ Tests that adding an image to Swift which has both an unknown size and exceeds Swift's maximum limit of 5GB is correctly uploaded. We avoid the overhead of creating a 5GB object for this test by temporarily setting MAX_SWIFT_OBJECT_SIZE to 1KB, and then adding an object of 5KB. Bug lp:891738 """ # Set up a 'large' image of 5KB expected_swift_size = FIVE_KB expected_swift_contents = "*" * expected_swift_size expected_checksum = hashlib.md5(expected_swift_contents).hexdigest() expected_image_id = uuidutils.generate_uuid() loc = 'swift+https://%s:key@localhost:8080/glance/%s' expected_location = loc % (self.swift_store_user, expected_image_id) image_swift = StringIO.StringIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 # Temporarily set Swift MAX_SWIFT_OBJECT_SIZE to 1KB and add our image, # explicitly setting the image_length to 0 self.config(swift_store_container='glance') self.store = Store() orig_max_size = self.store.large_object_size orig_temp_size = self.store.large_object_chunk_size global MAX_SWIFT_OBJECT_SIZE orig_max_swift_object_size = MAX_SWIFT_OBJECT_SIZE try: MAX_SWIFT_OBJECT_SIZE = 1024 self.store.large_object_size = 1024 self.store.large_object_chunk_size = 1024 location, size, checksum, _ = self.store.add( expected_image_id, image_swift, 0) finally: self.store.large_object_chunk_size = orig_temp_size self.store.large_object_size = orig_max_size MAX_SWIFT_OBJECT_SIZE = orig_max_swift_object_size self.assertEqual(expected_location, location) self.assertEqual(expected_swift_size, size) self.assertEqual(expected_checksum, checksum) # Expecting 7 calls to put_object -- 5 chunks, a zero chunk which is # then deleted, and the manifest. Note the difference with above # where the image_size is specified in advance (there's no zero chunk # in that case). self.assertEqual(SWIFT_PUT_OBJECT_CALLS, 7) loc = get_location_from_uri(expected_location) (new_image_swift, new_image_size) = self.store.get(loc) new_image_contents = new_image_swift.getvalue() new_image_swift_size = len(new_image_swift) self.assertEqual(expected_swift_contents, new_image_contents) self.assertEqual(expected_swift_size, new_image_swift_size)
def test_image_get_multiple_members(self): TENANT1 = uuidutils.generate_uuid() TENANT2 = uuidutils.generate_uuid() ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, owner_is_tenant=True) ctxt2 = context.RequestContext(is_admin=False, user=TENANT2, owner_is_tenant=False) UUIDX = uuidutils.generate_uuid() #we need private image and context.owner should not match image owner self.db_api.image_create(ctxt1, {'id': UUIDX, 'status': 'queued', 'is_public': False, 'owner': TENANT1}) values = {'image_id': UUIDX, 'member': TENANT2, 'can_share': False} self.db_api.image_member_create(ctxt1, values) image = self.db_api.image_get(ctxt2, UUIDX) self.assertEquals(UUIDX, image['id'])
def test_remove_image_member_does_not_exist(self): fake_uuid = uuidutils.generate_uuid() image = self.image_repo.get(UUID2) fake_member = glance.domain.ImageMemberFactory()\ .new_image_member(image, TENANT4) fake_member.id = fake_uuid exc = self.assertRaises(exception.NotFound, self.image_member_repo.remove, fake_member) self.assertTrue(fake_uuid in unicode(exc))
def test_object_chunking(self): """Upload an image that is split into multiple swift objects. We specifically check the case that image_size % swift_store_large_object_chunk_size != 0 to ensure we aren't losing image data. """ self.config(swift_store_large_object_size=2, swift_store_large_object_chunk_size=2) # 2 MB # 2 MB store = self.get_store() image_id = uuidutils.generate_uuid() image_size = 5242880 # 5 MB image_data = StringIO.StringIO("X" * image_size) image_checksum = "eb7f8c3716b9f059cee7617a4ba9d0d3" uri, add_size, add_checksum = store.add(image_id, image_data, image_size) self.assertEqual(image_size, add_size) self.assertEqual(image_checksum, add_checksum) location = glance.store.location.Location( self.store_name, store.get_store_location_class(), uri=uri, image_id=image_id ) # Store interface should still be respected even though # we are storing images in multiple Swift objects (get_iter, get_size) = store.get(location) self.assertEqual(5242880, get_size) self.assertEqual("X" * 5242880, "".join(get_iter)) # The object should have a manifest pointing to the chunks # of image data swift_location = location.store_location headers = swift_head_object(self.swift_client, swift_location.container, swift_location.obj) manifest = headers.get("x-object-manifest") self.assertTrue(manifest) # Verify the objects in the manifest exist manifest_container, manifest_prefix = manifest.split("/", 1) container = swift_get_container(self.swift_client, manifest_container, prefix=manifest_prefix) segments = [segment["name"] for segment in container[1]] for segment in segments: headers = swift_head_object(self.swift_client, manifest_container, segment) self.assertTrue(headers.get("content-length")) # Since we used a 5 MB image with a 2 MB chunk size, we should # expect to see the manifest object and three data objects for # a total of 4 self.assertEqual(4, len(segments), "Got segments %s" % segments) store.delete(location) # Verify the segments in the manifest are all gone for segment in segments: self.assertRaises( swiftclient.ClientException, swift_head_object, self.swift_client, manifest_container, segment )
def test_add_auth_url_variations(self): """ Test that we can add an image via the swift backend with a variety of different auth_address values """ variations = { 'http://*****:*****@localhost:80' '/glance/%s', 'http://localhost': 'swift+http://%s:key@localhost/glance/%s', 'http://localhost/v1': 'swift+http://%s:key@localhost' '/v1/glance/%s', 'http://localhost/v1/': 'swift+http://%s:key@localhost' '/v1/glance/%s', 'https://localhost': 'swift+https://%s:key@localhost/glance/%s', 'https://*****:*****@localhost:8080' '/glance/%s', 'https://localhost/v1': 'swift+https://%s:key@localhost' '/v1/glance/%s', 'https://localhost/v1/': 'swift+https://%s:key@localhost' '/v1/glance/%s', 'localhost': 'swift+https://%s:key@localhost/glance/%s', 'localhost:8080/v1': 'swift+https://%s:key@localhost:8080' '/v1/glance/%s', } for variation, expected_location in variations.items(): image_id = uuidutils.generate_uuid() expected_location = expected_location % ( self.swift_store_user, image_id) expected_swift_size = FIVE_KB expected_swift_contents = "*" * expected_swift_size expected_checksum = \ hashlib.md5(expected_swift_contents).hexdigest() image_swift = StringIO.StringIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 self.config(swift_store_auth_address=variation) self.store = Store() location, size, checksum = self.store.add(image_id, image_swift, expected_swift_size) self.assertEquals(expected_location, location) self.assertEquals(expected_swift_size, size) self.assertEquals(expected_checksum, checksum) self.assertEquals(SWIFT_PUT_OBJECT_CALLS, 1) loc = get_location_from_uri(expected_location) (new_image_swift, new_image_size) = self.store.get(loc) new_image_contents = new_image_swift.getvalue() new_image_swift_size = len(new_image_swift) self.assertEquals(expected_swift_contents, new_image_contents) self.assertEquals(expected_swift_size, new_image_swift_size)
def test_upload_non_existent_image_during_save(self): def fake_save(self): raise exception.NotFound() request = unit_test_utils.get_fake_request() image = FakeImage('abcd', locations=['http://example.com/image']) self.image_repo.result = image self.image_repo.save = fake_save self.assertRaises(webob.exc.HTTPGone, self.controller.upload, request, uuidutils.generate_uuid(), 'ABC', 3)
def test_download_get_image_location_forbidden(self): class ImageLocations(object): def __len__(self): raise exception.Forbidden() request = unit_test_utils.get_fake_request() image = FakeImage('abcd') self.image_repo.result = image image.locations = ImageLocations() self.assertRaises(webob.exc.HTTPForbidden, self.controller.download, request, uuidutils.generate_uuid())
def _image_member_format(image_id, tenant_id, can_share, status='pending'): dt = timeutils.utcnow() return { 'id': uuidutils.generate_uuid(), 'image_id': image_id, 'member': tenant_id, 'can_share': can_share, 'status': status, 'created_at': dt, 'updated_at': dt, }
def _image_locations_format(image_id, value, meta_data): dt = timeutils.utcnow() return { 'id': uuidutils.generate_uuid(), 'image_id': image_id, 'created_at': dt, 'updated_at': dt, 'deleted_at': None, 'deleted': False, 'url': value, 'metadata': meta_data, }
def test_image_get_all_owned(self): TENANT1 = uuidutils.generate_uuid() ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1) UUIDX = uuidutils.generate_uuid() self.db_api.image_create(ctxt1, { 'id': UUIDX, 'status': 'queued', 'owner': TENANT1 }) TENANT2 = uuidutils.generate_uuid() ctxt2 = context.RequestContext(is_admin=False, tenant=TENANT2) UUIDY = uuidutils.generate_uuid() self.db_api.image_create(ctxt2, { 'id': UUIDY, 'status': 'queued', 'owner': TENANT2 }) images = self.db_api.image_get_all(ctxt1) image_ids = [image['id'] for image in images] expected = [UUIDX, UUID3, UUID2, UUID1] self.assertEqual(sorted(expected), sorted(image_ids))
def test_get_remote_image(self): """Get an image that was created externally to Glance""" image_id = uuidutils.generate_uuid() image_uri = self.stash_image(image_id, 'XXX') store = self.get_store() location = glance.store.location.Location( self.store_name, store.get_store_location_class(), uri=image_uri) (get_iter, get_size) = store.get(location) self.assertEqual(3, get_size) self.assertEqual('XXX', ''.join(get_iter)) image_size = store.get_size(location) self.assertEqual(3, image_size)
def test_add_check_metadata_bad_nosuch_file(self): expected_image_id = uuidutils.generate_uuid() jsonfilename = os.path.join(self.test_dir, "storage_metadata.%s" % expected_image_id) self.config(filesystem_store_metadata_file=jsonfilename) expected_file_size = 10 expected_file_contents = "*" * expected_file_size image_file = StringIO.StringIO(expected_file_contents) location, size, checksum, metadata = self.store.add( expected_image_id, image_file, expected_file_size) self.assertEqual(metadata, {})
def test_task_invalid_status(self): task_id = uuidutils.generate_uuid() status = 'blah' self.assertRaises(exception.InvalidTaskStatus, domain.Task, task_id, type='import', status=status, input=None, result=None, owner=None, message=None, expires_at=None, created_at=timeutils.utcnow(), updated_at=timeutils.utcnow())