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 | |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 21 | from oslo_log import log as logging |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 22 | from tempest.api.image import base |
PranaliD | 491d63e | 2020-08-18 13:29:21 +0000 | [diff] [blame] | 23 | from tempest.common import waiters |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 24 | from tempest import config |
Ken'ichi Ohmichi | cc01c3e | 2017-03-10 10:48:14 -0800 | [diff] [blame] | 25 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 26 | from tempest.lib import decorators |
lkuchlan | 32b53c3 | 2017-04-20 16:51:08 +0300 | [diff] [blame] | 27 | from tempest.lib import exceptions as lib_exc |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 28 | |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 29 | CONF = config.CONF |
| 30 | LOG = logging.getLogger(__name__) |
| 31 | |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 32 | |
Abhishek Kekane | 7cff130 | 2020-07-16 10:30:13 +0000 | [diff] [blame] | 33 | class ImportImagesTest(base.BaseV2ImageTest): |
| 34 | """Here we test the import operations for image""" |
| 35 | |
| 36 | @classmethod |
| 37 | def skip_checks(cls): |
| 38 | super(ImportImagesTest, cls).skip_checks() |
| 39 | if not CONF.image_feature_enabled.import_image: |
| 40 | skip_msg = ( |
| 41 | "%s skipped as image import is not available" % cls.__name__) |
| 42 | raise cls.skipException(skip_msg) |
| 43 | |
Ghanshyam Mann | 1425ecd | 2020-07-22 21:01:26 -0500 | [diff] [blame] | 44 | @classmethod |
| 45 | def resource_setup(cls): |
| 46 | super(ImportImagesTest, cls).resource_setup() |
| 47 | cls.available_import_methods = cls.client.info_import()[ |
| 48 | 'import-methods']['value'] |
| 49 | if not cls.available_import_methods: |
| 50 | raise cls.skipException('Server does not support ' |
| 51 | 'any import method') |
Abhishek Kekane | 7cff130 | 2020-07-16 10:30:13 +0000 | [diff] [blame] | 52 | |
Ghanshyam Mann | 1425ecd | 2020-07-22 21:01:26 -0500 | [diff] [blame] | 53 | def _create_image(self): |
Abhishek Kekane | 7cff130 | 2020-07-16 10:30:13 +0000 | [diff] [blame] | 54 | # Create image |
| 55 | uuid = '00000000-1111-2222-3333-444455556666' |
| 56 | image_name = data_utils.rand_name('image') |
| 57 | container_format = CONF.image.container_formats[0] |
| 58 | disk_format = CONF.image.disk_formats[0] |
| 59 | image = self.create_image(name=image_name, |
| 60 | container_format=container_format, |
| 61 | disk_format=disk_format, |
| 62 | visibility='private', |
| 63 | ramdisk_id=uuid) |
| 64 | self.assertIn('name', image) |
| 65 | self.assertEqual(image_name, image['name']) |
| 66 | self.assertIn('visibility', image) |
| 67 | self.assertEqual('private', image['visibility']) |
| 68 | self.assertIn('status', image) |
| 69 | self.assertEqual('queued', image['status']) |
Ghanshyam Mann | 1425ecd | 2020-07-22 21:01:26 -0500 | [diff] [blame] | 70 | return image |
Abhishek Kekane | 7cff130 | 2020-07-16 10:30:13 +0000 | [diff] [blame] | 71 | |
Ghanshyam Mann | 1425ecd | 2020-07-22 21:01:26 -0500 | [diff] [blame] | 72 | @decorators.idempotent_id('32ca0c20-e16f-44ac-8590-07869c9b4cc2') |
| 73 | def test_image_glance_direct_import(self): |
| 74 | """Test 'glance-direct' import functionalities |
| 75 | |
| 76 | Create image, stage image data, import image and verify |
| 77 | that import succeeded. |
| 78 | """ |
| 79 | if 'glance-direct' not in self.available_import_methods: |
| 80 | raise self.skipException('Server does not support ' |
| 81 | 'glance-direct import method') |
| 82 | image = self._create_image() |
Abhishek Kekane | 7cff130 | 2020-07-16 10:30:13 +0000 | [diff] [blame] | 83 | # Stage image data |
| 84 | file_content = data_utils.random_bytes() |
| 85 | image_file = six.BytesIO(file_content) |
| 86 | self.client.stage_image_file(image['id'], image_file) |
Ghanshyam Mann | 1425ecd | 2020-07-22 21:01:26 -0500 | [diff] [blame] | 87 | # Check image status is 'uploading' |
| 88 | body = self.client.show_image(image['id']) |
| 89 | self.assertEqual(image['id'], body['id']) |
| 90 | self.assertEqual('uploading', body['status']) |
| 91 | # import image from staging to backend |
| 92 | self.client.image_import(image['id'], method='glance-direct') |
| 93 | self.client.wait_for_resource_activation(image['id']) |
Abhishek Kekane | 7cff130 | 2020-07-16 10:30:13 +0000 | [diff] [blame] | 94 | |
Ghanshyam Mann | 1425ecd | 2020-07-22 21:01:26 -0500 | [diff] [blame] | 95 | @decorators.idempotent_id('f6feb7a4-b04f-4706-a011-206129f83e62') |
| 96 | def test_image_web_download_import(self): |
| 97 | """Test 'web-download' import functionalities |
| 98 | |
| 99 | Create image, import image and verify that import |
| 100 | succeeded. |
| 101 | """ |
| 102 | if 'web-download' not in self.available_import_methods: |
| 103 | raise self.skipException('Server does not support ' |
| 104 | 'web-download import method') |
| 105 | image = self._create_image() |
Abhishek Kekane | 7cff130 | 2020-07-16 10:30:13 +0000 | [diff] [blame] | 106 | # Now try to get image details |
| 107 | body = self.client.show_image(image['id']) |
| 108 | self.assertEqual(image['id'], body['id']) |
Ghanshyam Mann | 1425ecd | 2020-07-22 21:01:26 -0500 | [diff] [blame] | 109 | self.assertEqual('queued', body['status']) |
| 110 | # import image from web to backend |
| 111 | image_uri = CONF.image.http_image |
| 112 | self.client.image_import(image['id'], method='web-download', |
| 113 | image_uri=image_uri) |
Abhishek Kekane | 7cff130 | 2020-07-16 10:30:13 +0000 | [diff] [blame] | 114 | self.client.wait_for_resource_activation(image['id']) |
| 115 | |
| 116 | |
PranaliD | 491d63e | 2020-08-18 13:29:21 +0000 | [diff] [blame] | 117 | class MultiStoresImportImagesTest(base.BaseV2ImageTest): |
| 118 | """Test importing image in multiple stores""" |
| 119 | @classmethod |
| 120 | def skip_checks(cls): |
| 121 | super(MultiStoresImportImagesTest, cls).skip_checks() |
| 122 | if not CONF.image_feature_enabled.import_image: |
| 123 | skip_msg = ( |
| 124 | "%s skipped as image import is not available" % cls.__name__) |
| 125 | raise cls.skipException(skip_msg) |
| 126 | |
| 127 | @classmethod |
| 128 | def resource_setup(cls): |
| 129 | super(MultiStoresImportImagesTest, cls).resource_setup() |
| 130 | cls.available_import_methods = cls.client.info_import()[ |
| 131 | 'import-methods']['value'] |
| 132 | if not cls.available_import_methods: |
| 133 | raise cls.skipException('Server does not support ' |
| 134 | 'any import method') |
| 135 | |
| 136 | # NOTE(pdeore): Skip if glance-direct import method and mutlistore |
| 137 | # are not enabled/configured, or only one store is configured in |
| 138 | # multiple stores setup. |
| 139 | cls.available_stores = cls.get_available_stores() |
| 140 | if ('glance-direct' not in cls.available_import_methods or |
| 141 | not len(cls.available_stores) > 1): |
| 142 | raise cls.skipException( |
| 143 | 'Either glance-direct import method not present in %s or ' |
| 144 | 'None or only one store is ' |
| 145 | 'configured %s' % (cls.available_import_methods, |
| 146 | cls.available_stores)) |
| 147 | |
| 148 | def _create_and_stage_image(self, all_stores=False): |
| 149 | """Create Image & stage image file for glance-direct import method.""" |
| 150 | image_name = data_utils.rand_name('test-image') |
| 151 | container_format = CONF.image.container_formats[0] |
| 152 | disk_format = CONF.image.disk_formats[0] |
| 153 | image = self.create_image(name=image_name, |
| 154 | container_format=container_format, |
| 155 | disk_format=disk_format, |
| 156 | visibility='private') |
| 157 | self.assertEqual('queued', image['status']) |
| 158 | |
| 159 | self.client.stage_image_file( |
| 160 | image['id'], |
Dan Smith | 8dfefce | 2021-01-14 12:15:45 -0800 | [diff] [blame] | 161 | six.BytesIO(data_utils.random_bytes())) |
PranaliD | 491d63e | 2020-08-18 13:29:21 +0000 | [diff] [blame] | 162 | # Check image status is 'uploading' |
| 163 | body = self.client.show_image(image['id']) |
| 164 | self.assertEqual(image['id'], body['id']) |
| 165 | self.assertEqual('uploading', body['status']) |
| 166 | |
| 167 | if all_stores: |
| 168 | stores_list = ','.join([store['id'] |
| 169 | for store in self.available_stores]) |
| 170 | else: |
| 171 | stores = [store['id'] for store in self.available_stores] |
| 172 | stores_list = stores[::len(stores) - 1] |
| 173 | |
| 174 | return body, stores_list |
| 175 | |
| 176 | @decorators.idempotent_id('bf04ff00-3182-47cb-833a-f1c6767b47fd') |
| 177 | def test_glance_direct_import_image_to_all_stores(self): |
| 178 | """Test image is imported in all available stores |
| 179 | |
| 180 | Create image, import image to all available stores using glance-direct |
| 181 | import method and verify that import succeeded. |
| 182 | """ |
| 183 | image, stores = self._create_and_stage_image(all_stores=True) |
| 184 | |
| 185 | self.client.image_import( |
| 186 | image['id'], method='glance-direct', all_stores=True) |
| 187 | |
| 188 | waiters.wait_for_image_imported_to_stores(self.client, |
| 189 | image['id'], stores) |
| 190 | |
| 191 | @decorators.idempotent_id('82fb131a-dd2b-11ea-aec7-340286b6c574') |
| 192 | def test_glance_direct_import_image_to_specific_stores(self): |
| 193 | """Test image is imported in all available stores |
| 194 | |
| 195 | Create image, import image to specified store(s) using glance-direct |
| 196 | import method and verify that import succeeded. |
| 197 | """ |
| 198 | image, stores = self._create_and_stage_image() |
| 199 | self.client.image_import(image['id'], method='glance-direct', |
| 200 | stores=stores) |
| 201 | |
| 202 | waiters.wait_for_image_imported_to_stores(self.client, image['id'], |
| 203 | (','.join(stores))) |
| 204 | |
| 205 | |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 206 | class BasicOperationsImagesTest(base.BaseV2ImageTest): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 207 | """Here we test the basic operations of images""" |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 208 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 209 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 210 | @decorators.idempotent_id('139b765e-7f3d-4b3d-8b37-3ca3876ee318') |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 211 | def test_register_upload_get_image_file(self): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 212 | """Here we test these functionalities |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 213 | |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 214 | Register image, upload the image file, get image and get image |
| 215 | file api's |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 216 | """ |
| 217 | |
Sean Dague | c6ec476 | 2014-05-29 08:54:21 -0400 | [diff] [blame] | 218 | uuid = '00000000-1111-2222-3333-444455556666' |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 219 | image_name = data_utils.rand_name('image') |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 220 | container_format = CONF.image.container_formats[0] |
| 221 | disk_format = CONF.image.disk_formats[0] |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 222 | image = self.create_image(name=image_name, |
| 223 | container_format=container_format, |
| 224 | disk_format=disk_format, |
| 225 | visibility='private', |
| 226 | ramdisk_id=uuid) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 227 | self.assertIn('name', image) |
| 228 | self.assertEqual(image_name, image['name']) |
| 229 | self.assertIn('visibility', image) |
| 230 | self.assertEqual('private', image['visibility']) |
| 231 | self.assertIn('status', image) |
| 232 | self.assertEqual('queued', image['status']) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 233 | |
wangxiyuan | 99e4dcf | 2019-09-17 09:51:55 +0800 | [diff] [blame] | 234 | # NOTE: This Glance API returns different status codes for image |
| 235 | # condition. In this empty data case, Glance should return 204, |
| 236 | # so here should check the status code. |
| 237 | image_file = self.client.show_image_file(image['id']) |
| 238 | self.assertEqual(0, len(image_file.data)) |
| 239 | self.assertEqual(204, image_file.response.status) |
| 240 | |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 241 | # Now try uploading an image file |
Mark Washenberger | 5c3b6fe | 2014-07-29 13:40:34 -0700 | [diff] [blame] | 242 | file_content = data_utils.random_bytes() |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 243 | image_file = six.BytesIO(file_content) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 244 | self.client.store_image_file(image['id'], image_file) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 245 | |
| 246 | # Now try to get image details |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 247 | body = self.client.show_image(image['id']) |
| 248 | self.assertEqual(image['id'], body['id']) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 249 | self.assertEqual(image_name, body['name']) |
Sean Dague | c6ec476 | 2014-05-29 08:54:21 -0400 | [diff] [blame] | 250 | self.assertEqual(uuid, body['ramdisk_id']) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 251 | self.assertIn('size', body) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 252 | self.assertEqual(1024, body.get('size')) |
| 253 | |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 254 | # Now try get image file |
Ken'ichi Ohmichi | 3b79f17 | 2018-03-20 11:31:44 -0700 | [diff] [blame] | 255 | # NOTE: This Glance API returns different status codes for image |
| 256 | # condition. In this non-empty data case, Glance should return 200, |
| 257 | # so here should check the status code. |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 258 | body = self.client.show_image_file(image['id']) |
David Kranz | d7e97b4 | 2015-02-16 09:37:31 -0500 | [diff] [blame] | 259 | self.assertEqual(file_content, body.data) |
Ken'ichi Ohmichi | 3b79f17 | 2018-03-20 11:31:44 -0700 | [diff] [blame] | 260 | self.assertEqual(200, body.response.status) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 261 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 262 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 263 | @decorators.idempotent_id('f848bb94-1c6e-45a4-8726-39e3a5b23535') |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 264 | def test_delete_image(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 265 | """Test deleting an image by image_id""" |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 266 | # Create image |
| 267 | image_name = data_utils.rand_name('image') |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 268 | container_format = CONF.image.container_formats[0] |
| 269 | disk_format = CONF.image.disk_formats[0] |
Benny Kopilov | 900fceb | 2016-11-09 09:45:40 +0200 | [diff] [blame] | 270 | image = self.create_image(name=image_name, |
| 271 | container_format=container_format, |
| 272 | disk_format=disk_format, |
| 273 | visibility='private') |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 274 | # Delete Image |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 275 | self.client.delete_image(image['id']) |
| 276 | self.client.wait_for_resource_deletion(image['id']) |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 277 | |
| 278 | # Verifying deletion |
John Warren | f3b3e95 | 2015-08-17 19:28:12 +0000 | [diff] [blame] | 279 | images = self.client.list_images()['images'] |
Sunil G | 29856a3 | 2014-07-17 23:17:58 +0530 | [diff] [blame] | 280 | images_id = [item['id'] for item in images] |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 281 | self.assertNotIn(image['id'], images_id) |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 282 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 283 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 284 | @decorators.idempotent_id('f66891a7-a35c-41a8-b590-a065c2a1caa6') |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 285 | def test_update_image(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 286 | """Test updating an image by image_id""" |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 287 | # Create image |
| 288 | image_name = data_utils.rand_name('image') |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 289 | container_format = CONF.image.container_formats[0] |
| 290 | disk_format = CONF.image.disk_formats[0] |
Benny Kopilov | 900fceb | 2016-11-09 09:45:40 +0200 | [diff] [blame] | 291 | image = self.create_image(name=image_name, |
| 292 | container_format=container_format, |
| 293 | disk_format=disk_format, |
| 294 | visibility='private') |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 295 | self.assertEqual('queued', image['status']) |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 296 | |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 297 | # Update Image |
| 298 | new_image_name = data_utils.rand_name('new-image') |
zhufl | 311104e | 2017-08-17 15:13:18 +0800 | [diff] [blame] | 299 | self.client.update_image(image['id'], [ |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame] | 300 | dict(replace='/name', value=new_image_name)]) |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 301 | |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 302 | # Verifying updating |
| 303 | |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 304 | body = self.client.show_image(image['id']) |
| 305 | self.assertEqual(image['id'], body['id']) |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 306 | self.assertEqual(new_image_name, body['name']) |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 307 | |
lkuchlan | 32b53c3 | 2017-04-20 16:51:08 +0300 | [diff] [blame] | 308 | @decorators.idempotent_id('951ebe01-969f-4ea9-9898-8a3f1f442ab0') |
| 309 | def test_deactivate_reactivate_image(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 310 | """Test deactivating and reactivating an image""" |
lkuchlan | 32b53c3 | 2017-04-20 16:51:08 +0300 | [diff] [blame] | 311 | # Create image |
| 312 | image_name = data_utils.rand_name('image') |
| 313 | image = self.create_image(name=image_name, |
| 314 | container_format='bare', |
| 315 | disk_format='raw', |
| 316 | visibility='private') |
| 317 | |
| 318 | # Upload an image file |
| 319 | content = data_utils.random_bytes() |
| 320 | image_file = six.BytesIO(content) |
| 321 | self.client.store_image_file(image['id'], image_file) |
| 322 | |
| 323 | # Deactivate image |
| 324 | self.client.deactivate_image(image['id']) |
| 325 | body = self.client.show_image(image['id']) |
| 326 | self.assertEqual("deactivated", body['status']) |
| 327 | |
| 328 | # User unable to download deactivated image |
| 329 | self.assertRaises(lib_exc.Forbidden, self.client.show_image_file, |
| 330 | image['id']) |
| 331 | |
| 332 | # Reactivate image |
| 333 | self.client.reactivate_image(image['id']) |
| 334 | body = self.client.show_image(image['id']) |
| 335 | self.assertEqual("active", body['status']) |
| 336 | |
| 337 | # User able to download image after reactivation |
| 338 | body = self.client.show_image_file(image['id']) |
| 339 | self.assertEqual(content, body.data) |
| 340 | |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 341 | |
zhufl | 6e042bc | 2017-01-25 10:33:40 +0800 | [diff] [blame] | 342 | class ListUserImagesTest(base.BaseV2ImageTest): |
| 343 | """Here we test the listing of image information""" |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 344 | |
| 345 | @classmethod |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 346 | def resource_setup(cls): |
zhufl | 6e042bc | 2017-01-25 10:33:40 +0800 | [diff] [blame] | 347 | super(ListUserImagesTest, cls).resource_setup() |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 348 | # We add a few images here to test the listing functionality of |
| 349 | # the images API |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 350 | container_fmts = CONF.image.container_formats |
| 351 | disk_fmts = CONF.image.disk_formats |
| 352 | all_pairs = [(container_fmt, disk_fmt) |
| 353 | for container_fmt in container_fmts |
| 354 | for disk_fmt in disk_fmts] |
| 355 | |
| 356 | for (container_fmt, disk_fmt) in all_pairs[:6]: |
Sergey Vilgelm | 36fdd20 | 2018-11-20 16:10:47 -0600 | [diff] [blame] | 357 | LOG.debug("Creating an image " |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 358 | "(Container format: %s, Disk format: %s).", |
| 359 | container_fmt, disk_fmt) |
| 360 | cls._create_standard_image(container_fmt, disk_fmt) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 361 | |
| 362 | @classmethod |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 363 | def _create_standard_image(cls, container_format, disk_format): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 364 | """Create a new standard image and return the newly-registered image-id |
| 365 | |
| 366 | 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] | 367 | 1024 and 4096 |
| 368 | """ |
Mark Washenberger | 5c3b6fe | 2014-07-29 13:40:34 -0700 | [diff] [blame] | 369 | size = random.randint(1024, 4096) |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 370 | image_file = six.BytesIO(data_utils.random_bytes(size)) |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 371 | tags = [data_utils.rand_name('tag'), data_utils.rand_name('tag')] |
zhufl | 08e4276 | 2016-10-18 16:07:56 +0800 | [diff] [blame] | 372 | image = cls.create_image(container_format=container_format, |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 373 | disk_format=disk_format, |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 374 | visibility='private', |
| 375 | tags=tags) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 376 | cls.client.store_image_file(image['id'], data=image_file) |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 377 | # Keep the data of one test image so it can be used to filter lists |
| 378 | cls.test_data = image |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 379 | |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 380 | return image['id'] |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 381 | |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 382 | def _list_by_param_value_and_assert(self, params): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 383 | """Perform list action with given params and validates result.""" |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 384 | # Retrieve the list of images that meet the filter |
John Warren | f3b3e95 | 2015-08-17 19:28:12 +0000 | [diff] [blame] | 385 | images_list = self.client.list_images(params=params)['images'] |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 386 | # Validating params of fetched images |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 387 | msg = 'No images were found that met the filter criteria.' |
| 388 | self.assertNotEmpty(images_list, msg) |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 389 | for image in images_list: |
| 390 | for key in params: |
| 391 | msg = "Failed to list images by %s" % key |
| 392 | self.assertEqual(params[key], image[key], msg) |
| 393 | |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 394 | def _list_sorted_by_image_size_and_assert(self, params, desc=False): |
| 395 | """Validate an image list that has been sorted by size |
| 396 | |
| 397 | Perform list action with given params and validates the results are |
| 398 | sorted by image size in either ascending or descending order. |
| 399 | """ |
| 400 | # Retrieve the list of images that meet the filter |
| 401 | images_list = self.client.list_images(params=params)['images'] |
| 402 | # Validate that the list was fetched sorted accordingly |
| 403 | msg = 'No images were found that met the filter criteria.' |
| 404 | self.assertNotEmpty(images_list, msg) |
zhufl | 940a9e2 | 2020-11-25 15:36:13 +0800 | [diff] [blame] | 405 | sorted_list = [image['size'] for image in images_list |
| 406 | if image['size'] is not None] |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 407 | msg = 'The list of images was not sorted correctly.' |
| 408 | self.assertEqual(sorted(sorted_list, reverse=desc), sorted_list, msg) |
| 409 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 410 | @decorators.idempotent_id('1e341d7a-90a9-494c-b143-2cdf2aeb6aee') |
Flavio Percoco | 7e26be1 | 2015-09-15 22:33:19 +0200 | [diff] [blame] | 411 | def test_list_no_params(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 412 | """Simple test to see all fixture images returned""" |
John Warren | f3b3e95 | 2015-08-17 19:28:12 +0000 | [diff] [blame] | 413 | images_list = self.client.list_images()['images'] |
Sirushti Murugesan | 935f2cc | 2016-07-12 19:48:24 +0530 | [diff] [blame] | 414 | image_list = [image['id'] for image in images_list] |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 415 | |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 416 | for image in self.created_images: |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 417 | self.assertIn(image, image_list) |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 418 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 419 | @decorators.idempotent_id('9959ca1d-1aa7-4b7a-a1ea-0fff0499b37e') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 420 | def test_list_images_param_container_format(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 421 | """Test to get all images with a specific container_format""" |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 422 | params = {"container_format": self.test_data['container_format']} |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 423 | self._list_by_param_value_and_assert(params) |
| 424 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 425 | @decorators.idempotent_id('4a4735a7-f22f-49b6-b0d9-66e1ef7453eb') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 426 | def test_list_images_param_disk_format(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 427 | """Test to get all images with disk_format = raw""" |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 428 | params = {"disk_format": "raw"} |
| 429 | self._list_by_param_value_and_assert(params) |
| 430 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 431 | @decorators.idempotent_id('7a95bb92-d99e-4b12-9718-7bc6ab73e6d2') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 432 | def test_list_images_param_visibility(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 433 | """Test to get all images with visibility = private""" |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame] | 434 | params = {"visibility": "private"} |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 435 | self._list_by_param_value_and_assert(params) |
| 436 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 437 | @decorators.idempotent_id('cf1b9a48-8340-480e-af7b-fe7e17690876') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 438 | def test_list_images_param_size(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 439 | """Test to get all images by size""" |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 440 | image_id = self.created_images[0] |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 441 | # Get image metadata |
Ken'ichi Ohmichi | 5d41076 | 2015-05-22 01:10:03 +0000 | [diff] [blame] | 442 | image = self.client.show_image(image_id) |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 443 | |
| 444 | params = {"size": image['size']} |
| 445 | self._list_by_param_value_and_assert(params) |
| 446 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 447 | @decorators.idempotent_id('4ad8c157-971a-4ba8-aa84-ed61154b1e7f') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 448 | def test_list_images_param_min_max_size(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 449 | """Test to get all images with min size and max size""" |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 450 | image_id = self.created_images[0] |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 451 | # Get image metadata |
Ken'ichi Ohmichi | 5d41076 | 2015-05-22 01:10:03 +0000 | [diff] [blame] | 452 | image = self.client.show_image(image_id) |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 453 | |
| 454 | size = image['size'] |
| 455 | params = {"size_min": size - 500, "size_max": size + 500} |
John Warren | f3b3e95 | 2015-08-17 19:28:12 +0000 | [diff] [blame] | 456 | images_list = self.client.list_images(params=params)['images'] |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 457 | image_size_list = map(lambda x: x['size'], images_list) |
| 458 | |
| 459 | for image_size in image_size_list: |
Béla Vancsics | 64862f7 | 2016-11-08 09:12:31 +0100 | [diff] [blame] | 460 | self.assertGreaterEqual(image_size, params['size_min'], |
| 461 | "Failed to get images by size_min") |
| 462 | self.assertLessEqual(image_size, params['size_max'], |
| 463 | "Failed to get images by size_max") |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 464 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 465 | @decorators.idempotent_id('7fc9e369-0f58-4d05-9aa5-0969e2d59d15') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 466 | def test_list_images_param_status(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 467 | """Test to get all active images""" |
Anju Tiwari | ca2249d | 2014-01-23 17:33:02 +0530 | [diff] [blame] | 468 | params = {"status": "active"} |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 469 | self._list_by_param_value_and_assert(params) |
| 470 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 471 | @decorators.idempotent_id('e914a891-3cc8-4b40-ad32-e0a39ffbddbb') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 472 | def test_list_images_param_limit(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 473 | """Test to get images by limit""" |
Takashi NATSUME | 12a4851 | 2015-08-10 18:33:16 +0900 | [diff] [blame] | 474 | params = {"limit": 1} |
John Warren | f3b3e95 | 2015-08-17 19:28:12 +0000 | [diff] [blame] | 475 | images_list = self.client.list_images(params=params)['images'] |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 476 | |
| 477 | self.assertEqual(len(images_list), params['limit'], |
| 478 | "Failed to get images by limit") |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 479 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 480 | @decorators.idempotent_id('e9a44b91-31c8-4b40-a332-e0a39ffb4dbb') |
Li Wei | 14bf241 | 2016-09-25 15:56:23 +0800 | [diff] [blame] | 481 | def test_list_image_param_owner(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 482 | """Test to get images by owner""" |
Li Wei | 14bf241 | 2016-09-25 15:56:23 +0800 | [diff] [blame] | 483 | image_id = self.created_images[0] |
| 484 | # Get image metadata |
| 485 | image = self.client.show_image(image_id) |
| 486 | |
| 487 | params = {"owner": image['owner']} |
| 488 | self._list_by_param_value_and_assert(params) |
| 489 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 490 | @decorators.idempotent_id('55c8f5f5-bfed-409d-a6d5-4caeda985d7b') |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 491 | def test_list_images_param_name(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 492 | """Test to get images by name""" |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 493 | params = {'name': self.test_data['name']} |
| 494 | self._list_by_param_value_and_assert(params) |
| 495 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 496 | @decorators.idempotent_id('aa8ac4df-cff9-418b-8d0f-dd9c67b072c9') |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 497 | def test_list_images_param_tag(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 498 | """Test to get images matching a tag""" |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 499 | params = {'tag': self.test_data['tags'][0]} |
| 500 | images_list = self.client.list_images(params=params)['images'] |
| 501 | # Validating properties of fetched images |
| 502 | self.assertNotEmpty(images_list) |
| 503 | for image in images_list: |
| 504 | msg = ("The image {image_name} does not have the expected tag " |
| 505 | "{expected_tag} among its tags: {observerd_tags}." |
| 506 | .format(image_name=image['name'], |
| 507 | expected_tag=self.test_data['tags'][0], |
| 508 | observerd_tags=image['tags'])) |
| 509 | self.assertIn(self.test_data['tags'][0], image['tags'], msg) |
| 510 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 511 | @decorators.idempotent_id('eeadce49-04e0-43b7-aec7-52535d903e7a') |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 512 | def test_list_images_param_sort(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 513 | """Test listing images sorting in descending order""" |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 514 | params = {'sort': 'size:desc'} |
| 515 | self._list_sorted_by_image_size_and_assert(params, desc=True) |
| 516 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 517 | @decorators.idempotent_id('9faaa0c2-c3a5-43e1-8f61-61c54b409a49') |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 518 | def test_list_images_param_sort_key_dir(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 519 | """Test listing images sorting by size in descending order""" |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 520 | params = {'sort_key': 'size', 'sort_dir': 'desc'} |
| 521 | self._list_sorted_by_image_size_and_assert(params, desc=True) |
| 522 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 523 | @decorators.idempotent_id('622b925c-479f-4736-860d-adeaf13bc371') |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 524 | def test_get_image_schema(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 525 | """Test to get image schema""" |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 526 | schema = "image" |
Ken'ichi Ohmichi | 190b24e | 2016-06-07 23:20:09 +0900 | [diff] [blame] | 527 | body = self.schemas_client.show_schema(schema) |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 528 | self.assertEqual("image", body['name']) |
| 529 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 530 | @decorators.idempotent_id('25c8d7b2-df21-460f-87ac-93130bcdc684') |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 531 | def test_get_images_schema(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 532 | """Test to get images schema""" |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 533 | schema = "images" |
Ken'ichi Ohmichi | 190b24e | 2016-06-07 23:20:09 +0900 | [diff] [blame] | 534 | body = self.schemas_client.show_schema(schema) |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 535 | self.assertEqual("images", body['name']) |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 536 | |
| 537 | |
zhufl | 6e042bc | 2017-01-25 10:33:40 +0800 | [diff] [blame] | 538 | class ListSharedImagesTest(base.BaseV2ImageTest): |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 539 | """Here we test the listing of a shared image information""" |
| 540 | |
| 541 | credentials = ['primary', 'alt'] |
| 542 | |
| 543 | @classmethod |
| 544 | def setup_clients(cls): |
| 545 | super(ListSharedImagesTest, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 546 | cls.image_member_client = cls.os_primary.image_member_client_v2 |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 547 | cls.alt_img_client = cls.os_alt.image_client_v2 |
| 548 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 549 | @decorators.idempotent_id('3fa50be4-8e38-4c02-a8db-7811bb780122') |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 550 | def test_list_images_param_member_status(self): |
zhufl | e68f435 | 2020-04-21 13:44:55 +0800 | [diff] [blame] | 551 | """Test listing images by member_status and visibility""" |
Steve Lewis | 8ac5b97 | 2016-12-22 07:41:29 -0800 | [diff] [blame] | 552 | # Create an image to be shared using default visibility |
| 553 | image_file = six.BytesIO(data_utils.random_bytes(2048)) |
| 554 | container_format = CONF.image.container_formats[0] |
| 555 | disk_format = CONF.image.disk_formats[0] |
| 556 | image = self.create_image(container_format=container_format, |
| 557 | disk_format=disk_format) |
| 558 | self.client.store_image_file(image['id'], data=image_file) |
| 559 | |
| 560 | # Share the image created with the alt user |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 561 | self.image_member_client.create_image_member( |
Steve Lewis | 8ac5b97 | 2016-12-22 07:41:29 -0800 | [diff] [blame] | 562 | image_id=image['id'], member=self.alt_img_client.tenant_id) |
| 563 | |
Castulo J. Martinez | e9c8ce8 | 2016-05-16 07:55:53 -0700 | [diff] [blame] | 564 | # As an image consumer you need to provide the member_status parameter |
| 565 | # along with the visibility=shared parameter in order for it to show |
| 566 | # results |
| 567 | params = {'member_status': 'pending', 'visibility': 'shared'} |
| 568 | fetched_images = self.alt_img_client.list_images(params)['images'] |
| 569 | self.assertEqual(1, len(fetched_images)) |
Steve Lewis | 8ac5b97 | 2016-12-22 07:41:29 -0800 | [diff] [blame] | 570 | self.assertEqual(image['id'], fetched_images[0]['id']) |