Fix the key error in ims resource_setup and _data_setup methods

The resource_setup and _data_setup methods fails while running
ims test cases with below error.

KeyError: 'id'

Pre generate the id and associate with payload so that clean up
can be called before resource creation to avoid resource leak.

Change-Id: I751b187918302a3708f20a41e015e470fa5a6ff5
This commit is contained in:
Ansuman Bebarta 2019-11-27 20:33:25 +05:30
parent f79ac16d20
commit 22f72955cc
2 changed files with 11 additions and 12 deletions

View File

@ -14,6 +14,7 @@
# under the License.
import time
import uuid
from oslo_log import log as logging
from ranger_tempest_plugin.tests.api import base
@ -49,6 +50,7 @@ class ImsBaseOrmTest(base.BaseOrmTest):
def _get_image_params(cls, set_region=True, single_tenant=True,
set_private=True, set_enabled=True):
region, post_body = {}, {}
post_body["id"] = uuid.uuid4().hex
post_body["name"] = data_utils.rand_name(
"orm-plugin-TestTempestIms-image")

View File

@ -233,16 +233,15 @@ class TestTempestIms(ims_base.ImsBaseOrmTest):
@decorators.idempotent_id('0331e02a-ab52-4341-b676-a02462244277')
def test_create_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'
_, body = self.client.create_image(**post_body)
image = body["image"]
test_image_id = image["id"]
self._wait_for_image_status_on_dcp(test_image_id, 'Success')
# do not forget to add this account to tempest cleanup
self.addCleanup(
self._del_img_validate_deletion_on_dcp_and_lcp,
test_image_id)
# verify image record created successfully
_, body = self.client.get_image(test_image_id)
image = body["image"]
@ -254,9 +253,6 @@ class TestTempestIms(ims_base.ImsBaseOrmTest):
post_body = self._get_image_params(set_region=False)
image = self._data_setup(post_body)
test_image_id = image['id']
self.addCleanup(
self._del_img_validate_deletion_on_dcp_and_lcp,
test_image_id)
# setup region and change 'enabled', 'customers' properties
region["name"] = self.region_id
@ -466,22 +462,23 @@ class TestTempestIms(ims_base.ImsBaseOrmTest):
self.assertEqual(image["regions"][0]["id"], post_body['id'])
@decorators.idempotent_id('ae1223b5-cb75-442b-82eb-488969acc978')
def test_create_flavor_with_region_group(self):
def test_create_image_with_region_group(self):
post_body = self._get_image_params()
# region group
region_group = {"name": "NCLargetest", "type": "group"}
# update region_group to regions
post_body["regions"].append(region_group)
# add image to tempest cleanup
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"]
test_image_id = image["id"]
self._wait_for_image_status_on_dcp(test_image_id, 'Success')
# add image to tempest cleanup
self.addCleanup(
self._del_img_validate_deletion_on_dcp_and_lcp,
test_image_id)
# verify image record created successfully
_, body = self.client.get_image(test_image_id)
image = body["image"]