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 | |
| 17 | import cStringIO as StringIO |
| 18 | import random |
| 19 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 20 | from tempest.api.image import base |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 21 | from tempest.common.utils import data_utils |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 22 | from tempest import test |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 23 | |
| 24 | |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 25 | class BasicOperationsImagesTest(base.BaseV2ImageTest): |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 26 | """ |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 27 | Here we test the basic operations of images |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 28 | """ |
| 29 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 30 | @test.attr(type='gate') |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 31 | def test_register_upload_get_image_file(self): |
| 32 | |
| 33 | """ |
| 34 | Here we test these functionalities - Register image, |
| 35 | upload the image file, get image and get image file api's |
| 36 | """ |
| 37 | |
Sean Dague | c6ec476 | 2014-05-29 08:54:21 -0400 | [diff] [blame] | 38 | uuid = '00000000-1111-2222-3333-444455556666' |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 39 | image_name = data_utils.rand_name('image') |
| 40 | resp, body = self.create_image(name=image_name, |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 41 | container_format='bare', |
| 42 | disk_format='raw', |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame^] | 43 | visibility='private', |
Sean Dague | c6ec476 | 2014-05-29 08:54:21 -0400 | [diff] [blame] | 44 | ramdisk_id=uuid) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 45 | self.assertIn('id', body) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 46 | image_id = body.get('id') |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 47 | self.assertIn('name', body) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 48 | self.assertEqual(image_name, body['name']) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 49 | self.assertIn('visibility', body) |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame^] | 50 | self.assertEqual('private', body['visibility']) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 51 | self.assertIn('status', body) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 52 | self.assertEqual('queued', body['status']) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 53 | |
| 54 | # Now try uploading an image file |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 55 | file_content = '*' * 1024 |
| 56 | image_file = StringIO.StringIO(file_content) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 57 | resp, body = self.client.store_image(image_id, image_file) |
| 58 | self.assertEqual(resp.status, 204) |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 59 | |
| 60 | # Now try to get image details |
| 61 | resp, body = self.client.get_image(image_id) |
| 62 | self.assertEqual(200, resp.status) |
| 63 | self.assertEqual(image_id, body['id']) |
| 64 | self.assertEqual(image_name, body['name']) |
Sean Dague | c6ec476 | 2014-05-29 08:54:21 -0400 | [diff] [blame] | 65 | self.assertEqual(uuid, body['ramdisk_id']) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 66 | self.assertIn('size', body) |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 67 | self.assertEqual(1024, body.get('size')) |
| 68 | |
Hoisaleshwara Madan V S | e50a6f1 | 2013-10-23 18:01:01 +0530 | [diff] [blame] | 69 | # Now try get image file |
| 70 | resp, body = self.client.get_image_file(image_id) |
| 71 | self.assertEqual(200, resp.status) |
| 72 | self.assertEqual(file_content, body) |
| 73 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 74 | @test.attr(type='gate') |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 75 | def test_delete_image(self): |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 76 | # Deletes an image by image_id |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 77 | |
| 78 | # Create image |
| 79 | image_name = data_utils.rand_name('image') |
| 80 | resp, body = self.client.create_image(name=image_name, |
| 81 | container_format='bare', |
| 82 | disk_format='raw', |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame^] | 83 | visibility='private') |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 84 | self.assertEqual(201, resp.status) |
| 85 | image_id = body['id'] |
| 86 | |
| 87 | # Delete Image |
| 88 | self.client.delete_image(image_id) |
| 89 | self.client.wait_for_resource_deletion(image_id) |
| 90 | |
| 91 | # Verifying deletion |
| 92 | resp, images = self.client.image_list() |
| 93 | self.assertEqual(resp.status, 200) |
| 94 | self.assertNotIn(image_id, images) |
| 95 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 96 | @test.attr(type='gate') |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 97 | def test_update_image(self): |
| 98 | # Updates an image by image_id |
| 99 | |
| 100 | # Create image |
| 101 | image_name = data_utils.rand_name('image') |
| 102 | resp, body = self.client.create_image(name=image_name, |
| 103 | container_format='bare', |
| 104 | disk_format='iso', |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame^] | 105 | visibility='private') |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 106 | self.assertEqual(201, resp.status) |
Masayuki Igawa | 930ac37 | 2014-03-11 18:50:26 +0900 | [diff] [blame] | 107 | self.addCleanup(self.client.delete_image, body['id']) |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 108 | self.assertEqual('queued', body['status']) |
| 109 | image_id = body['id'] |
| 110 | |
| 111 | # Now try uploading an image file |
| 112 | file_content = '*' * 1024 |
| 113 | image_file = StringIO.StringIO(file_content) |
| 114 | resp, body = self.client.store_image(image_id, image_file) |
| 115 | self.assertEqual(204, resp.status) |
| 116 | |
| 117 | # Update Image |
| 118 | new_image_name = data_utils.rand_name('new-image') |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 119 | resp, body = self.client.update_image(image_id, [ |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame^] | 120 | dict(replace='/name', value=new_image_name)]) |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 121 | |
| 122 | self.assertEqual(200, resp.status) |
| 123 | |
| 124 | # Verifying updating |
| 125 | |
| 126 | resp, body = self.client.get_image(image_id) |
| 127 | self.assertEqual(200, resp.status) |
| 128 | self.assertEqual(image_id, body['id']) |
| 129 | self.assertEqual(new_image_name, body['name']) |
Sergey Nikitin | c6b2ee8 | 2014-02-03 17:13:50 +0400 | [diff] [blame] | 130 | |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 131 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 132 | class ListImagesTest(base.BaseV2ImageTest): |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 133 | """ |
| 134 | Here we test the listing of image information |
| 135 | """ |
| 136 | |
| 137 | @classmethod |
Zhi Kun Liu | ca934a4 | 2014-03-24 01:30:31 -0500 | [diff] [blame] | 138 | @test.safe_setup |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 139 | def setUpClass(cls): |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 140 | super(ListImagesTest, cls).setUpClass() |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 141 | # We add a few images here to test the listing functionality of |
| 142 | # the images API |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 143 | cls._create_standard_image('bare', 'raw') |
| 144 | cls._create_standard_image('bare', 'raw') |
| 145 | cls._create_standard_image('ami', 'raw') |
| 146 | # Add some more for listing |
| 147 | cls._create_standard_image('ami', 'ami') |
| 148 | cls._create_standard_image('ari', 'ari') |
| 149 | cls._create_standard_image('aki', 'aki') |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 150 | |
| 151 | @classmethod |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 152 | def _create_standard_image(cls, container_format, disk_format): |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 153 | """ |
| 154 | Create a new standard image and return the ID of the newly-registered |
| 155 | image. Note that the size of the new image is a random number between |
| 156 | 1024 and 4096 |
| 157 | """ |
| 158 | image_file = StringIO.StringIO('*' * random.randint(1024, 4096)) |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 159 | name = data_utils.rand_name('image-') |
| 160 | resp, body = cls.create_image(name=name, |
| 161 | container_format=container_format, |
| 162 | disk_format=disk_format, |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame^] | 163 | visibility='private') |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 164 | image_id = body['id'] |
| 165 | resp, body = cls.client.store_image(image_id, data=image_file) |
| 166 | |
| 167 | return image_id |
| 168 | |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 169 | def _list_by_param_value_and_assert(self, params): |
| 170 | """ |
| 171 | Perform list action with given params and validates result. |
| 172 | """ |
| 173 | resp, images_list = self.client.image_list(params=params) |
| 174 | self.assertEqual(200, resp.status) |
| 175 | # Validating params of fetched images |
| 176 | for image in images_list: |
| 177 | for key in params: |
| 178 | msg = "Failed to list images by %s" % key |
| 179 | self.assertEqual(params[key], image[key], msg) |
| 180 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 181 | @test.attr(type='gate') |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 182 | def test_index_no_params(self): |
| 183 | # Simple test to see all fixture images returned |
| 184 | resp, images_list = self.client.image_list() |
| 185 | self.assertEqual(resp['status'], '200') |
| 186 | image_list = map(lambda x: x['id'], images_list) |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 187 | |
Matthew Treinish | a62347f | 2013-03-01 16:37:30 -0500 | [diff] [blame] | 188 | for image in self.created_images: |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 189 | self.assertIn(image, image_list) |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 190 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 191 | @test.attr(type='gate') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 192 | def test_list_images_param_container_format(self): |
| 193 | # Test to get all images with container_format='bare' |
| 194 | params = {"container_format": "bare"} |
| 195 | self._list_by_param_value_and_assert(params) |
| 196 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 197 | @test.attr(type='gate') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 198 | def test_list_images_param_disk_format(self): |
| 199 | # Test to get all images with disk_format = raw |
| 200 | params = {"disk_format": "raw"} |
| 201 | self._list_by_param_value_and_assert(params) |
| 202 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 203 | @test.attr(type='gate') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 204 | def test_list_images_param_visibility(self): |
Aaron Rosen | c772062 | 2014-05-20 10:38:10 -0700 | [diff] [blame^] | 205 | # Test to get all images with visibility = private |
| 206 | params = {"visibility": "private"} |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 207 | self._list_by_param_value_and_assert(params) |
| 208 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 209 | @test.attr(type='gate') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 210 | def test_list_images_param_size(self): |
| 211 | # Test to get all images by size |
| 212 | image_id = self.created_images[1] |
| 213 | # Get image metadata |
| 214 | resp, image = self.client.get_image(image_id) |
| 215 | self.assertEqual(resp['status'], '200') |
| 216 | |
| 217 | params = {"size": image['size']} |
| 218 | self._list_by_param_value_and_assert(params) |
| 219 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 220 | @test.attr(type='gate') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 221 | def test_list_images_param_min_max_size(self): |
| 222 | # Test to get all images with size between 2000 to 3000 |
| 223 | image_id = self.created_images[1] |
| 224 | # Get image metadata |
| 225 | resp, image = self.client.get_image(image_id) |
| 226 | self.assertEqual(resp['status'], '200') |
| 227 | |
| 228 | size = image['size'] |
| 229 | params = {"size_min": size - 500, "size_max": size + 500} |
| 230 | resp, images_list = self.client.image_list(params=params) |
| 231 | self.assertEqual(resp['status'], '200') |
| 232 | image_size_list = map(lambda x: x['size'], images_list) |
| 233 | |
| 234 | for image_size in image_size_list: |
| 235 | self.assertTrue(image_size >= params['size_min'] and |
| 236 | image_size <= params['size_max'], |
| 237 | "Failed to get images by size_min and size_max") |
| 238 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 239 | @test.attr(type='gate') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 240 | def test_list_images_param_status(self): |
Anju Tiwari | ca2249d | 2014-01-23 17:33:02 +0530 | [diff] [blame] | 241 | # Test to get all active images |
| 242 | params = {"status": "active"} |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 243 | self._list_by_param_value_and_assert(params) |
| 244 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 245 | @test.attr(type='gate') |
Abhijeet Malawade | f268d8e | 2013-09-17 06:20:23 -0700 | [diff] [blame] | 246 | def test_list_images_param_limit(self): |
| 247 | # Test to get images by limit |
| 248 | params = {"limit": 2} |
| 249 | resp, images_list = self.client.image_list(params=params) |
| 250 | self.assertEqual(resp['status'], '200') |
| 251 | |
| 252 | self.assertEqual(len(images_list), params['limit'], |
| 253 | "Failed to get images by limit") |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 254 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 255 | @test.attr(type='gate') |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 256 | def test_get_image_schema(self): |
| 257 | # Test to get image schema |
| 258 | schema = "image" |
| 259 | resp, body = self.client.get_schema(schema) |
| 260 | self.assertEqual(200, resp.status) |
| 261 | self.assertEqual("image", body['name']) |
| 262 | |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 263 | @test.attr(type='gate') |
raiesmh08 | a1ce354 | 2014-03-04 11:58:29 +0530 | [diff] [blame] | 264 | def test_get_images_schema(self): |
| 265 | # Test to get images schema |
| 266 | schema = "images" |
| 267 | resp, body = self.client.get_schema(schema) |
| 268 | self.assertEqual(200, resp.status) |
| 269 | self.assertEqual("images", body['name']) |