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 | |
| 16 | import cStringIO as StringIO |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 17 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.image import base |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 19 | from tempest.common.utils import data_utils |
Matthew Treinish | bc0e03e | 2014-01-30 16:51:06 +0000 | [diff] [blame] | 20 | from tempest import config |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 21 | from tempest import test |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 22 | |
Matthew Treinish | bc0e03e | 2014-01-30 16:51:06 +0000 | [diff] [blame] | 23 | CONF = config.CONF |
| 24 | |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 25 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 26 | class CreateRegisterImagesTest(base.BaseV1ImageTest): |
| 27 | """Here we test the registration and creation of images.""" |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 28 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 29 | @test.attr(type='gate') |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 30 | def test_register_then_upload(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 31 | # Register, then upload an image |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 32 | properties = {'prop1': 'val1'} |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 33 | _, body = self.create_image(name='New Name', |
| 34 | container_format='bare', |
| 35 | disk_format='raw', |
| 36 | is_public=False, |
| 37 | properties=properties) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 38 | self.assertIn('id', body) |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 39 | image_id = body.get('id') |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 40 | self.assertEqual('New Name', body.get('name')) |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame] | 41 | self.assertFalse(body.get('is_public')) |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 42 | self.assertEqual('queued', body.get('status')) |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 43 | for key, val in properties.items(): |
| 44 | self.assertEqual(val, body.get('properties')[key]) |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 45 | |
| 46 | # Now try uploading an image file |
Mark Washenberger | 5c3b6fe | 2014-07-29 13:40:34 -0700 | [diff] [blame] | 47 | image_file = StringIO.StringIO(data_utils.random_bytes()) |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 48 | _, body = self.client.update_image(image_id, data=image_file) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 49 | self.assertIn('size', body) |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 50 | self.assertEqual(1024, body.get('size')) |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 51 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 52 | @test.attr(type='gate') |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 53 | def test_register_remote_image(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 54 | # Register a new remote image |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 55 | _, body = self.create_image(name='New Remote Image', |
| 56 | container_format='bare', |
| 57 | disk_format='raw', is_public=False, |
| 58 | location=CONF.image.http_image, |
| 59 | properties={'key1': 'value1', |
| 60 | 'key2': 'value2'}) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 61 | self.assertIn('id', body) |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 62 | self.assertEqual('New Remote Image', body.get('name')) |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame] | 63 | self.assertFalse(body.get('is_public')) |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 64 | self.assertEqual('active', body.get('status')) |
afazekas | 4a96bf8 | 2013-03-25 16:07:38 +0100 | [diff] [blame] | 65 | properties = body.get('properties') |
| 66 | self.assertEqual(properties['key1'], 'value1') |
| 67 | self.assertEqual(properties['key2'], 'value2') |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 68 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 69 | @test.attr(type='gate') |
Attila Fazekas | e72b7cd | 2013-03-26 18:34:21 +0100 | [diff] [blame] | 70 | def test_register_http_image(self): |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 71 | _, body = self.create_image(name='New Http Image', |
| 72 | container_format='bare', |
| 73 | disk_format='raw', is_public=False, |
| 74 | copy_from=CONF.image.http_image) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 75 | self.assertIn('id', body) |
Attila Fazekas | e72b7cd | 2013-03-26 18:34:21 +0100 | [diff] [blame] | 76 | image_id = body.get('id') |
Attila Fazekas | e72b7cd | 2013-03-26 18:34:21 +0100 | [diff] [blame] | 77 | self.assertEqual('New Http Image', body.get('name')) |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame] | 78 | self.assertFalse(body.get('is_public')) |
Attila Fazekas | e72b7cd | 2013-03-26 18:34:21 +0100 | [diff] [blame] | 79 | self.client.wait_for_image_status(image_id, 'active') |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 80 | self.client.get_image(image_id) |
Attila Fazekas | e72b7cd | 2013-03-26 18:34:21 +0100 | [diff] [blame] | 81 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 82 | @test.attr(type='gate') |
hi2suresh | 75a2030 | 2013-04-09 09:17:06 +0000 | [diff] [blame] | 83 | def test_register_image_with_min_ram(self): |
| 84 | # Register an image with min ram |
| 85 | properties = {'prop1': 'val1'} |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 86 | _, body = self.create_image(name='New_image_with_min_ram', |
| 87 | container_format='bare', |
| 88 | disk_format='raw', |
| 89 | is_public=False, |
| 90 | min_ram=40, |
| 91 | properties=properties) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 92 | self.assertIn('id', body) |
hi2suresh | 75a2030 | 2013-04-09 09:17:06 +0000 | [diff] [blame] | 93 | self.assertEqual('New_image_with_min_ram', body.get('name')) |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame] | 94 | self.assertFalse(body.get('is_public')) |
hi2suresh | 75a2030 | 2013-04-09 09:17:06 +0000 | [diff] [blame] | 95 | self.assertEqual('queued', body.get('status')) |
| 96 | self.assertEqual(40, body.get('min_ram')) |
| 97 | for key, val in properties.items(): |
| 98 | self.assertEqual(val, body.get('properties')[key]) |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 99 | self.client.delete_image(body['id']) |
hi2suresh | 75a2030 | 2013-04-09 09:17:06 +0000 | [diff] [blame] | 100 | |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 101 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 102 | class ListImagesTest(base.BaseV1ImageTest): |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 103 | |
| 104 | """ |
| 105 | Here we test the listing of image information |
| 106 | """ |
| 107 | |
| 108 | @classmethod |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 109 | def resource_setup(cls): |
| 110 | super(ListImagesTest, cls).resource_setup() |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 111 | # We add a few images here to test the listing functionality of |
| 112 | # the images API |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 113 | img1 = cls._create_remote_image('one', 'bare', 'raw') |
| 114 | img2 = cls._create_remote_image('two', 'ami', 'ami') |
| 115 | img3 = cls._create_remote_image('dup', 'bare', 'raw') |
| 116 | img4 = cls._create_remote_image('dup', 'bare', 'raw') |
| 117 | img5 = cls._create_standard_image('1', 'ami', 'ami', 42) |
| 118 | img6 = cls._create_standard_image('2', 'ami', 'ami', 142) |
| 119 | img7 = cls._create_standard_image('33', 'bare', 'raw', 142) |
| 120 | img8 = cls._create_standard_image('33', 'bare', 'raw', 142) |
| 121 | cls.created_set = set(cls.created_images) |
| 122 | # 4x-4x remote image |
| 123 | cls.remote_set = set((img1, img2, img3, img4)) |
| 124 | cls.standard_set = set((img5, img6, img7, img8)) |
| 125 | # 5x bare, 3x ami |
| 126 | cls.bare_set = set((img1, img3, img4, img7, img8)) |
| 127 | cls.ami_set = set((img2, img5, img6)) |
| 128 | # 1x with size 42 |
| 129 | cls.size42_set = set((img5,)) |
| 130 | # 3x with size 142 |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 131 | cls.size142_set = set((img6, img7, img8,)) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 132 | # dup named |
| 133 | cls.dup_set = set((img3, img4)) |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 134 | |
| 135 | @classmethod |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 136 | def _create_remote_image(cls, name, container_format, disk_format): |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 137 | """ |
| 138 | Create a new remote image and return the ID of the newly-registered |
| 139 | image |
| 140 | """ |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 141 | name = 'New Remote Image %s' % name |
Matthew Treinish | e81ae69 | 2014-06-19 17:41:31 -0400 | [diff] [blame] | 142 | location = CONF.image.http_image |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 143 | _, image = cls.create_image(name=name, |
| 144 | container_format=container_format, |
| 145 | disk_format=disk_format, |
| 146 | is_public=False, |
| 147 | location=location) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 148 | image_id = image['id'] |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 149 | return image_id |
| 150 | |
| 151 | @classmethod |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 152 | def _create_standard_image(cls, name, container_format, |
| 153 | disk_format, size): |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 154 | """ |
| 155 | Create a new standard image and return the ID of the newly-registered |
| 156 | image. Note that the size of the new image is a random number between |
| 157 | 1024 and 4096 |
| 158 | """ |
Mark Washenberger | 5c3b6fe | 2014-07-29 13:40:34 -0700 | [diff] [blame] | 159 | image_file = StringIO.StringIO(data_utils.random_bytes(size)) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 160 | name = 'New Standard Image %s' % name |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 161 | _, image = cls.create_image(name=name, |
| 162 | container_format=container_format, |
| 163 | disk_format=disk_format, |
| 164 | is_public=False, data=image_file) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 165 | image_id = image['id'] |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 166 | return image_id |
| 167 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 168 | @test.attr(type='gate') |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 169 | def test_index_no_params(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 170 | # Simple test to see all fixture images returned |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 171 | _, images_list = self.client.image_list() |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 172 | image_list = map(lambda x: x['id'], images_list) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 173 | for image_id in self.created_images: |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 174 | self.assertIn(image_id, image_list) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 175 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 176 | @test.attr(type='gate') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 177 | def test_index_disk_format(self): |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 178 | _, images_list = self.client.image_list(disk_format='ami') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 179 | for image in images_list: |
| 180 | self.assertEqual(image['disk_format'], 'ami') |
| 181 | result_set = set(map(lambda x: x['id'], images_list)) |
| 182 | self.assertTrue(self.ami_set <= result_set) |
| 183 | self.assertFalse(self.created_set - self.ami_set <= result_set) |
| 184 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 185 | @test.attr(type='gate') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 186 | def test_index_container_format(self): |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 187 | _, images_list = self.client.image_list(container_format='bare') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 188 | for image in images_list: |
| 189 | self.assertEqual(image['container_format'], 'bare') |
| 190 | result_set = set(map(lambda x: x['id'], images_list)) |
| 191 | self.assertTrue(self.bare_set <= result_set) |
| 192 | self.assertFalse(self.created_set - self.bare_set <= result_set) |
| 193 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 194 | @test.attr(type='gate') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 195 | def test_index_max_size(self): |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 196 | _, images_list = self.client.image_list(size_max=42) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 197 | for image in images_list: |
| 198 | self.assertTrue(image['size'] <= 42) |
| 199 | result_set = set(map(lambda x: x['id'], images_list)) |
| 200 | self.assertTrue(self.size42_set <= result_set) |
| 201 | self.assertFalse(self.created_set - self.size42_set <= result_set) |
| 202 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 203 | @test.attr(type='gate') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 204 | def test_index_min_size(self): |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 205 | _, images_list = self.client.image_list(size_min=142) |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 206 | for image in images_list: |
| 207 | self.assertTrue(image['size'] >= 142) |
| 208 | result_set = set(map(lambda x: x['id'], images_list)) |
| 209 | self.assertTrue(self.size142_set <= result_set) |
| 210 | self.assertFalse(self.size42_set <= result_set) |
| 211 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 212 | @test.attr(type='gate') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 213 | def test_index_status_active_detail(self): |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 214 | _, images_list = self.client.image_list_detail(status='active', |
| 215 | sort_key='size', |
| 216 | sort_dir='desc') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 217 | top_size = images_list[0]['size'] # We have non-zero sized images |
| 218 | for image in images_list: |
| 219 | size = image['size'] |
| 220 | self.assertTrue(size <= top_size) |
| 221 | top_size = size |
| 222 | self.assertEqual(image['status'], 'active') |
| 223 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 224 | @test.attr(type='gate') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 225 | def test_index_name(self): |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 226 | _, images_list = self.client.image_list_detail( |
Sean Dague | 14c6818 | 2013-04-14 15:34:30 -0400 | [diff] [blame] | 227 | name='New Remote Image dup') |
Attila Fazekas | 11795b5 | 2013-02-24 15:49:08 +0100 | [diff] [blame] | 228 | result_set = set(map(lambda x: x['id'], images_list)) |
| 229 | for image in images_list: |
| 230 | self.assertEqual(image['name'], 'New Remote Image dup') |
| 231 | self.assertTrue(self.dup_set <= result_set) |
| 232 | self.assertFalse(self.created_set - self.dup_set <= result_set) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 233 | |
| 234 | |
| 235 | class ListSnapshotImagesTest(base.BaseV1ImageTest): |
| 236 | @classmethod |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 237 | def resource_setup(cls): |
Zhi Kun Liu | 4640b01 | 2014-04-23 22:50:40 +0800 | [diff] [blame] | 238 | # This test class only uses nova v3 api to create snapshot |
| 239 | # as the similar test which uses nova v2 api already exists |
| 240 | # in nova v2 compute images api tests. |
| 241 | # Since nova v3 doesn't have images api proxy, this test |
| 242 | # class was added in the image api tests. |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 243 | if not CONF.compute_feature_enabled.api_v3: |
Zhi Kun Liu | 4640b01 | 2014-04-23 22:50:40 +0800 | [diff] [blame] | 244 | skip_msg = ("%s skipped as nova v3 api is not available" % |
| 245 | cls.__name__) |
| 246 | raise cls.skipException(skip_msg) |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 247 | super(ListSnapshotImagesTest, cls).resource_setup() |
Zhi Kun Liu | 4640b01 | 2014-04-23 22:50:40 +0800 | [diff] [blame] | 248 | cls.servers_client = cls.os.servers_v3_client |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 249 | cls.servers = [] |
| 250 | # We add a few images here to test the listing functionality of |
| 251 | # the images API |
| 252 | cls.snapshot = cls._create_snapshot( |
| 253 | 'snapshot', CONF.compute.image_ref, |
| 254 | CONF.compute.flavor_ref) |
| 255 | cls.snapshot_set = set((cls.snapshot,)) |
| 256 | |
| 257 | image_file = StringIO.StringIO('*' * 42) |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 258 | _, image = cls.create_image(name="Standard Image", |
| 259 | container_format='ami', |
| 260 | disk_format='ami', |
| 261 | is_public=False, data=image_file) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 262 | cls.image_id = image['id'] |
| 263 | cls.client.wait_for_image_status(image['id'], 'active') |
| 264 | |
| 265 | @classmethod |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 266 | def resource_cleanup(cls): |
Zhi Kun Liu | ca934a4 | 2014-03-24 01:30:31 -0500 | [diff] [blame] | 267 | for server in getattr(cls, "servers", []): |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 268 | cls.servers_client.delete_server(server['id']) |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 269 | super(ListSnapshotImagesTest, cls).resource_cleanup() |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 270 | |
| 271 | @classmethod |
| 272 | def _create_snapshot(cls, name, image_id, flavor, **kwargs): |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 273 | _, server = cls.servers_client.create_server( |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 274 | name, image_id, flavor, **kwargs) |
| 275 | cls.servers.append(server) |
| 276 | cls.servers_client.wait_for_server_status( |
| 277 | server['id'], 'ACTIVE') |
Zhi Kun Liu | 4640b01 | 2014-04-23 22:50:40 +0800 | [diff] [blame] | 278 | resp, _ = cls.servers_client.create_image(server['id'], name) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 279 | image_id = data_utils.parse_image_id(resp['location']) |
| 280 | cls.created_images.append(image_id) |
| 281 | cls.client.wait_for_image_status(image_id, |
| 282 | 'active') |
| 283 | return image_id |
| 284 | |
| 285 | @test.attr(type='gate') |
Matthew Treinish | 08c6a01 | 2014-05-05 22:04:38 -0400 | [diff] [blame] | 286 | @test.services('compute') |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 287 | def test_index_server_id(self): |
| 288 | # The images should contain images filtered by server id |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 289 | _, images = self.client.image_list_detail( |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 290 | {'instance_uuid': self.servers[0]['id']}) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 291 | result_set = set(map(lambda x: x['id'], images)) |
| 292 | self.assertEqual(self.snapshot_set, result_set) |
| 293 | |
| 294 | @test.attr(type='gate') |
Matthew Treinish | 08c6a01 | 2014-05-05 22:04:38 -0400 | [diff] [blame] | 295 | @test.services('compute') |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 296 | def test_index_type(self): |
| 297 | # The list of servers should be filtered by image type |
| 298 | params = {'image_type': 'snapshot'} |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 299 | _, images = self.client.image_list_detail(params) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 300 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 301 | result_set = set(map(lambda x: x['id'], images)) |
| 302 | self.assertIn(self.snapshot, result_set) |
| 303 | |
| 304 | @test.attr(type='gate') |
Matthew Treinish | 08c6a01 | 2014-05-05 22:04:38 -0400 | [diff] [blame] | 305 | @test.services('compute') |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 306 | def test_index_limit(self): |
| 307 | # Verify only the expected number of results are returned |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 308 | _, images = self.client.image_list_detail(limit=1) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 309 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 310 | self.assertEqual(1, len(images)) |
| 311 | |
| 312 | @test.attr(type='gate') |
Matthew Treinish | 08c6a01 | 2014-05-05 22:04:38 -0400 | [diff] [blame] | 313 | @test.services('compute') |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 314 | def test_index_by_change_since(self): |
| 315 | # Verify an update image is returned |
| 316 | # Becoming ACTIVE will modify the updated time |
| 317 | # Filter by the image's created time |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 318 | _, image = self.client.get_image_meta(self.snapshot) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 319 | self.assertEqual(self.snapshot, image['id']) |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 320 | _, images = self.client.image_list_detail( |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 321 | changes_since=image['updated_at']) |
| 322 | |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 323 | result_set = set(map(lambda x: x['id'], images)) |
| 324 | self.assertIn(self.image_id, result_set) |
| 325 | self.assertNotIn(self.snapshot, result_set) |
| 326 | |
| 327 | |
| 328 | class UpdateImageMetaTest(base.BaseV1ImageTest): |
| 329 | @classmethod |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 330 | def resource_setup(cls): |
| 331 | super(UpdateImageMetaTest, cls).resource_setup() |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 332 | cls.image_id = cls._create_standard_image('1', 'ami', 'ami', 42) |
| 333 | |
| 334 | @classmethod |
| 335 | def _create_standard_image(cls, name, container_format, |
| 336 | disk_format, size): |
| 337 | """ |
| 338 | Create a new standard image and return the ID of the newly-registered |
Mark Washenberger | 5c3b6fe | 2014-07-29 13:40:34 -0700 | [diff] [blame] | 339 | image. |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 340 | """ |
Mark Washenberger | 5c3b6fe | 2014-07-29 13:40:34 -0700 | [diff] [blame] | 341 | image_file = StringIO.StringIO(data_utils.random_bytes(size)) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 342 | name = 'New Standard Image %s' % name |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 343 | _, image = cls.create_image(name=name, |
| 344 | container_format=container_format, |
| 345 | disk_format=disk_format, |
| 346 | is_public=False, data=image_file, |
| 347 | properties={'key1': 'value1'}) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 348 | image_id = image['id'] |
| 349 | return image_id |
| 350 | |
| 351 | @test.attr(type='gate') |
| 352 | def test_list_image_metadata(self): |
| 353 | # All metadata key/value pairs for an image should be returned |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 354 | _, resp_metadata = self.client.get_image_meta(self.image_id) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 355 | expected = {'key1': 'value1'} |
| 356 | self.assertEqual(expected, resp_metadata['properties']) |
| 357 | |
| 358 | @test.attr(type='gate') |
| 359 | def test_update_image_metadata(self): |
| 360 | # The metadata for the image should match the updated values |
| 361 | req_metadata = {'key1': 'alt1', 'key2': 'value2'} |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 362 | _, metadata = self.client.get_image_meta(self.image_id) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 363 | self.assertEqual(metadata['properties'], {'key1': 'value1'}) |
| 364 | metadata['properties'].update(req_metadata) |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 365 | _, metadata = self.client.update_image( |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 366 | self.image_id, properties=metadata['properties']) |
| 367 | |
David Kranz | 9c3b3b6 | 2014-06-19 16:05:53 -0400 | [diff] [blame] | 368 | _, resp_metadata = self.client.get_image_meta(self.image_id) |
ivan-zhu | d1bbe5d | 2013-12-29 18:32:46 +0800 | [diff] [blame] | 369 | expected = {'key1': 'alt1', 'key2': 'value2'} |
| 370 | self.assertEqual(expected, resp_metadata['properties']) |