Add testcases for images
Adds tests for those GET API functions that accept params
Image_list glance API
Partial-Bug: #1086590
Change-Id: I9e2c5df63b066dd79ad8f5467b40bf3d6e252e98
diff --git a/tempest/api/image/v2/test_images.py b/tempest/api/image/v2/test_images.py
index 6408c15..090f31f 100644
--- a/tempest/api/image/v2/test_images.py
+++ b/tempest/api/image/v2/test_images.py
@@ -25,7 +25,6 @@
class BasicOperationsImagesTest(base.BaseV2ImageTest):
-
"""
Here we test the basic operations of images
"""
@@ -95,7 +94,6 @@
class ListImagesTest(base.BaseV2ImageTest):
-
"""
Here we test the listing of image information
"""
@@ -105,31 +103,114 @@
super(ListImagesTest, cls).setUpClass()
# We add a few images here to test the listing functionality of
# the images API
- for x in xrange(0, 10):
- cls._create_standard_image(x)
+ cls._create_standard_image('bare', 'raw')
+ cls._create_standard_image('bare', 'raw')
+ cls._create_standard_image('ami', 'raw')
+ # Add some more for listing
+ cls._create_standard_image('ami', 'ami')
+ cls._create_standard_image('ari', 'ari')
+ cls._create_standard_image('aki', 'aki')
@classmethod
- def _create_standard_image(cls, number):
+ def _create_standard_image(cls, container_format, disk_format):
"""
Create a new standard image and return the ID of the newly-registered
image. Note that the size of the new image is a random number between
1024 and 4096
"""
image_file = StringIO.StringIO('*' * random.randint(1024, 4096))
- name = 'New Standard Image %s' % number
- resp, body = cls.create_image(name=name, container_format='bare',
- disk_format='raw',
+ name = data_utils.rand_name('image-')
+ resp, body = cls.create_image(name=name,
+ container_format=container_format,
+ disk_format=disk_format,
visibility='public')
image_id = body['id']
resp, body = cls.client.store_image(image_id, data=image_file)
return image_id
+ def _list_by_param_value_and_assert(self, params):
+ """
+ Perform list action with given params and validates result.
+ """
+ resp, images_list = self.client.image_list(params=params)
+ self.assertEqual(200, resp.status)
+ # Validating params of fetched images
+ for image in images_list:
+ for key in params:
+ msg = "Failed to list images by %s" % key
+ self.assertEqual(params[key], image[key], msg)
+
@attr(type='gate')
def test_index_no_params(self):
# Simple test to see all fixture images returned
resp, images_list = self.client.image_list()
self.assertEqual(resp['status'], '200')
image_list = map(lambda x: x['id'], images_list)
+
for image in self.created_images:
self.assertIn(image, image_list)
+
+ @attr(type='gate')
+ def test_list_images_param_container_format(self):
+ # Test to get all images with container_format='bare'
+ params = {"container_format": "bare"}
+ self._list_by_param_value_and_assert(params)
+
+ @attr(type='gate')
+ def test_list_images_param_disk_format(self):
+ # Test to get all images with disk_format = raw
+ params = {"disk_format": "raw"}
+ self._list_by_param_value_and_assert(params)
+
+ @attr(type='gate')
+ def test_list_images_param_visibility(self):
+ # Test to get all images with visibility = public
+ params = {"visibility": "public"}
+ self._list_by_param_value_and_assert(params)
+
+ @attr(type='gate')
+ def test_list_images_param_size(self):
+ # Test to get all images by size
+ image_id = self.created_images[1]
+ # Get image metadata
+ resp, image = self.client.get_image(image_id)
+ self.assertEqual(resp['status'], '200')
+
+ params = {"size": image['size']}
+ self._list_by_param_value_and_assert(params)
+
+ @attr(type='gate')
+ def test_list_images_param_min_max_size(self):
+ # Test to get all images with size between 2000 to 3000
+ image_id = self.created_images[1]
+ # Get image metadata
+ resp, image = self.client.get_image(image_id)
+ self.assertEqual(resp['status'], '200')
+
+ size = image['size']
+ params = {"size_min": size - 500, "size_max": size + 500}
+ resp, images_list = self.client.image_list(params=params)
+ self.assertEqual(resp['status'], '200')
+ image_size_list = map(lambda x: x['size'], images_list)
+
+ for image_size in image_size_list:
+ self.assertTrue(image_size >= params['size_min'] and
+ image_size <= params['size_max'],
+ "Failed to get images by size_min and size_max")
+
+ @attr(type='gate')
+ def test_list_images_param_status(self):
+ # Test to get all available images
+ params = {"status": "available"}
+ self._list_by_param_value_and_assert(params)
+
+ @attr(type='gate')
+ def test_list_images_param_limit(self):
+ # Test to get images by limit
+ params = {"limit": 2}
+ resp, images_list = self.client.image_list(params=params)
+ self.assertEqual(resp['status'], '200')
+
+ self.assertEqual(len(images_list), params['limit'],
+ "Failed to get images by limit")