blob: ef0b5f1578ecebc93ac77fd47e1eb176dd0670a0 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2013 OpenStack Foundation
Hoisaleshwara Madan V S7cba1082013-11-26 12:43:04 +05302# Copyright 2013 IBM Corp
Matthew Treinisha62347f2013-03-01 16:37:30 -05003# All Rights Reserved.
Matthew Treinisha62347f2013-03-01 16:37:30 -05004#
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
Matthew Treinisha62347f2013-03-01 16:37:30 -050017import random
18
Matthew Treinishb0c65f22015-04-23 09:09:41 -040019from six import moves
Matthew Treinish01472ff2015-02-20 17:26:52 -050020from tempest_lib.common.utils import data_utils
21
Sean Dague1937d092013-05-17 16:36:38 -040022from tempest.api.image import base
Eiichi Aikawa9012f462014-03-05 16:43:32 +090023from tempest import test
Matthew Treinisha62347f2013-03-01 16:37:30 -050024
25
Hoisaleshwara Madan V S7cba1082013-11-26 12:43:04 +053026class BasicOperationsImagesTest(base.BaseV2ImageTest):
Matthew Treinisha62347f2013-03-01 16:37:30 -050027 """
Hoisaleshwara Madan V S7cba1082013-11-26 12:43:04 +053028 Here we test the basic operations of images
Matthew Treinisha62347f2013-03-01 16:37:30 -050029 """
30
Eiichi Aikawa9012f462014-03-05 16:43:32 +090031 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080032 @test.idempotent_id('139b765e-7f3d-4b3d-8b37-3ca3876ee318')
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053033 def test_register_upload_get_image_file(self):
34
35 """
36 Here we test these functionalities - Register image,
37 upload the image file, get image and get image file api's
38 """
39
Sean Daguec6ec4762014-05-29 08:54:21 -040040 uuid = '00000000-1111-2222-3333-444455556666'
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053041 image_name = data_utils.rand_name('image')
David Kranz34f18782015-01-06 13:43:55 -050042 body = self.create_image(name=image_name,
43 container_format='bare',
44 disk_format='raw',
45 visibility='private',
46 ramdisk_id=uuid)
Attila Fazekase191cb12013-07-29 06:41:52 +020047 self.assertIn('id', body)
Matthew Treinisha62347f2013-03-01 16:37:30 -050048 image_id = body.get('id')
Attila Fazekase191cb12013-07-29 06:41:52 +020049 self.assertIn('name', body)
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053050 self.assertEqual(image_name, body['name'])
Attila Fazekase191cb12013-07-29 06:41:52 +020051 self.assertIn('visibility', body)
Aaron Rosenc7720622014-05-20 10:38:10 -070052 self.assertEqual('private', body['visibility'])
Attila Fazekase191cb12013-07-29 06:41:52 +020053 self.assertIn('status', body)
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053054 self.assertEqual('queued', body['status'])
Matthew Treinisha62347f2013-03-01 16:37:30 -050055
56 # Now try uploading an image file
Mark Washenberger5c3b6fe2014-07-29 13:40:34 -070057 file_content = data_utils.random_bytes()
Matthew Treinishb0c65f22015-04-23 09:09:41 -040058 image_file = moves.cStringIO(file_content)
David Kranz9c3b3b62014-06-19 16:05:53 -040059 self.client.store_image(image_id, image_file)
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053060
61 # Now try to get image details
David Kranz34f18782015-01-06 13:43:55 -050062 body = self.client.get_image(image_id)
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053063 self.assertEqual(image_id, body['id'])
64 self.assertEqual(image_name, body['name'])
Sean Daguec6ec4762014-05-29 08:54:21 -040065 self.assertEqual(uuid, body['ramdisk_id'])
Attila Fazekase191cb12013-07-29 06:41:52 +020066 self.assertIn('size', body)
Matthew Treinisha62347f2013-03-01 16:37:30 -050067 self.assertEqual(1024, body.get('size'))
68
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053069 # Now try get image file
David Kranzd7e97b42015-02-16 09:37:31 -050070 body = self.client.get_image_file(image_id)
71 self.assertEqual(file_content, body.data)
Hoisaleshwara Madan V Se50a6f12013-10-23 18:01:01 +053072
Eiichi Aikawa9012f462014-03-05 16:43:32 +090073 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080074 @test.idempotent_id('f848bb94-1c6e-45a4-8726-39e3a5b23535')
Hoisaleshwara Madan V S7cba1082013-11-26 12:43:04 +053075 def test_delete_image(self):
Sergey Nikitinc6b2ee82014-02-03 17:13:50 +040076 # Deletes an image by image_id
Hoisaleshwara Madan V S7cba1082013-11-26 12:43:04 +053077
78 # Create image
79 image_name = data_utils.rand_name('image')
David Kranz34f18782015-01-06 13:43:55 -050080 body = self.client.create_image(name=image_name,
81 container_format='bare',
82 disk_format='raw',
83 visibility='private')
Hoisaleshwara Madan V S7cba1082013-11-26 12:43:04 +053084 image_id = body['id']
85
86 # Delete Image
87 self.client.delete_image(image_id)
88 self.client.wait_for_resource_deletion(image_id)
89
90 # Verifying deletion
David Kranz34f18782015-01-06 13:43:55 -050091 images = self.client.image_list()
Sunil G29856a32014-07-17 23:17:58 +053092 images_id = [item['id'] for item in images]
93 self.assertNotIn(image_id, images_id)
Hoisaleshwara Madan V S7cba1082013-11-26 12:43:04 +053094
Eiichi Aikawa9012f462014-03-05 16:43:32 +090095 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080096 @test.idempotent_id('f66891a7-a35c-41a8-b590-a065c2a1caa6')
Sergey Nikitinc6b2ee82014-02-03 17:13:50 +040097 def test_update_image(self):
98 # Updates an image by image_id
99
100 # Create image
101 image_name = data_utils.rand_name('image')
David Kranz34f18782015-01-06 13:43:55 -0500102 body = self.client.create_image(name=image_name,
103 container_format='bare',
104 disk_format='iso',
105 visibility='private')
Masayuki Igawa930ac372014-03-11 18:50:26 +0900106 self.addCleanup(self.client.delete_image, body['id'])
Sergey Nikitinc6b2ee82014-02-03 17:13:50 +0400107 self.assertEqual('queued', body['status'])
108 image_id = body['id']
109
110 # Now try uploading an image file
Matthew Treinishb0c65f22015-04-23 09:09:41 -0400111 image_file = moves.cStringIO(data_utils.random_bytes())
David Kranz9c3b3b62014-06-19 16:05:53 -0400112 self.client.store_image(image_id, image_file)
Sergey Nikitinc6b2ee82014-02-03 17:13:50 +0400113
114 # Update Image
115 new_image_name = data_utils.rand_name('new-image')
David Kranz34f18782015-01-06 13:43:55 -0500116 body = self.client.update_image(image_id, [
Aaron Rosenc7720622014-05-20 10:38:10 -0700117 dict(replace='/name', value=new_image_name)])
Sergey Nikitinc6b2ee82014-02-03 17:13:50 +0400118
Sergey Nikitinc6b2ee82014-02-03 17:13:50 +0400119 # Verifying updating
120
David Kranz34f18782015-01-06 13:43:55 -0500121 body = self.client.get_image(image_id)
Sergey Nikitinc6b2ee82014-02-03 17:13:50 +0400122 self.assertEqual(image_id, body['id'])
123 self.assertEqual(new_image_name, body['name'])
Sergey Nikitinc6b2ee82014-02-03 17:13:50 +0400124
Matthew Treinisha62347f2013-03-01 16:37:30 -0500125
Matthew Treinishce3ef922013-03-11 14:02:46 -0400126class ListImagesTest(base.BaseV2ImageTest):
Matthew Treinisha62347f2013-03-01 16:37:30 -0500127 """
128 Here we test the listing of image information
129 """
130
131 @classmethod
Andrea Frittoli69a6b632014-09-15 13:14:53 +0100132 def resource_setup(cls):
133 super(ListImagesTest, cls).resource_setup()
Matthew Treinisha62347f2013-03-01 16:37:30 -0500134 # We add a few images here to test the listing functionality of
135 # the images API
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700136 cls._create_standard_image('bare', 'raw')
137 cls._create_standard_image('bare', 'raw')
138 cls._create_standard_image('ami', 'raw')
139 # Add some more for listing
140 cls._create_standard_image('ami', 'ami')
141 cls._create_standard_image('ari', 'ari')
142 cls._create_standard_image('aki', 'aki')
Matthew Treinisha62347f2013-03-01 16:37:30 -0500143
144 @classmethod
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700145 def _create_standard_image(cls, container_format, disk_format):
Matthew Treinisha62347f2013-03-01 16:37:30 -0500146 """
147 Create a new standard image and return the ID of the newly-registered
148 image. Note that the size of the new image is a random number between
149 1024 and 4096
150 """
Mark Washenberger5c3b6fe2014-07-29 13:40:34 -0700151 size = random.randint(1024, 4096)
Matthew Treinishb0c65f22015-04-23 09:09:41 -0400152 image_file = moves.cStringIO(data_utils.random_bytes(size))
Ken'ichi Ohmichid3906c92015-03-23 00:26:11 +0000153 name = data_utils.rand_name('image')
David Kranz34f18782015-01-06 13:43:55 -0500154 body = cls.create_image(name=name,
155 container_format=container_format,
156 disk_format=disk_format,
157 visibility='private')
Matthew Treinisha62347f2013-03-01 16:37:30 -0500158 image_id = body['id']
David Kranz9c3b3b62014-06-19 16:05:53 -0400159 cls.client.store_image(image_id, data=image_file)
Matthew Treinisha62347f2013-03-01 16:37:30 -0500160
161 return image_id
162
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700163 def _list_by_param_value_and_assert(self, params):
164 """
165 Perform list action with given params and validates result.
166 """
David Kranz34f18782015-01-06 13:43:55 -0500167 images_list = self.client.image_list(params=params)
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700168 # Validating params of fetched images
169 for image in images_list:
170 for key in params:
171 msg = "Failed to list images by %s" % key
172 self.assertEqual(params[key], image[key], msg)
173
Eiichi Aikawa9012f462014-03-05 16:43:32 +0900174 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800175 @test.idempotent_id('1e341d7a-90a9-494c-b143-2cdf2aeb6aee')
Matthew Treinisha62347f2013-03-01 16:37:30 -0500176 def test_index_no_params(self):
177 # Simple test to see all fixture images returned
David Kranz34f18782015-01-06 13:43:55 -0500178 images_list = self.client.image_list()
Matthew Treinisha62347f2013-03-01 16:37:30 -0500179 image_list = map(lambda x: x['id'], images_list)
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700180
Matthew Treinisha62347f2013-03-01 16:37:30 -0500181 for image in self.created_images:
Attila Fazekase191cb12013-07-29 06:41:52 +0200182 self.assertIn(image, image_list)
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700183
Eiichi Aikawa9012f462014-03-05 16:43:32 +0900184 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800185 @test.idempotent_id('9959ca1d-1aa7-4b7a-a1ea-0fff0499b37e')
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700186 def test_list_images_param_container_format(self):
187 # Test to get all images with container_format='bare'
188 params = {"container_format": "bare"}
189 self._list_by_param_value_and_assert(params)
190
Eiichi Aikawa9012f462014-03-05 16:43:32 +0900191 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800192 @test.idempotent_id('4a4735a7-f22f-49b6-b0d9-66e1ef7453eb')
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700193 def test_list_images_param_disk_format(self):
194 # Test to get all images with disk_format = raw
195 params = {"disk_format": "raw"}
196 self._list_by_param_value_and_assert(params)
197
Eiichi Aikawa9012f462014-03-05 16:43:32 +0900198 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800199 @test.idempotent_id('7a95bb92-d99e-4b12-9718-7bc6ab73e6d2')
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700200 def test_list_images_param_visibility(self):
Aaron Rosenc7720622014-05-20 10:38:10 -0700201 # Test to get all images with visibility = private
202 params = {"visibility": "private"}
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700203 self._list_by_param_value_and_assert(params)
204
Eiichi Aikawa9012f462014-03-05 16:43:32 +0900205 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800206 @test.idempotent_id('cf1b9a48-8340-480e-af7b-fe7e17690876')
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700207 def test_list_images_param_size(self):
208 # Test to get all images by size
209 image_id = self.created_images[1]
210 # Get image metadata
David Kranz34f18782015-01-06 13:43:55 -0500211 image = self.client.get_image(image_id)
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700212
213 params = {"size": image['size']}
214 self._list_by_param_value_and_assert(params)
215
Eiichi Aikawa9012f462014-03-05 16:43:32 +0900216 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800217 @test.idempotent_id('4ad8c157-971a-4ba8-aa84-ed61154b1e7f')
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700218 def test_list_images_param_min_max_size(self):
219 # Test to get all images with size between 2000 to 3000
220 image_id = self.created_images[1]
221 # Get image metadata
David Kranz34f18782015-01-06 13:43:55 -0500222 image = self.client.get_image(image_id)
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700223
224 size = image['size']
225 params = {"size_min": size - 500, "size_max": size + 500}
David Kranz34f18782015-01-06 13:43:55 -0500226 images_list = self.client.image_list(params=params)
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700227 image_size_list = map(lambda x: x['size'], images_list)
228
229 for image_size in image_size_list:
230 self.assertTrue(image_size >= params['size_min'] and
231 image_size <= params['size_max'],
232 "Failed to get images by size_min and size_max")
233
Eiichi Aikawa9012f462014-03-05 16:43:32 +0900234 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800235 @test.idempotent_id('7fc9e369-0f58-4d05-9aa5-0969e2d59d15')
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700236 def test_list_images_param_status(self):
Anju Tiwarica2249d2014-01-23 17:33:02 +0530237 # Test to get all active images
238 params = {"status": "active"}
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700239 self._list_by_param_value_and_assert(params)
240
Eiichi Aikawa9012f462014-03-05 16:43:32 +0900241 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800242 @test.idempotent_id('e914a891-3cc8-4b40-ad32-e0a39ffbddbb')
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700243 def test_list_images_param_limit(self):
244 # Test to get images by limit
245 params = {"limit": 2}
David Kranz34f18782015-01-06 13:43:55 -0500246 images_list = self.client.image_list(params=params)
Abhijeet Malawadef268d8e2013-09-17 06:20:23 -0700247
248 self.assertEqual(len(images_list), params['limit'],
249 "Failed to get images by limit")
raiesmh08a1ce3542014-03-04 11:58:29 +0530250
Eiichi Aikawa9012f462014-03-05 16:43:32 +0900251 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800252 @test.idempotent_id('622b925c-479f-4736-860d-adeaf13bc371')
raiesmh08a1ce3542014-03-04 11:58:29 +0530253 def test_get_image_schema(self):
254 # Test to get image schema
255 schema = "image"
David Kranz34f18782015-01-06 13:43:55 -0500256 body = self.client.get_schema(schema)
raiesmh08a1ce3542014-03-04 11:58:29 +0530257 self.assertEqual("image", body['name'])
258
Eiichi Aikawa9012f462014-03-05 16:43:32 +0900259 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800260 @test.idempotent_id('25c8d7b2-df21-460f-87ac-93130bcdc684')
raiesmh08a1ce3542014-03-04 11:58:29 +0530261 def test_get_images_schema(self):
262 # Test to get images schema
263 schema = "images"
David Kranz34f18782015-01-06 13:43:55 -0500264 body = self.client.get_schema(schema)
raiesmh08a1ce3542014-03-04 11:58:29 +0530265 self.assertEqual("images", body['name'])