Full response from v2 ImageClient methods
Provide the entire response object for all methods of the
v2 ImageClient. The equivalent change for the v1 ImageClient
(change 208045) included the temporary addition of a class method
that was to be removed when the equivalent changes were made to
the v2 client. However, it turns out that for the method in
question the v2 client was already returning the full response
object which can be used as-is. The additional class method
was therefore removed and a better change was made instead.
partially implements: blueprint method-return-value-and-move-service-clients-to-lib
Change-Id: I98c6a1685e4f3549faf1b567c6c6b193b6d644a2
diff --git a/tempest/api/image/base.py b/tempest/api/image/base.py
index 4572310..da0ce83 100644
--- a/tempest/api/image/base.py
+++ b/tempest/api/image/base.py
@@ -72,6 +72,10 @@
image = cls.client.create_image(name, container_format,
disk_format, **kwargs)
+ # Image objects returned by the v1 client have the image
+ # data inside a dict that is keyed against 'image'.
+ if 'image' in image:
+ image = image['image']
cls.created_images.append(image['id'])
return image
@@ -90,26 +94,6 @@
super(BaseV1ImageTest, cls).setup_clients()
cls.client = cls.os.image_client
- # TODO(jswarren) Remove this method once the v2 client also returns the
- # full response object, not just the ['image'] value. At that
- # point BaseImageTest.create_image will need to retrieve the
- # ['image'] value.
- @classmethod
- def create_image(cls, **kwargs):
- """Wrapper that returns a test image."""
- name = data_utils.rand_name(cls.__name__ + "-instance")
-
- if 'name' in kwargs:
- name = kwargs.pop('name')
-
- container_format = kwargs.pop('container_format')
- disk_format = kwargs.pop('disk_format')
-
- image = cls.client.create_image(name, container_format,
- disk_format, **kwargs)['image']
- cls.created_images.append(image['id'])
- return image
-
class BaseV1ImageMembersTest(BaseV1ImageTest):
@@ -166,7 +150,7 @@
cls.alt_tenant_id = cls.alt_img_client.tenant_id
def _list_image_ids_as_alt(self):
- image_list = self.alt_img_client.list_images()
+ image_list = self.alt_img_client.list_images()['images']
image_ids = map(lambda x: x['id'], image_list)
return image_ids
diff --git a/tempest/api/image/v2/test_images.py b/tempest/api/image/v2/test_images.py
index 20e9bca..b446ec3 100644
--- a/tempest/api/image/v2/test_images.py
+++ b/tempest/api/image/v2/test_images.py
@@ -88,7 +88,7 @@
self.client.wait_for_resource_deletion(image_id)
# Verifying deletion
- images = self.client.list_images()
+ images = self.client.list_images()['images']
images_id = [item['id'] for item in images]
self.assertNotIn(image_id, images_id)
@@ -164,7 +164,7 @@
"""
Perform list action with given params and validates result.
"""
- images_list = self.client.list_images(params=params)
+ images_list = self.client.list_images(params=params)['images']
# Validating params of fetched images
for image in images_list:
for key in params:
@@ -174,7 +174,7 @@
@test.idempotent_id('1e341d7a-90a9-494c-b143-2cdf2aeb6aee')
def test_index_no_params(self):
# Simple test to see all fixture images returned
- images_list = self.client.list_images()
+ images_list = self.client.list_images()['images']
image_list = map(lambda x: x['id'], images_list)
for image in self.created_images:
@@ -217,7 +217,7 @@
size = image['size']
params = {"size_min": size - 500, "size_max": size + 500}
- images_list = self.client.list_images(params=params)
+ images_list = self.client.list_images(params=params)['images']
image_size_list = map(lambda x: x['size'], images_list)
for image_size in image_size_list:
@@ -235,7 +235,7 @@
def test_list_images_param_limit(self):
# Test to get images by limit
params = {"limit": 2}
- images_list = self.client.list_images(params=params)
+ images_list = self.client.list_images(params=params)['images']
self.assertEqual(len(images_list), params['limit'],
"Failed to get images by limit")
diff --git a/tempest/services/image/v2/json/image_client.py b/tempest/services/image/v2/json/image_client.py
index 67f7708..c5aa41a 100644
--- a/tempest/services/image/v2/json/image_client.py
+++ b/tempest/services/image/v2/json/image_client.py
@@ -123,7 +123,7 @@
self.expected_success(200, resp.status)
body = json.loads(body)
self._validate_schema(body, type='images')
- return service_client.ResponseBodyList(resp, body['images'])
+ return service_client.ResponseBody(resp, body)
def show_image(self, image_id):
url = 'v2/images/%s' % image_id