ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2013 OpenStack Foundation |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 2 | # Copyright 2013 IBM Corp |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 3 | # All Rights Reserved. |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 17 | import random |
| 18 | |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 19 | import six |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 20 | |
lkuchlan | 32b53c3 | 2017-04-20 16:51:08 +0300 | [diff] [blame] | 21 | import testtools |
| 22 | |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 23 | from oslo_log import log as logging |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 24 | from tempest.api.image import base |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 25 | from tempest import config |
Ken'ichi Ohmichi | cc01c3e | 2017-03-10 10:48:14 -0800 | [diff] [blame] | 26 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 27 | from tempest.lib import decorators |
lkuchlan | 32b53c3 | 2017-04-20 16:51:08 +0300 | [diff] [blame] | 28 | from tempest.lib import exceptions as lib_exc |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 29 | |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 30 | CONF = config.CONF |
| 31 | LOG = logging.getLogger(__name__) |
| 32 | |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 33 | |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 34 | class BasicOperationsImagesTest(base.BaseV2ImageTest): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 35 | """Here we test the basic operations of images""" |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 36 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 37 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 38 | @decorators.idempotent_id('139b765e-7f3d-4b3d-8b37-3ca3876ee318') |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 39 | def test_register_upload_get_image_file(self): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 40 | """Here we test these functionalities |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 41 | |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 42 | Register image, upload the image file, get image and get image |
| 43 | file api's |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 44 | """ |
| 45 | |
Sean Dague | c6ec476 | 2014-05-29 08:54:21 -0400 | [diff] [blame] | 46 | uuid = '00000000-1111-2222-3333-444455556666' |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 47 | image_name = data_utils.rand_name('image') |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 48 | container_format = CONF.image.container_formats[0] |
| 49 | disk_format = CONF.image.disk_formats[0] |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 50 | image = self.create_image(name=image_name, |
| 51 | container_format=container_format, |
| 52 | disk_format=disk_format, |
| 53 | visibility='private', |
| 54 | ramdisk_id=uuid) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 55 | self.assertIn('name', image) |
| 56 | self.assertEqual(image_name, image['name']) |
| 57 | self.assertIn('visibility', image) |
| 58 | self.assertEqual('private', image['visibility']) |
| 59 | self.assertIn('status', image) |
| 60 | self.assertEqual('queued', image['status']) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 61 | |
| 62 | # Now try uploading an image file |
Mark Washenberger | 5c3b6fe | 2014-07-29 13:40:34 -0700 | [diff] [blame] | 63 | file_content = data_utils.random_bytes() |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 64 | image_file = six.BytesIO(file_content) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 65 | self.client.store_image_file(image['id'], image_file) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 66 | |
| 67 | # Now try to get image details |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 68 | body = self.client.show_image(image['id']) |
| 69 | self.assertEqual(image['id'], body['id']) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 70 | self.assertEqual(image_name, body['name']) |
Sean Dague | c6ec476 | 2014-05-29 08:54:21 -0400 | [diff] [blame] | 71 | self.assertEqual(uuid, body['ramdisk_id']) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 72 | self.assertIn('size', body) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 73 | self.assertEqual(1024, body.get('size')) |
| 74 | |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 75 | # Now try get image file |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 76 | body = self.client.show_image_file(image['id']) |
David Kranz | d7e97b4 | 2015-02-16 09:37:31 -0500 | [diff] [blame] | 77 | self.assertEqual(file_content, body.data) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 78 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 79 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 80 | @decorators.idempotent_id('f848bb94-1c6e-45a4-8726-39e3a5b23535') |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 81 | def test_delete_image(self): |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 82 | # Deletes an image by image_id |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 83 | |
| 84 | # Create image |
| 85 | image_name = data_utils.rand_name('image') |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 86 | container_format = CONF.image.container_formats[0] |
| 87 | disk_format = CONF.image.disk_formats[0] |
Benny Kopilov | 900fceb | 2016-11-09 09:45:40 +0200 | [diff] [blame] | 88 | image = self.create_image(name=image_name, |
| 89 | container_format=container_format, |
| 90 | disk_format=disk_format, |
| 91 | visibility='private') |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 92 | # Delete Image |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 93 | self.client.delete_image(image['id']) |
| 94 | self.client.wait_for_resource_deletion(image['id']) |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 95 | |
| 96 | # Verifying deletion |
John Warren | f3b3e95 | 2015-08-17 19:28:12 +0000 | [diff] [blame] | 97 | images = self.client.list_images()['images'] |
Sunil G | 29856a3 | 2014-07-17 23:17:58 +0530 | [diff] [blame] | 98 | images_id = [item['id'] for item in images] |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 99 | self.assertNotIn(image['id'], images_id) |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 100 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 101 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 102 | @decorators.idempotent_id('f66891a7-a35c-41a8-b590-a065c2a1caa6') |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 103 | def test_update_image(self): |
| 104 | # Updates an image by image_id |
| 105 | |
| 106 | # Create image |
| 107 | image_name = data_utils.rand_name('image') |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 108 | container_format = CONF.image.container_formats[0] |
| 109 | disk_format = CONF.image.disk_formats[0] |
Benny Kopilov | 900fceb | 2016-11-09 09:45:40 +0200 | [diff] [blame] | 110 | image = self.create_image(name=image_name, |
| 111 | container_format=container_format, |
| 112 | disk_format=disk_format, |
| 113 | visibility='private') |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 114 | self.assertEqual('queued', image['status']) |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 115 | |
| 116 | # Now try uploading an image file |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 117 | image_file = six.BytesIO(data_utils.random_bytes()) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 118 | self.client.store_image_file(image['id'], image_file) |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 119 | |
| 120 | # Update Image |
| 121 | new_image_name = data_utils.rand_name('new-image') |
zhufl | 311104e | 2017-08-17 15:13:18 +0800 | [diff] [blame] | 122 | self.client.update_image(image['id'], [ |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame] | 123 | dict(replace='/name', value=new_image_name)]) |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 124 | |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 125 | # Verifying updating |
| 126 | |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 127 | body = self.client.show_image(image['id']) |
| 128 | self.assertEqual(image['id'], body['id']) |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 129 | self.assertEqual(new_image_name, body['name']) |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 130 | |
lkuchlan | 32b53c3 | 2017-04-20 16:51:08 +0300 | [diff] [blame] | 131 | @testtools.skipUnless(CONF.image_feature_enabled.deactivate_image, |
| 132 | 'deactivate-image is not available.') |
| 133 | @decorators.idempotent_id('951ebe01-969f-4ea9-9898-8a3f1f442ab0') |
| 134 | def test_deactivate_reactivate_image(self): |
| 135 | # Create image |
| 136 | image_name = data_utils.rand_name('image') |
| 137 | image = self.create_image(name=image_name, |
| 138 | container_format='bare', |
| 139 | disk_format='raw', |
| 140 | visibility='private') |
| 141 | |
| 142 | # Upload an image file |
| 143 | content = data_utils.random_bytes() |
| 144 | image_file = six.BytesIO(content) |
| 145 | self.client.store_image_file(image['id'], image_file) |
| 146 | |
| 147 | # Deactivate image |
| 148 | self.client.deactivate_image(image['id']) |
| 149 | body = self.client.show_image(image['id']) |
| 150 | self.assertEqual("deactivated", body['status']) |
| 151 | |
| 152 | # User unable to download deactivated image |
| 153 | self.assertRaises(lib_exc.Forbidden, self.client.show_image_file, |
| 154 | image['id']) |
| 155 | |
| 156 | # Reactivate image |
| 157 | self.client.reactivate_image(image['id']) |
| 158 | body = self.client.show_image(image['id']) |
| 159 | self.assertEqual("active", body['status']) |
| 160 | |
| 161 | # User able to download image after reactivation |
| 162 | body = self.client.show_image_file(image['id']) |
| 163 | self.assertEqual(content, body.data) |
| 164 | |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 165 | |
zhufl | 6e042bc | 2017-01-25 10:33:40 +0800 | [diff] [blame] | 166 | class ListUserImagesTest(base.BaseV2ImageTest): |
| 167 | """Here we test the listing of image information""" |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 168 | |
| 169 | @classmethod |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 170 | def resource_setup(cls): |
zhufl | 6e042bc | 2017-01-25 10:33:40 +0800 | [diff] [blame] | 171 | super(ListUserImagesTest, cls).resource_setup() |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 172 | # We add a few images here to test the listing functionality of |
| 173 | # the images API |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 174 | container_fmts = CONF.image.container_formats |
| 175 | disk_fmts = CONF.image.disk_formats |
| 176 | all_pairs = [(container_fmt, disk_fmt) |
| 177 | for container_fmt in container_fmts |
| 178 | for disk_fmt in disk_fmts] |
| 179 | |
| 180 | for (container_fmt, disk_fmt) in all_pairs[:6]: |
hgangwx | f186edc | 2015-12-28 21:12:59 +0800 | [diff] [blame] | 181 | LOG.debug("Creating an image" |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 182 | "(Container format: %s, Disk format: %s).", |
| 183 | container_fmt, disk_fmt) |
| 184 | cls._create_standard_image(container_fmt, disk_fmt) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 185 | |
| 186 | @classmethod |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 187 | def _create_standard_image(cls, container_format, disk_format): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 188 | """Create a new standard image and return the newly-registered image-id |
| 189 | |
| 190 | Note that the size of the new image is a random number between |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 191 | 1024 and 4096 |
| 192 | """ |
Mark Washenberger | 5c3b6fe | 2014-07-29 13:40:34 -0700 | [diff] [blame] | 193 | size = random.randint(1024, 4096) |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 194 | image_file = six.BytesIO(data_utils.random_bytes(size)) |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 195 | tags = [data_utils.rand_name('tag'), data_utils.rand_name('tag')] |
zhufl | 08e4276 | 2016-10-18 16:07:56 +0800 | [diff] [blame] | 196 | image = cls.create_image(container_format=container_format, |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 197 | disk_format=disk_format, |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 198 | visibility='private', |
| 199 | tags=tags) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 200 | cls.client.store_image_file(image['id'], data=image_file) |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 201 | # Keep the data of one test image so it can be used to filter lists |
| 202 | cls.test_data = image |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 203 | |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 204 | return image['id'] |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 205 | |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 206 | def _list_by_param_value_and_assert(self, params): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 207 | """Perform list action with given params and validates result.""" |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 208 | # Retrieve the list of images that meet the filter |
John Warren | f3b3e95 | 2015-08-17 19:28:12 +0000 | [diff] [blame] | 209 | images_list = self.client.list_images(params=params)['images'] |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 210 | # Validating params of fetched images |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 211 | msg = 'No images were found that met the filter criteria.' |
| 212 | self.assertNotEmpty(images_list, msg) |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 213 | for image in images_list: |
| 214 | for key in params: |
| 215 | msg = "Failed to list images by %s" % key |
| 216 | self.assertEqual(params[key], image[key], msg) |
| 217 | |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 218 | def _list_sorted_by_image_size_and_assert(self, params, desc=False): |
| 219 | """Validate an image list that has been sorted by size |
| 220 | |
| 221 | Perform list action with given params and validates the results are |
| 222 | sorted by image size in either ascending or descending order. |
| 223 | """ |
| 224 | # Retrieve the list of images that meet the filter |
| 225 | images_list = self.client.list_images(params=params)['images'] |
| 226 | # Validate that the list was fetched sorted accordingly |
| 227 | msg = 'No images were found that met the filter criteria.' |
| 228 | self.assertNotEmpty(images_list, msg) |
| 229 | sorted_list = [image['size'] for image in images_list] |
| 230 | msg = 'The list of images was not sorted correctly.' |
| 231 | self.assertEqual(sorted(sorted_list, reverse=desc), sorted_list, msg) |
| 232 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 233 | @decorators.idempotent_id('1e341d7a-90a9-494c-b143-2cdf2aeb6aee') |
Flavio Percoco | 7e26be1 | 2015-09-15 22:33:19 +0200 | [diff] [blame] | 234 | def test_list_no_params(self): |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 235 | # Simple test to see all fixture images returned |
John Warren | f3b3e95 | 2015-08-17 19:28:12 +0000 | [diff] [blame] | 236 | images_list = self.client.list_images()['images'] |
Sirushti Murugesan | 935f2cc | 2016-07-12 19:48:24 +0530 | [diff] [blame] | 237 | image_list = [image['id'] for image in images_list] |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 238 | |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 239 | for image in self.created_images: |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 240 | self.assertIn(image, image_list) |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 241 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 242 | @decorators.idempotent_id('9959ca1d-1aa7-4b7a-a1ea-0fff0499b37e') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 243 | def test_list_images_param_container_format(self): |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 244 | # Test to get all images with a specific container_format |
| 245 | params = {"container_format": self.test_data['container_format']} |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 246 | self._list_by_param_value_and_assert(params) |
| 247 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 248 | @decorators.idempotent_id('4a4735a7-f22f-49b6-b0d9-66e1ef7453eb') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 249 | def test_list_images_param_disk_format(self): |
| 250 | # Test to get all images with disk_format = raw |
| 251 | params = {"disk_format": "raw"} |
| 252 | self._list_by_param_value_and_assert(params) |
| 253 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 254 | @decorators.idempotent_id('7a95bb92-d99e-4b12-9718-7bc6ab73e6d2') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 255 | def test_list_images_param_visibility(self): |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame] | 256 | # Test to get all images with visibility = private |
| 257 | params = {"visibility": "private"} |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 258 | self._list_by_param_value_and_assert(params) |
| 259 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 260 | @decorators.idempotent_id('cf1b9a48-8340-480e-af7b-fe7e17690876') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 261 | def test_list_images_param_size(self): |
| 262 | # Test to get all images by size |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 263 | image_id = self.created_images[0] |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 264 | # Get image metadata |
Ken'ichi Ohmichi | 5d41076 | 2015-05-22 01:10:03 +0000 | [diff] [blame] | 265 | image = self.client.show_image(image_id) |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 266 | |
| 267 | params = {"size": image['size']} |
| 268 | self._list_by_param_value_and_assert(params) |
| 269 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 270 | @decorators.idempotent_id('4ad8c157-971a-4ba8-aa84-ed61154b1e7f') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 271 | def test_list_images_param_min_max_size(self): |
| 272 | # Test to get all images with size between 2000 to 3000 |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 273 | image_id = self.created_images[0] |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 274 | # Get image metadata |
Ken'ichi Ohmichi | 5d41076 | 2015-05-22 01:10:03 +0000 | [diff] [blame] | 275 | image = self.client.show_image(image_id) |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 276 | |
| 277 | size = image['size'] |
| 278 | params = {"size_min": size - 500, "size_max": size + 500} |
John Warren | f3b3e95 | 2015-08-17 19:28:12 +0000 | [diff] [blame] | 279 | images_list = self.client.list_images(params=params)['images'] |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 280 | image_size_list = map(lambda x: x['size'], images_list) |
| 281 | |
| 282 | for image_size in image_size_list: |
Béla Vancsics | 64862f7 | 2016-11-08 09:12:31 +0100 | [diff] [blame] | 283 | self.assertGreaterEqual(image_size, params['size_min'], |
| 284 | "Failed to get images by size_min") |
| 285 | self.assertLessEqual(image_size, params['size_max'], |
| 286 | "Failed to get images by size_max") |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 287 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 288 | @decorators.idempotent_id('7fc9e369-0f58-4d05-9aa5-0969e2d59d15') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 289 | def test_list_images_param_status(self): |
Anju Tiwari | ca2249d | 2014-01-23 17:33:02 +0530 | [diff] [blame] | 290 | # Test to get all active images |
| 291 | params = {"status": "active"} |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 292 | self._list_by_param_value_and_assert(params) |
| 293 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 294 | @decorators.idempotent_id('e914a891-3cc8-4b40-ad32-e0a39ffbddbb') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 295 | def test_list_images_param_limit(self): |
| 296 | # Test to get images by limit |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 297 | params = {"limit": 1} |
John Warren | f3b3e95 | 2015-08-17 19:28:12 +0000 | [diff] [blame] | 298 | images_list = self.client.list_images(params=params)['images'] |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 299 | |
| 300 | self.assertEqual(len(images_list), params['limit'], |
| 301 | "Failed to get images by limit") |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 302 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 303 | @decorators.idempotent_id('e9a44b91-31c8-4b40-a332-e0a39ffb4dbb') |
Li Wei | 14bf241 | 2016-09-25 15:56:23 +0800 | [diff] [blame] | 304 | def test_list_image_param_owner(self): |
| 305 | # Test to get images by owner |
| 306 | image_id = self.created_images[0] |
| 307 | # Get image metadata |
| 308 | image = self.client.show_image(image_id) |
| 309 | |
| 310 | params = {"owner": image['owner']} |
| 311 | self._list_by_param_value_and_assert(params) |
| 312 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 313 | @decorators.idempotent_id('55c8f5f5-bfed-409d-a6d5-4caeda985d7b') |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 314 | def test_list_images_param_name(self): |
| 315 | # Test to get images by name |
| 316 | params = {'name': self.test_data['name']} |
| 317 | self._list_by_param_value_and_assert(params) |
| 318 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 319 | @decorators.idempotent_id('aa8ac4df-cff9-418b-8d0f-dd9c67b072c9') |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 320 | def test_list_images_param_tag(self): |
| 321 | # Test to get images matching a tag |
| 322 | params = {'tag': self.test_data['tags'][0]} |
| 323 | images_list = self.client.list_images(params=params)['images'] |
| 324 | # Validating properties of fetched images |
| 325 | self.assertNotEmpty(images_list) |
| 326 | for image in images_list: |
| 327 | msg = ("The image {image_name} does not have the expected tag " |
| 328 | "{expected_tag} among its tags: {observerd_tags}." |
| 329 | .format(image_name=image['name'], |
| 330 | expected_tag=self.test_data['tags'][0], |
| 331 | observerd_tags=image['tags'])) |
| 332 | self.assertIn(self.test_data['tags'][0], image['tags'], msg) |
| 333 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 334 | @decorators.idempotent_id('eeadce49-04e0-43b7-aec7-52535d903e7a') |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 335 | def test_list_images_param_sort(self): |
| 336 | params = {'sort': 'size:desc'} |
| 337 | self._list_sorted_by_image_size_and_assert(params, desc=True) |
| 338 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 339 | @decorators.idempotent_id('9faaa0c2-c3a5-43e1-8f61-61c54b409a49') |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 340 | def test_list_images_param_sort_key_dir(self): |
| 341 | params = {'sort_key': 'size', 'sort_dir': 'desc'} |
| 342 | self._list_sorted_by_image_size_and_assert(params, desc=True) |
| 343 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 344 | @decorators.idempotent_id('622b925c-479f-4736-860d-adeaf13bc371') |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 345 | def test_get_image_schema(self): |
| 346 | # Test to get image schema |
| 347 | schema = "image" |
Ken'ichi Ohmichi | 190b24e | 2016-06-07 23:20:09 +0900 | [diff] [blame] | 348 | body = self.schemas_client.show_schema(schema) |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 349 | self.assertEqual("image", body['name']) |
| 350 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 351 | @decorators.idempotent_id('25c8d7b2-df21-460f-87ac-93130bcdc684') |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 352 | def test_get_images_schema(self): |
| 353 | # Test to get images schema |
| 354 | schema = "images" |
Ken'ichi Ohmichi | 190b24e | 2016-06-07 23:20:09 +0900 | [diff] [blame] | 355 | body = self.schemas_client.show_schema(schema) |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 356 | self.assertEqual("images", body['name']) |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 357 | |
| 358 | |
zhufl | 6e042bc | 2017-01-25 10:33:40 +0800 | [diff] [blame] | 359 | class ListSharedImagesTest(base.BaseV2ImageTest): |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 360 | """Here we test the listing of a shared image information""" |
| 361 | |
| 362 | credentials = ['primary', 'alt'] |
| 363 | |
| 364 | @classmethod |
| 365 | def setup_clients(cls): |
| 366 | super(ListSharedImagesTest, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 367 | cls.image_member_client = cls.os_primary.image_member_client_v2 |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 368 | cls.alt_img_client = cls.os_alt.image_client_v2 |
| 369 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 370 | @decorators.idempotent_id('3fa50be4-8e38-4c02-a8db-7811bb780122') |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 371 | def test_list_images_param_member_status(self): |
Steve Lewis | 8ac5b97 | 2016-12-22 07:41:29 -0800 | [diff] [blame] | 372 | # Create an image to be shared using default visibility |
| 373 | image_file = six.BytesIO(data_utils.random_bytes(2048)) |
| 374 | container_format = CONF.image.container_formats[0] |
| 375 | disk_format = CONF.image.disk_formats[0] |
| 376 | image = self.create_image(container_format=container_format, |
| 377 | disk_format=disk_format) |
| 378 | self.client.store_image_file(image['id'], data=image_file) |
| 379 | |
| 380 | # Share the image created with the alt user |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 381 | self.image_member_client.create_image_member( |
Steve Lewis | 8ac5b97 | 2016-12-22 07:41:29 -0800 | [diff] [blame] | 382 | image_id=image['id'], member=self.alt_img_client.tenant_id) |
| 383 | |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 384 | # As an image consumer you need to provide the member_status parameter |
| 385 | # along with the visibility=shared parameter in order for it to show |
| 386 | # results |
| 387 | params = {'member_status': 'pending', 'visibility': 'shared'} |
| 388 | fetched_images = self.alt_img_client.list_images(params)['images'] |
| 389 | self.assertEqual(1, len(fetched_images)) |
Steve Lewis | 8ac5b97 | 2016-12-22 07:41:29 -0800 | [diff] [blame] | 390 | self.assertEqual(image['id'], fetched_images[0]['id']) |