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