ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 16 | import six |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 17 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.image import base |
Ken'ichi Ohmichi | 01151e8 | 2016-06-10 11:19:52 -0700 | [diff] [blame] | 19 | from tempest.common import image as common_image |
Yaroslav Lobankov | 2fea405 | 2016-04-19 15:05:57 +0300 | [diff] [blame] | 20 | from tempest.common import waiters |
Matthew Treinish | bc0e03e | 2014-01-30 16:51:06 +0000 | [diff] [blame] | 21 | from tempest import config |
Ken'ichi Ohmichi | cc01c3e | 2017-03-10 10:48:14 -0800 | [diff] [blame] | 22 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 23 | from tempest.lib import decorators |
Matthew Treinish | 4217a70 | 2016-10-07 17:27:11 -0400 | [diff] [blame] | 24 | from tempest.lib import exceptions |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 25 | |
Matthew Treinish | bc0e03e | 2014-01-30 16:51:06 +0000 | [diff] [blame] | 26 | CONF = config.CONF |
| 27 | |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 28 | |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 29 | def get_container_and_disk_format(): |
| 30 | a_formats = ['ami', 'ari', 'aki'] |
| 31 | |
| 32 | container_format = CONF.image.container_formats[0] |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 33 | |
zhufl | 5aba18f | 2016-12-27 11:39:31 +0800 | [diff] [blame] | 34 | # In v1, If container_format is one of ['ami', 'ari', 'aki'], then |
| 35 | # disk_format must be same with container_format. |
| 36 | # If they are of different item sequence in tempest.conf, such as: |
| 37 | # container_formats = ami,ari,aki,bare |
| 38 | # disk_formats = ari,ami,aki,vhd |
| 39 | # we can select one in disk_format list that is same with container_format. |
| 40 | if container_format in a_formats: |
| 41 | if container_format in CONF.image.disk_formats: |
| 42 | disk_format = container_format |
| 43 | else: |
| 44 | msg = ("The container format and the disk format don't match. " |
| 45 | "Container format: %(container)s, Disk format: %(disk)s." % |
lkuchlan | ead5bf6 | 2017-05-23 16:05:45 +0300 | [diff] [blame] | 46 | {'container': container_format, 'disk': |
| 47 | CONF.image.disk_formats}) |
zhufl | 5aba18f | 2016-12-27 11:39:31 +0800 | [diff] [blame] | 48 | raise exceptions.InvalidConfiguration(msg) |
| 49 | else: |
| 50 | disk_format = CONF.image.disk_formats[0] |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 51 | |
| 52 | return container_format, disk_format |
| 53 | |
| 54 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 55 | class CreateRegisterImagesTest(base.BaseV1ImageTest): |
| 56 | """Here we test the registration and creation of images.""" |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 57 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 58 | @decorators.idempotent_id('3027f8e6-3492-4a11-8575-c3293017af4d') |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 59 | def test_register_then_upload(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 60 | # Register, then upload an image |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 61 | properties = {'prop1': 'val1'} |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 62 | container_format, disk_format = get_container_and_disk_format() |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 63 | image = self.create_image(name='New Name', |
| 64 | container_format=container_format, |
| 65 | disk_format=disk_format, |
| 66 | is_public=False, |
| 67 | properties=properties) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 68 | self.assertEqual('New Name', image.get('name')) |
| 69 | self.assertFalse(image.get('is_public')) |
| 70 | self.assertEqual('queued', image.get('status')) |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 71 | for key, val in properties.items(): |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 72 | self.assertEqual(val, image.get('properties')[key]) |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 73 | |
| 74 | # Now try uploading an image file |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 75 | image_file = six.BytesIO(data_utils.random_bytes()) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 76 | body = self.client.update_image(image['id'], data=image_file)['image'] |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 77 | self.assertIn('size', body) |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 78 | self.assertEqual(1024, body.get('size')) |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 79 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 80 | @decorators.idempotent_id('69da74d9-68a9-404b-9664-ff7164ccb0f5') |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 81 | def test_register_remote_image(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 82 | # Register a new remote image |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 83 | container_format, disk_format = get_container_and_disk_format() |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 84 | body = self.create_image(name='New Remote Image', |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 85 | container_format=container_format, |
| 86 | disk_format=disk_format, is_public=False, |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 87 | location=CONF.image.http_image, |
| 88 | properties={'key1': 'value1', |
| 89 | 'key2': 'value2'}) |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 90 | self.assertEqual('New Remote Image', body.get('name')) |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame] | 91 | self.assertFalse(body.get('is_public')) |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 92 | self.assertEqual('active', body.get('status')) |
afazekas | 4a96bf8 | 2013-03-25 16:07:38 +0100 | [diff] [blame] | 93 | properties = body.get('properties') |
| 94 | self.assertEqual(properties['key1'], 'value1') |
| 95 | self.assertEqual(properties['key2'], 'value2') |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 96 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 97 | @decorators.idempotent_id('6d0e13a7-515b-460c-b91f-9f4793f09816') |
Attila Fazekas | e72b7cd | 2013-03-26 18:34:21 +0100 | [diff] [blame] | 98 | def test_register_http_image(self): |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 99 | container_format, disk_format = get_container_and_disk_format() |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 100 | image = self.create_image(name='New Http Image', |
| 101 | container_format=container_format, |
| 102 | disk_format=disk_format, is_public=False, |
| 103 | copy_from=CONF.image.http_image) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 104 | self.assertEqual('New Http Image', image.get('name')) |
| 105 | self.assertFalse(image.get('is_public')) |
| 106 | waiters.wait_for_image_status(self.client, image['id'], 'active') |
| 107 | self.client.show_image(image['id']) |
Attila Fazekas | e72b7cd | 2013-03-26 18:34:21 +0100 | [diff] [blame] | 108 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 109 | @decorators.idempotent_id('05b19d55-140c-40d0-b36b-fafd774d421b') |
hi2suresh | 75a2030 | 2013-04-09 09:17:06 +0000 | [diff] [blame] | 110 | def test_register_image_with_min_ram(self): |
| 111 | # Register an image with min ram |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 112 | container_format, disk_format = get_container_and_disk_format() |
hi2suresh | 75a2030 | 2013-04-09 09:17:06 +0000 | [diff] [blame] | 113 | properties = {'prop1': 'val1'} |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 114 | body = self.create_image(name='New_image_with_min_ram', |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 115 | container_format=container_format, |
| 116 | disk_format=disk_format, |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 117 | is_public=False, |
| 118 | min_ram=40, |
| 119 | properties=properties) |
hi2suresh | 75a2030 | 2013-04-09 09:17:06 +0000 | [diff] [blame] | 120 | self.assertEqual('New_image_with_min_ram', body.get('name')) |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame] | 121 | self.assertFalse(body.get('is_public')) |
hi2suresh | 75a2030 | 2013-04-09 09:17:06 +0000 | [diff] [blame] | 122 | self.assertEqual('queued', body.get('status')) |
| 123 | self.assertEqual(40, body.get('min_ram')) |
| 124 | for key, val in properties.items(): |
| 125 | self.assertEqual(val, body.get('properties')[key]) |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 126 | self.client.delete_image(body['id']) |
hi2suresh | 75a2030 | 2013-04-09 09:17:06 +0000 | [diff] [blame] | 127 | |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 128 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 129 | class ListImagesTest(base.BaseV1ImageTest): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 130 | """Here we test the listing of image information""" |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 131 | |
| 132 | @classmethod |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 133 | def skip_checks(cls): |
| 134 | super(ListImagesTest, cls).skip_checks() |
Federico Ressi | 2d6bcaa | 2018-04-11 12:37:36 +0200 | [diff] [blame] | 135 | if (len(CONF.image.container_formats) < 2 or |
| 136 | len(CONF.image.disk_formats) < 2): |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 137 | skip_msg = ("%s skipped as multiple container formats " |
| 138 | "or disk formats are not available." % cls.__name__) |
| 139 | raise cls.skipException(skip_msg) |
| 140 | |
| 141 | @classmethod |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 142 | def resource_setup(cls): |
| 143 | super(ListImagesTest, cls).resource_setup() |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 144 | # We add a few images here to test the listing functionality of |
| 145 | # the images API |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 146 | a_formats = ['ami', 'ari', 'aki'] |
| 147 | |
| 148 | (cls.container_format, |
zhufl | 7a8f29d | 2017-02-17 10:16:45 +0800 | [diff] [blame] | 149 | container_format_alt) = CONF.image.container_formats[:2] |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 150 | cls.disk_format, cls.disk_format_alt = CONF.image.disk_formats[:2] |
| 151 | if cls.container_format in a_formats: |
| 152 | cls.disk_format = cls.container_format |
zhufl | 7a8f29d | 2017-02-17 10:16:45 +0800 | [diff] [blame] | 153 | if container_format_alt in a_formats: |
| 154 | cls.disk_format_alt = container_format_alt |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 155 | |
| 156 | img1 = cls._create_remote_image('one', cls.container_format, |
| 157 | cls.disk_format) |
zhufl | 7a8f29d | 2017-02-17 10:16:45 +0800 | [diff] [blame] | 158 | img2 = cls._create_remote_image('two', container_format_alt, |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 159 | cls.disk_format_alt) |
| 160 | img3 = cls._create_remote_image('dup', cls.container_format, |
| 161 | cls.disk_format) |
| 162 | img4 = cls._create_remote_image('dup', cls.container_format, |
| 163 | cls.disk_format) |
zhufl | 7a8f29d | 2017-02-17 10:16:45 +0800 | [diff] [blame] | 164 | img5 = cls._create_standard_image('1', container_format_alt, |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 165 | cls.disk_format_alt, 42) |
zhufl | 7a8f29d | 2017-02-17 10:16:45 +0800 | [diff] [blame] | 166 | img6 = cls._create_standard_image('2', container_format_alt, |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 167 | cls.disk_format_alt, 142) |
| 168 | img7 = cls._create_standard_image('33', cls.container_format, |
| 169 | cls.disk_format, 142) |
| 170 | img8 = cls._create_standard_image('33', cls.container_format, |
| 171 | cls.disk_format, 142) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 172 | cls.created_set = set(cls.created_images) |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 173 | # same container format |
| 174 | cls.same_container_format_set = set((img1, img3, img4, img7, img8)) |
| 175 | # same disk format |
| 176 | cls.same_disk_format_set = set((img2, img5, img6)) |
| 177 | |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 178 | # 1x with size 42 |
| 179 | cls.size42_set = set((img5,)) |
| 180 | # 3x with size 142 |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 181 | cls.size142_set = set((img6, img7, img8,)) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 182 | # dup named |
| 183 | cls.dup_set = set((img3, img4)) |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 184 | |
| 185 | @classmethod |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 186 | def _create_remote_image(cls, name, container_format, disk_format): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 187 | """Create a new remote image and return newly-registered image-id""" |
| 188 | |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 189 | name = 'New Remote Image %s' % name |
Matthew Treinish | e81ae69 | 2014-06-19 17:41:31 -0400 | [diff] [blame] | 190 | location = CONF.image.http_image |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 191 | image = cls.create_image(name=name, |
| 192 | container_format=container_format, |
| 193 | disk_format=disk_format, |
| 194 | is_public=False, |
| 195 | location=location) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 196 | return image['id'] |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 197 | |
| 198 | @classmethod |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 199 | def _create_standard_image(cls, name, container_format, |
| 200 | disk_format, size): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 201 | """Create a new standard image and return newly-registered image-id |
| 202 | |
| 203 | Note that the size of the new image is a random number between |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 204 | 1024 and 4096 |
| 205 | """ |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 206 | image_file = six.BytesIO(data_utils.random_bytes(size)) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 207 | name = 'New Standard Image %s' % name |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 208 | image = cls.create_image(name=name, |
| 209 | container_format=container_format, |
| 210 | disk_format=disk_format, |
| 211 | is_public=False, data=image_file) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 212 | return image['id'] |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 213 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 214 | @decorators.idempotent_id('246178ab-3b33-4212-9a4b-a7fe8261794d') |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 215 | def test_index_no_params(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 216 | # Simple test to see all fixture images returned |
John Warren | 6620725 | 2015-07-31 15:51:02 -0400 | [diff] [blame] | 217 | images_list = self.client.list_images()['images'] |
Sirushti Murugesan | 935f2cc | 2016-07-12 19:48:24 +0530 | [diff] [blame] | 218 | image_list = [image['id'] for image in images_list] |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 219 | for image_id in self.created_images: |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 220 | self.assertIn(image_id, image_list) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 221 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 222 | @decorators.idempotent_id('f1755589-63d6-4468-b098-589820eb4031') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 223 | def test_index_disk_format(self): |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 224 | images_list = self.client.list_images( |
| 225 | disk_format=self.disk_format_alt)['images'] |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 226 | for image in images_list: |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 227 | self.assertEqual(image['disk_format'], self.disk_format_alt) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 228 | result_set = set(map(lambda x: x['id'], images_list)) |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 229 | self.assertTrue(self.same_disk_format_set <= result_set) |
Federico Ressi | 2d6bcaa | 2018-04-11 12:37:36 +0200 | [diff] [blame] | 230 | self.assertFalse(self.created_set - self.same_disk_format_set <= |
| 231 | result_set) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 232 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 233 | @decorators.idempotent_id('2143655d-96d9-4bec-9188-8674206b4b3b') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 234 | def test_index_container_format(self): |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 235 | images_list = self.client.list_images( |
| 236 | container_format=self.container_format)['images'] |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 237 | for image in images_list: |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 238 | self.assertEqual(image['container_format'], self.container_format) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 239 | result_set = set(map(lambda x: x['id'], images_list)) |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 240 | self.assertTrue(self.same_container_format_set <= result_set) |
Federico Ressi | 2d6bcaa | 2018-04-11 12:37:36 +0200 | [diff] [blame] | 241 | self.assertFalse(self.created_set - self.same_container_format_set <= |
| 242 | result_set) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 243 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 244 | @decorators.idempotent_id('feb32ac6-22bb-4a16-afd8-9454bb714b14') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 245 | def test_index_max_size(self): |
John Warren | 6620725 | 2015-07-31 15:51:02 -0400 | [diff] [blame] | 246 | images_list = self.client.list_images(size_max=42)['images'] |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 247 | for image in images_list: |
Béla Vancsics | 64862f7 | 2016-11-08 09:12:31 +0100 | [diff] [blame] | 248 | self.assertLessEqual(image['size'], 42) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 249 | result_set = set(map(lambda x: x['id'], images_list)) |
| 250 | self.assertTrue(self.size42_set <= result_set) |
| 251 | self.assertFalse(self.created_set - self.size42_set <= result_set) |
| 252 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 253 | @decorators.idempotent_id('6ffc16d0-4cbf-4401-95c8-4ac63eac34d8') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 254 | def test_index_min_size(self): |
John Warren | 6620725 | 2015-07-31 15:51:02 -0400 | [diff] [blame] | 255 | images_list = self.client.list_images(size_min=142)['images'] |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 256 | for image in images_list: |
zhufl | 080dcfb | 2016-10-21 17:45:38 +0800 | [diff] [blame] | 257 | self.assertGreaterEqual(image['size'], 142) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 258 | result_set = set(map(lambda x: x['id'], images_list)) |
| 259 | self.assertTrue(self.size142_set <= result_set) |
| 260 | self.assertFalse(self.size42_set <= result_set) |
| 261 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 262 | @decorators.idempotent_id('e5dc26d9-9aa2-48dd-bda5-748e1445da98') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 263 | def test_index_status_active_detail(self): |
Ken'ichi Ohmichi | bcad2a2 | 2015-05-22 09:37:06 +0000 | [diff] [blame] | 264 | images_list = self.client.list_images(detail=True, |
| 265 | status='active', |
| 266 | sort_key='size', |
John Warren | 6620725 | 2015-07-31 15:51:02 -0400 | [diff] [blame] | 267 | sort_dir='desc')['images'] |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 268 | top_size = images_list[0]['size'] # We have non-zero sized images |
| 269 | for image in images_list: |
| 270 | size = image['size'] |
Béla Vancsics | 64862f7 | 2016-11-08 09:12:31 +0100 | [diff] [blame] | 271 | self.assertLessEqual(size, top_size) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 272 | top_size = size |
| 273 | self.assertEqual(image['status'], 'active') |
| 274 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 275 | @decorators.idempotent_id('097af10a-bae8-4342-bff4-edf89969ed2a') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 276 | def test_index_name(self): |
Ken'ichi Ohmichi | bcad2a2 | 2015-05-22 09:37:06 +0000 | [diff] [blame] | 277 | images_list = self.client.list_images( |
| 278 | detail=True, |
John Warren | 6620725 | 2015-07-31 15:51:02 -0400 | [diff] [blame] | 279 | name='New Remote Image dup')['images'] |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 280 | result_set = set(map(lambda x: x['id'], images_list)) |
| 281 | for image in images_list: |
| 282 | self.assertEqual(image['name'], 'New Remote Image dup') |
| 283 | self.assertTrue(self.dup_set <= result_set) |
| 284 | self.assertFalse(self.created_set - self.dup_set <= result_set) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 285 | |
| 286 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 287 | class UpdateImageMetaTest(base.BaseV1ImageTest): |
| 288 | @classmethod |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 289 | def resource_setup(cls): |
| 290 | super(UpdateImageMetaTest, cls).resource_setup() |
Takashi NATSUME | b7d8591 | 2015-11-10 13:24:48 +0900 | [diff] [blame] | 291 | container_format, disk_format = get_container_and_disk_format() |
| 292 | cls.image_id = cls._create_standard_image('1', container_format, |
| 293 | disk_format, 42) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 294 | |
| 295 | @classmethod |
| 296 | def _create_standard_image(cls, name, container_format, |
| 297 | disk_format, size): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 298 | """Create a new standard image and return newly-registered image-id""" |
| 299 | |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 300 | image_file = six.BytesIO(data_utils.random_bytes(size)) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 301 | name = 'New Standard Image %s' % name |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 302 | image = cls.create_image(name=name, |
| 303 | container_format=container_format, |
| 304 | disk_format=disk_format, |
| 305 | is_public=False, data=image_file, |
| 306 | properties={'key1': 'value1'}) |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 307 | return image['id'] |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 308 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 309 | @decorators.idempotent_id('01752c1c-0275-4de3-9e5b-876e44541928') |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 310 | def test_list_image_metadata(self): |
| 311 | # All metadata key/value pairs for an image should be returned |
Ken'ichi Ohmichi | 01151e8 | 2016-06-10 11:19:52 -0700 | [diff] [blame] | 312 | resp = self.client.check_image(self.image_id) |
| 313 | resp_metadata = common_image.get_image_meta_from_headers(resp) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 314 | expected = {'key1': 'value1'} |
| 315 | self.assertEqual(expected, resp_metadata['properties']) |
| 316 | |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 317 | @decorators.idempotent_id('d6d7649c-08ce-440d-9ea7-e3dda552f33c') |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 318 | def test_update_image_metadata(self): |
| 319 | # The metadata for the image should match the updated values |
| 320 | req_metadata = {'key1': 'alt1', 'key2': 'value2'} |
Ken'ichi Ohmichi | 01151e8 | 2016-06-10 11:19:52 -0700 | [diff] [blame] | 321 | resp = self.client.check_image(self.image_id) |
| 322 | metadata = common_image.get_image_meta_from_headers(resp) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 323 | self.assertEqual(metadata['properties'], {'key1': 'value1'}) |
| 324 | metadata['properties'].update(req_metadata) |
Ken'ichi Ohmichi | 02bcdf3 | 2016-06-17 16:41:26 -0700 | [diff] [blame] | 325 | headers = common_image.image_meta_to_headers( |
| 326 | properties=metadata['properties']) |
guo yunxian | 6c5f5eb | 2016-08-23 15:35:53 +0800 | [diff] [blame] | 327 | self.client.update_image(self.image_id, headers=headers) |
Ken'ichi Ohmichi | 01151e8 | 2016-06-10 11:19:52 -0700 | [diff] [blame] | 328 | resp = self.client.check_image(self.image_id) |
| 329 | resp_metadata = common_image.get_image_meta_from_headers(resp) |
guo yunxian | 6c5f5eb | 2016-08-23 15:35:53 +0800 | [diff] [blame] | 330 | self.assertEqual(req_metadata, resp_metadata['properties']) |