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