Use id mapping for auto creation of db item for alien images

In according to initial DB API contract, a user can not modify db items
of other project. Shortly before 0.1.0 release this had been broken due
to a critical bugfix.

This patch makes images to avoid creating of db item in other project.
It uses db mapping instead.

Change-Id: I07119b7e1348bbe63e5c736dad4141daa2a07fb9
This commit is contained in:
Feodor Tersin 2015-08-12 19:17:34 +03:00
parent 3adf3a1f50
commit bcf40ac932
2 changed files with 22 additions and 7 deletions

View File

@ -308,9 +308,16 @@ class ImageDescriber(common.TaggableItemsDescriber):
def auto_update_db(self, image, os_image):
if not image:
kind = _get_os_image_kind(os_image)
image = ec2utils.get_db_item_by_os_id(
self.context, kind, os_image.id, self.items_dict,
os_image=os_image, project_id=os_image.owner)
if self.context.project_id == os_image.owner:
image = ec2utils.get_db_item_by_os_id(
self.context, kind, os_image.id, self.items_dict,
os_image=os_image)
else:
image_id = ec2utils.os_id_to_ec2_id(
self.context, kind, os_image.id,
items_by_os_id=self.items_dict, ids_by_os_id=self.ids_dict)
image = {'id': image_id,
'os_id': os_image.id}
elif (self.context.project_id == os_image.owner and
image.get('is_public') != os_image.is_public):
image['is_public'] = os_image.is_public

View File

@ -97,9 +97,17 @@ class DBItemsAutoCreationTestCase(base.MockOSMixin, base.DbTestCase):
aki_image = next(i for i in images['imagesSet']
if i['imageType'] == 'kernel')
self.assertEqual(image_project_id, image['imageOwnerId'])
self.assert_image_project(image_project_id, image['imageId'])
self.assert_image_project(
(image_project_id
if image_project_id == fakes.ID_OS_PROJECT else
None),
image['imageId'])
self.assertEqual(aki_image_project_id, aki_image['imageOwnerId'])
self.assert_image_project(aki_image_project_id, aki_image['imageId'])
self.assert_image_project(
(aki_image_project_id
if aki_image_project_id == fakes.ID_OS_PROJECT else
None),
aki_image['imageId'])
def test_describe_new_alien_images(self):
alien_project_id = fakes.random_os_id()
@ -233,7 +241,7 @@ class DBItemsAutoCreationTestCase(base.MockOSMixin, base.DbTestCase):
bdm_image_project_id=alien_project_id)
image_id = self._find_snapshot_id_in_bdm(image, '/dev/vdi')
image_api.describe_images(self.context, image_id=[image_id])
self.assert_image_project(alien_project_id, image_id)
self.assert_image_project(None, image_id)
def test_describe_new_alien_bdm_image_from_new_alien_image(self):
alien_project_id = fakes.random_os_id()
@ -242,7 +250,7 @@ class DBItemsAutoCreationTestCase(base.MockOSMixin, base.DbTestCase):
bdm_image_project_id=alien_project_id)
image_id = self._find_snapshot_id_in_bdm(image, '/dev/vdi')
image_api.describe_images(self.context, image_id=[image_id])
self.assert_image_project(alien_project_id, image_id)
self.assert_image_project(None, image_id)
def _test_describe_new_instance_then_its_image(self, image_project_id):
os_instance_id = fakes.random_os_id()