Refactor image test cases for shared images
Change-Id: Icd8a6417d9c0cd328bda9c6412e43851574f268c
This commit is contained in:
parent
bd5acac654
commit
e123abc10e
@ -48,7 +48,7 @@ class ImsBaseOrmTest(base.BaseOrmTest):
|
||||
|
||||
@classmethod
|
||||
def _get_image_params(cls, set_region=True, single_tenant=True,
|
||||
set_private=True, set_enabled=True):
|
||||
set_shared=True, set_enabled=True):
|
||||
region, post_body = {}, {}
|
||||
post_body["id"] = uuid.uuid4().hex
|
||||
post_body["name"] = data_utils.rand_name(
|
||||
@ -62,16 +62,16 @@ class ImsBaseOrmTest(base.BaseOrmTest):
|
||||
region["type"] = "single"
|
||||
|
||||
# set enabled status to True or False based on set_enabled value
|
||||
post_body["enabled"] = True if set_enabled else False
|
||||
post_body["enabled"] = bool(set_enabled)
|
||||
# add region for the image as needed
|
||||
post_body["regions"] = [region] if set_region else []
|
||||
# create image with visibililty = "public" or "private"
|
||||
post_body["visibility"] = "private" if set_private else "public"
|
||||
# create image with visibililty = "public" or "shared"
|
||||
post_body["visibility"] = "shared" if set_shared else "public"
|
||||
# set image tags
|
||||
post_body["tags"] = ["tag1", "tag2"]
|
||||
|
||||
# add tenant for the image only if set_private
|
||||
if set_private:
|
||||
# add tenant for the image only if set_shared
|
||||
if set_shared:
|
||||
if single_tenant:
|
||||
post_body["customers"] = [cls.tenant_id]
|
||||
else:
|
||||
@ -106,9 +106,9 @@ class ImsBaseOrmTest(base.BaseOrmTest):
|
||||
|
||||
cls._wait_for_image_status_on_dcp(image_id, image_status)
|
||||
return image
|
||||
else:
|
||||
message = ('image %s not created successfully' % kwargs["name"])
|
||||
raise exceptions.TempestException(message)
|
||||
|
||||
message = ('image %s not created successfully' % kwargs["name"])
|
||||
raise exceptions.TempestException(message)
|
||||
|
||||
@classmethod
|
||||
def _wait_for_image_status_on_dcp(cls, image_id, status):
|
||||
@ -140,12 +140,12 @@ class ImsBaseOrmTest(base.BaseOrmTest):
|
||||
if image_id not in image_ids:
|
||||
message = ('Image %s not in image list on LCP' % image_id)
|
||||
raise exceptions.TempestException(message)
|
||||
else:
|
||||
image_status = cls.client.show_image()["image"]["status"]
|
||||
if image_status != status:
|
||||
message = ('Image %s is in %s status instead of %s on LCP.'
|
||||
% (image_id, image_status, status))
|
||||
raise exceptions.TempestException(message)
|
||||
|
||||
image_status = cls.client.show_image()["image"]["status"]
|
||||
if image_status != status:
|
||||
message = ('Image %s is in %s status instead of %s on LCP.'
|
||||
% (image_id, image_status, status))
|
||||
raise exceptions.TempestException(message)
|
||||
|
||||
@classmethod
|
||||
def _update_img_validate_status_on_dcp_and_lcp(cls, image_id, para=None,
|
||||
@ -202,8 +202,8 @@ class ImsBaseOrmTest(base.BaseOrmTest):
|
||||
time.sleep(cls.build_interval)
|
||||
_, image_list = cls.client.list_images()["images"]
|
||||
image_ids = [image["id"]
|
||||
for image in image_list if image["id"] ==
|
||||
image_id]
|
||||
for image in image_list if image["id"]
|
||||
== image_id]
|
||||
if image_ids:
|
||||
image_status = image_list[0]["status"]
|
||||
_, body = cls.client.list_images()["images"]
|
||||
|
@ -45,10 +45,10 @@ class TestTempestIms(ims_base.ImsBaseOrmTest):
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
super(TestTempestIms, cls).resource_setup()
|
||||
# setup public image for tempest testing
|
||||
# setup image parameters for tempest testing
|
||||
cls.image_params_public = \
|
||||
cls._get_image_params(set_private=False)
|
||||
cls.image_params_private = \
|
||||
cls._get_image_params(set_shared=False)
|
||||
cls.image_params_shared = \
|
||||
cls._get_image_params(set_enabled=False)
|
||||
|
||||
cls.addClassResourceCleanup(
|
||||
@ -56,17 +56,17 @@ class TestTempestIms(ims_base.ImsBaseOrmTest):
|
||||
cls.image_params_public['id'])
|
||||
cls.addClassResourceCleanup(
|
||||
cls._del_img_validate_deletion_on_dcp_and_lcp,
|
||||
cls.image_params_private['id'])
|
||||
cls.image_params_shared['id'])
|
||||
|
||||
# setup public image for tempest testing
|
||||
cls.public_image = \
|
||||
cls._create_img_and_validate_creation_on_dcp_and_lcp(
|
||||
**cls.image_params_public)
|
||||
|
||||
# setup private image for tempest testing
|
||||
cls.private_image = \
|
||||
# setup shared image for tempest testing
|
||||
cls.shared_image = \
|
||||
cls._create_img_and_validate_creation_on_dcp_and_lcp(
|
||||
**cls.image_params_private)
|
||||
**cls.image_params_shared)
|
||||
|
||||
def _update_region(self, region_name, status=None):
|
||||
if status is None:
|
||||
@ -122,7 +122,7 @@ class TestTempestIms(ims_base.ImsBaseOrmTest):
|
||||
- no filter (i.e. list all images)
|
||||
- filter by region
|
||||
- filter by customer
|
||||
- filter by visibility (public/private)
|
||||
- filter by visibility (public/shared)
|
||||
"""
|
||||
|
||||
# define the list customer filters to be used for this test
|
||||
@ -130,24 +130,24 @@ class TestTempestIms(ims_base.ImsBaseOrmTest):
|
||||
customer_filter = "?customer=%s" % self.tenant_id
|
||||
region_filter = "?region=%s" % self.region_id
|
||||
public_filter = "?visibility=public"
|
||||
private_filter = "?visibility=private"
|
||||
shared_filter = "?visibility=shared"
|
||||
|
||||
# list public images
|
||||
_, body = self.client.list_images(public_filter)
|
||||
image_ids = [img['id'] for img in body['images']]
|
||||
self.assertIn(self.public_image['id'], image_ids)
|
||||
|
||||
# list private images
|
||||
_, body = self.client.list_images(private_filter)
|
||||
# list shared images
|
||||
_, body = self.client.list_images(shared_filter)
|
||||
image_ids = [img['id'] for img in body['images']]
|
||||
self.assertIn(self.private_image['id'], image_ids)
|
||||
self.assertIn(self.shared_image['id'], image_ids)
|
||||
|
||||
# execute list_customers with the rest of the filters
|
||||
for list_filter in [no_filter, region_filter,
|
||||
customer_filter]:
|
||||
_, body = self.client.list_images(list_filter)
|
||||
images = [image['id'] for image in body['images']]
|
||||
self.assertIn(self.private_image['id'], images)
|
||||
self.assertIn(self.shared_image['id'], images)
|
||||
|
||||
@decorators.idempotent_id('4435fef4-49a9-435b-8463-cf8a1e0b7cd8')
|
||||
def test_disable_image(self):
|
||||
@ -162,10 +162,10 @@ class TestTempestIms(ims_base.ImsBaseOrmTest):
|
||||
|
||||
@decorators.idempotent_id('f32a13e3-6f38-423b-a616-09c8d4e1c277')
|
||||
def test_enable_image(self):
|
||||
# enable self.private_image and check if request is successful
|
||||
self.client.enabled_image(self.private_image['id'], True)
|
||||
self._wait_for_image_status_on_dcp(self.private_image['id'], 'Success')
|
||||
_, body = self.client.get_image(self.private_image['id'])
|
||||
# enable self.shared_image and check if request is successful
|
||||
self.client.enabled_image(self.shared_image['id'], True)
|
||||
self._wait_for_image_status_on_dcp(self.shared_image['id'], 'Success')
|
||||
_, body = self.client.get_image(self.shared_image['id'])
|
||||
image = body["image"]
|
||||
|
||||
# assert that the image["enabled"] value is 'True'
|
||||
@ -199,49 +199,49 @@ class TestTempestIms(ims_base.ImsBaseOrmTest):
|
||||
|
||||
@decorators.idempotent_id('0ee68189-66a8-4213-ad68-bc12991c174a')
|
||||
def test_add_delete_image_tenant(self):
|
||||
# add alt tenant to self.private_image & check if status = "Success"
|
||||
self.client.add_customer_to_image(self.private_image['id'],
|
||||
# add alt tenant to self.shared_image & check if status = "Success"
|
||||
self.client.add_customer_to_image(self.shared_image['id'],
|
||||
self.alt_tenant_id)
|
||||
self._wait_for_image_status_on_dcp(self.private_image['id'],
|
||||
self._wait_for_image_status_on_dcp(self.shared_image['id'],
|
||||
'Success')
|
||||
|
||||
# check that alt tenant successfully added to image tenants array
|
||||
_, body = self.client.get_image(self.private_image['id'])
|
||||
# check that alt tenant successfully added to image tenants list
|
||||
_, body = self.client.get_image(self.shared_image['id'])
|
||||
image = body["image"]
|
||||
self.assertEqual(len(image["customers"]), 2)
|
||||
self.assertIn(self.alt_tenant_id, image['customers'])
|
||||
|
||||
# now delete alt_tenant_id and ensure operation is successful
|
||||
_, body = self.client.delete_customer_from_image(
|
||||
self.private_image['id'],
|
||||
self.shared_image['id'],
|
||||
self.alt_tenant_id)
|
||||
self._wait_for_image_status_on_dcp(self.private_image['id'], 'Success')
|
||||
self._wait_for_image_status_on_dcp(self.shared_image['id'], 'Success')
|
||||
|
||||
# image region array should no longer contain alt tenant
|
||||
_, body = self.client.get_image(self.private_image['id'])
|
||||
_, body = self.client.get_image(self.shared_image['id'])
|
||||
image = body["image"]
|
||||
self.assertNotIn(self.alt_tenant_id, image['customers'])
|
||||
|
||||
@decorators.idempotent_id('bac99348-6b13-4b30-958b-3c039b27eda3')
|
||||
def test_update_image_tenant(self):
|
||||
# replace current tenant in self.private_image with alt tenant
|
||||
self.client.update_customer(self.private_image['id'],
|
||||
# replace current tenant in self.shared_image with alt tenant
|
||||
self.client.update_customer(self.shared_image['id'],
|
||||
self.alt_tenant_id)
|
||||
self._wait_for_image_status_on_dcp(self.private_image['id'], 'Success')
|
||||
self._wait_for_image_status_on_dcp(self.shared_image['id'], 'Success')
|
||||
|
||||
# check that image tenants array contains only alt tenant
|
||||
_, body = self.client.get_image(self.private_image['id'])
|
||||
_, body = self.client.get_image(self.shared_image['id'])
|
||||
image = body["image"]
|
||||
self.assertEqual(len(image["customers"]), 1)
|
||||
self.assertIn(self.alt_tenant_id, image['customers'])
|
||||
|
||||
@decorators.idempotent_id('0331e02a-ab52-4341-b676-a02462244277')
|
||||
def test_create_image(self):
|
||||
def test_create_shared_image(self):
|
||||
post_body = self._get_image_params()
|
||||
self.addCleanup(
|
||||
self._del_img_validate_deletion_on_dcp_and_lcp,
|
||||
post_body['id'])
|
||||
# call client create_IMAGE and wait till status equals 'Success'
|
||||
# call client create_image and wait till status equals 'Success'
|
||||
_, body = self.client.create_image(**post_body)
|
||||
image = body["image"]
|
||||
self._wait_for_image_status_on_dcp(image['id'], 'Success')
|
||||
@ -250,6 +250,61 @@ class TestTempestIms(ims_base.ImsBaseOrmTest):
|
||||
_, body = self.client.get_image(image['id'])
|
||||
image = body["image"]
|
||||
self.assertEqual(image["regions"][0]["name"], CONF.identity.region)
|
||||
self.assertEqual(image["visibility"], post_body['visibility'])
|
||||
|
||||
@decorators.idempotent_id('28fb9788-b3a2-4ea1-a3a2-fac63018c05b')
|
||||
def test_create_private_image(self):
|
||||
post_body = self._get_image_params(set_shared=False)
|
||||
post_body["visibility"] = "private"
|
||||
self.addCleanup(
|
||||
self._del_img_validate_deletion_on_dcp_and_lcp,
|
||||
post_body['id'])
|
||||
# call client create_image and wait till status equals 'Success'
|
||||
_, body = self.client.create_image(**post_body)
|
||||
image = body["image"]
|
||||
self._wait_for_image_status_on_dcp(image['id'], 'Success')
|
||||
|
||||
# verify image record created successfully
|
||||
_, body = self.client.get_image(image['id'])
|
||||
image = body["image"]
|
||||
self.assertEqual(image["regions"][0]["name"], CONF.identity.region)
|
||||
self.assertEqual(image["visibility"], post_body['visibility'])
|
||||
|
||||
@decorators.idempotent_id('01806310-2a14-4ebb-9679-cce5ee7401b0')
|
||||
def test_create_private_image_with_customer(self):
|
||||
post_body = self._get_image_params()
|
||||
post_body["visibility"] = "private"
|
||||
|
||||
# private image can not have associated customers list
|
||||
self.assertRaises(exceptions.BadRequest,
|
||||
self.client.create_image, **post_body)
|
||||
|
||||
@decorators.idempotent_id('06defa6d-3ce9-4428-8b36-09a351dba872')
|
||||
def test_create_community_image(self):
|
||||
post_body = self._get_image_params(set_shared=False)
|
||||
post_body["visibility"] = "community"
|
||||
self.addCleanup(
|
||||
self._del_img_validate_deletion_on_dcp_and_lcp,
|
||||
post_body['id'])
|
||||
# call client create_image and wait till status equals 'Success'
|
||||
_, body = self.client.create_image(**post_body)
|
||||
image = body["image"]
|
||||
self._wait_for_image_status_on_dcp(image['id'], 'Success')
|
||||
|
||||
# verify image record created successfully
|
||||
_, body = self.client.get_image(image['id'])
|
||||
image = body["image"]
|
||||
self.assertEqual(image["regions"][0]["name"], CONF.identity.region)
|
||||
self.assertEqual(image["visibility"], post_body['visibility'])
|
||||
|
||||
@decorators.idempotent_id('298976ae-a6d6-4cdd-b679-786a29eefe2f')
|
||||
def test_create_community_image_with_customer(self):
|
||||
post_body = self._get_image_params()
|
||||
post_body["visibility"] = "community"
|
||||
|
||||
# private image can not have associated customers list
|
||||
self.assertRaises(exceptions.BadRequest,
|
||||
self.client.create_image, **post_body)
|
||||
|
||||
@decorators.idempotent_id('01160918-e217-401d-a6a0-e7992ab76e41')
|
||||
def test_update_image(self):
|
||||
@ -365,8 +420,8 @@ class TestTempestIms(ims_base.ImsBaseOrmTest):
|
||||
@decorators.idempotent_id('eae7ca20-5383-4579-9f73-0138b8b3ec85')
|
||||
def test_list_public_images(self):
|
||||
"""List images with visibility = 'public'"""
|
||||
# set_private = False to create image with visibility = 'public'
|
||||
post_body = self._get_image_params(set_private=False)
|
||||
# set_shared = False to create image with visibility = 'public'
|
||||
post_body = self._get_image_params(set_shared=False)
|
||||
image = self._data_setup(post_body)
|
||||
test_image_id = image['id']
|
||||
# confirm image visibility is set to "public" after image is created
|
||||
@ -379,17 +434,17 @@ class TestTempestIms(ims_base.ImsBaseOrmTest):
|
||||
self.assertIn(test_image_id, image_ids)
|
||||
|
||||
@decorators.idempotent_id('dc321d60-f3bd-477c-b7bf-1594626f0a12')
|
||||
def test_list_private_images(self):
|
||||
"""List images with visibility = 'private' """
|
||||
# image data created with visibility = private set by default
|
||||
def test_list_shared_images(self):
|
||||
"""List images with visibility = 'shared' """
|
||||
# image data created with visibility = shared set by default
|
||||
post_body = self._get_image_params()
|
||||
image = self._data_setup(post_body)
|
||||
# confirm image visibility is set to "private" after image is created
|
||||
self.assertEqual(image["visibility"], "private")
|
||||
filter_private_images = "?visibility=%s" % image["visibility"]
|
||||
# confirm image visibility is set to "shared" after image is created
|
||||
self.assertEqual(image["visibility"], "shared")
|
||||
filter_shared_images = "?visibility=%s" % image["visibility"]
|
||||
|
||||
# list all public images and check if image id is in the list
|
||||
_, body = self.client.list_images(filter_private_images)
|
||||
# list all shared images and check if image id is in the list
|
||||
_, body = self.client.list_images(filter_shared_images)
|
||||
image_ids = [img['id'] for img in body['images']]
|
||||
self.assertIn(image['id'], image_ids)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user