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