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