blob: c5d3f935c3a24eb20999ff7d5119f3c500100a94 [file] [log] [blame]
Jay Pipes50677282012-01-06 15:39:20 -05001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import cStringIO as StringIO
Jay Pipes50677282012-01-06 15:39:20 -050019
Sean Dague1937d092013-05-17 16:36:38 -040020from tempest.api.image import base
Matthew Treinish72ea4422013-02-07 14:42:49 -050021from tempest import exceptions
Attila Fazekas11795b52013-02-24 15:49:08 +010022from tempest.test import attr
Jay Pipes50677282012-01-06 15:39:20 -050023
24
Matthew Treinishce3ef922013-03-11 14:02:46 -040025class CreateRegisterImagesTest(base.BaseV1ImageTest):
26 """Here we test the registration and creation of images."""
Jay Pipes50677282012-01-06 15:39:20 -050027
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040028 @attr(type='gate')
Matthew Treinish72ea4422013-02-07 14:42:49 -050029 def test_register_with_invalid_container_format(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050030 # Negative tests for invalid data supplied to POST /images
Chris Yeohe04628e2013-02-25 17:12:21 +103031 self.assertRaises(exceptions.BadRequest, self.client.create_image,
32 'test', 'wrong', 'vhd')
Jay Pipes50677282012-01-06 15:39:20 -050033
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040034 @attr(type='gate')
Matthew Treinish72ea4422013-02-07 14:42:49 -050035 def test_register_with_invalid_disk_format(self):
Chris Yeohe04628e2013-02-25 17:12:21 +103036 self.assertRaises(exceptions.BadRequest, self.client.create_image,
37 'test', 'bare', 'wrong')
Jay Pipes50677282012-01-06 15:39:20 -050038
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040039 @attr(type='gate')
Jay Pipes50677282012-01-06 15:39:20 -050040 def test_register_then_upload(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050041 # Register, then upload an image
Matthew Treinish72ea4422013-02-07 14:42:49 -050042 properties = {'prop1': 'val1'}
Matthew Treinishce3ef922013-03-11 14:02:46 -040043 resp, body = self.create_image(name='New Name',
44 container_format='bare',
45 disk_format='raw',
46 is_public=True,
47 properties=properties)
Matthew Treinish72ea4422013-02-07 14:42:49 -050048 self.assertTrue('id' in body)
49 image_id = body.get('id')
Jay Pipes50677282012-01-06 15:39:20 -050050 self.created_images.append(image_id)
Matthew Treinish72ea4422013-02-07 14:42:49 -050051 self.assertEqual('New Name', body.get('name'))
Matthew Treinish72ea4422013-02-07 14:42:49 -050052 self.assertTrue(body.get('is_public'))
Matthew Treinish72ea4422013-02-07 14:42:49 -050053 self.assertEqual('queued', body.get('status'))
Matthew Treinish72ea4422013-02-07 14:42:49 -050054 for key, val in properties.items():
55 self.assertEqual(val, body.get('properties')[key])
Jay Pipes50677282012-01-06 15:39:20 -050056
57 # Now try uploading an image file
Matthew Treinish72ea4422013-02-07 14:42:49 -050058 image_file = StringIO.StringIO(('*' * 1024))
59 resp, body = self.client.update_image(image_id, data=image_file)
60 self.assertTrue('size' in body)
61 self.assertEqual(1024, body.get('size'))
Jay Pipes50677282012-01-06 15:39:20 -050062
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040063 @attr(type='gate')
Jay Pipes50677282012-01-06 15:39:20 -050064 def test_register_remote_image(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050065 # Register a new remote image
Matthew Treinishce3ef922013-03-11 14:02:46 -040066 resp, body = self.create_image(name='New Remote Image',
67 container_format='bare',
68 disk_format='raw', is_public=True,
69 location='http://example.com'
afazekas4a96bf82013-03-25 16:07:38 +010070 '/someimage.iso',
71 properties={'key1': 'value1',
72 'key2': 'value2'})
Matthew Treinish72ea4422013-02-07 14:42:49 -050073 self.assertTrue('id' in body)
74 image_id = body.get('id')
Jay Pipes50677282012-01-06 15:39:20 -050075 self.created_images.append(image_id)
Matthew Treinish72ea4422013-02-07 14:42:49 -050076 self.assertEqual('New Remote Image', body.get('name'))
Matthew Treinish72ea4422013-02-07 14:42:49 -050077 self.assertTrue(body.get('is_public'))
Matthew Treinish72ea4422013-02-07 14:42:49 -050078 self.assertEqual('active', body.get('status'))
afazekas4a96bf82013-03-25 16:07:38 +010079 properties = body.get('properties')
80 self.assertEqual(properties['key1'], 'value1')
81 self.assertEqual(properties['key2'], 'value2')
Jay Pipes50677282012-01-06 15:39:20 -050082
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040083 @attr(type='gate')
Attila Fazekase72b7cd2013-03-26 18:34:21 +010084 def test_register_http_image(self):
Attila Fazekase72b7cd2013-03-26 18:34:21 +010085 resp, body = self.create_image(name='New Http Image',
86 container_format='bare',
87 disk_format='raw', is_public=True,
Sean Dague83401992013-05-06 17:46:36 -040088 copy_from=self.config.images.http_image)
Attila Fazekase72b7cd2013-03-26 18:34:21 +010089 self.assertTrue('id' in body)
90 image_id = body.get('id')
91 self.created_images.append(image_id)
92 self.assertEqual('New Http Image', body.get('name'))
93 self.assertTrue(body.get('is_public'))
94 self.client.wait_for_image_status(image_id, 'active')
95 resp, body = self.client.get_image(image_id)
96 self.assertEqual(resp['status'], '200')
Attila Fazekase72b7cd2013-03-26 18:34:21 +010097
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040098 @attr(type='gate')
hi2suresh75a20302013-04-09 09:17:06 +000099 def test_register_image_with_min_ram(self):
100 # Register an image with min ram
101 properties = {'prop1': 'val1'}
102 resp, body = self.create_image(name='New_image_with_min_ram',
103 container_format='bare',
104 disk_format='raw',
105 is_public=True,
106 min_ram=40,
107 properties=properties)
108 self.assertTrue('id' in body)
109 image_id = body.get('id')
110 self.created_images.append(image_id)
111 self.assertEqual('New_image_with_min_ram', body.get('name'))
112 self.assertTrue(body.get('is_public'))
113 self.assertEqual('queued', body.get('status'))
114 self.assertEqual(40, body.get('min_ram'))
115 for key, val in properties.items():
116 self.assertEqual(val, body.get('properties')[key])
117
Jay Pipes50677282012-01-06 15:39:20 -0500118
Matthew Treinishce3ef922013-03-11 14:02:46 -0400119class ListImagesTest(base.BaseV1ImageTest):
Jay Pipes50677282012-01-06 15:39:20 -0500120
121 """
122 Here we test the listing of image information
123 """
124
125 @classmethod
126 def setUpClass(cls):
Matthew Treinishce3ef922013-03-11 14:02:46 -0400127 super(ListImagesTest, cls).setUpClass()
Jay Pipes50677282012-01-06 15:39:20 -0500128
129 # We add a few images here to test the listing functionality of
130 # the images API
Attila Fazekas11795b52013-02-24 15:49:08 +0100131 img1 = cls._create_remote_image('one', 'bare', 'raw')
132 img2 = cls._create_remote_image('two', 'ami', 'ami')
133 img3 = cls._create_remote_image('dup', 'bare', 'raw')
134 img4 = cls._create_remote_image('dup', 'bare', 'raw')
135 img5 = cls._create_standard_image('1', 'ami', 'ami', 42)
136 img6 = cls._create_standard_image('2', 'ami', 'ami', 142)
137 img7 = cls._create_standard_image('33', 'bare', 'raw', 142)
138 img8 = cls._create_standard_image('33', 'bare', 'raw', 142)
139 cls.created_set = set(cls.created_images)
140 # 4x-4x remote image
141 cls.remote_set = set((img1, img2, img3, img4))
142 cls.standard_set = set((img5, img6, img7, img8))
143 # 5x bare, 3x ami
144 cls.bare_set = set((img1, img3, img4, img7, img8))
145 cls.ami_set = set((img2, img5, img6))
146 # 1x with size 42
147 cls.size42_set = set((img5,))
148 # 3x with size 142
149 cls.size142_set = set((img6, img7, img8))
150 # dup named
151 cls.dup_set = set((img3, img4))
Jay Pipes50677282012-01-06 15:39:20 -0500152
153 @classmethod
Attila Fazekas11795b52013-02-24 15:49:08 +0100154 def _create_remote_image(cls, name, container_format, disk_format):
Jay Pipes50677282012-01-06 15:39:20 -0500155 """
156 Create a new remote image and return the ID of the newly-registered
157 image
158 """
Attila Fazekas11795b52013-02-24 15:49:08 +0100159 name = 'New Remote Image %s' % name
160 location = 'http://example.com/someimage_%s.iso' % name
Matthew Treinishce3ef922013-03-11 14:02:46 -0400161 resp, image = cls.create_image(name=name,
162 container_format=container_format,
163 disk_format=disk_format,
164 is_public=True,
165 location=location)
Attila Fazekas11795b52013-02-24 15:49:08 +0100166 image_id = image['id']
Jay Pipes50677282012-01-06 15:39:20 -0500167 return image_id
168
169 @classmethod
Attila Fazekas11795b52013-02-24 15:49:08 +0100170 def _create_standard_image(cls, name, container_format,
171 disk_format, size):
Jay Pipes50677282012-01-06 15:39:20 -0500172 """
173 Create a new standard image and return the ID of the newly-registered
174 image. Note that the size of the new image is a random number between
175 1024 and 4096
176 """
Attila Fazekas11795b52013-02-24 15:49:08 +0100177 image_file = StringIO.StringIO('*' * size)
178 name = 'New Standard Image %s' % name
Matthew Treinishce3ef922013-03-11 14:02:46 -0400179 resp, image = cls.create_image(name=name,
180 container_format=container_format,
181 disk_format=disk_format,
182 is_public=True, data=image_file)
Attila Fazekas11795b52013-02-24 15:49:08 +0100183 image_id = image['id']
Jay Pipes50677282012-01-06 15:39:20 -0500184 return image_id
185
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400186 @attr(type='gate')
Jay Pipes50677282012-01-06 15:39:20 -0500187 def test_index_no_params(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500188 # Simple test to see all fixture images returned
Matthew Treinish72ea4422013-02-07 14:42:49 -0500189 resp, images_list = self.client.image_list()
190 self.assertEqual(resp['status'], '200')
191 image_list = map(lambda x: x['id'], images_list)
Attila Fazekas11795b52013-02-24 15:49:08 +0100192 for image_id in self.created_images:
193 self.assertTrue(image_id in image_list)
194
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400195 @attr(type='gate')
Attila Fazekas11795b52013-02-24 15:49:08 +0100196 def test_index_disk_format(self):
197 resp, images_list = self.client.image_list(disk_format='ami')
198 self.assertEqual(resp['status'], '200')
199 for image in images_list:
200 self.assertEqual(image['disk_format'], 'ami')
201 result_set = set(map(lambda x: x['id'], images_list))
202 self.assertTrue(self.ami_set <= result_set)
203 self.assertFalse(self.created_set - self.ami_set <= result_set)
204
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400205 @attr(type='gate')
Attila Fazekas11795b52013-02-24 15:49:08 +0100206 def test_index_container_format(self):
207 resp, images_list = self.client.image_list(container_format='bare')
208 self.assertEqual(resp['status'], '200')
209 for image in images_list:
210 self.assertEqual(image['container_format'], 'bare')
211 result_set = set(map(lambda x: x['id'], images_list))
212 self.assertTrue(self.bare_set <= result_set)
213 self.assertFalse(self.created_set - self.bare_set <= result_set)
214
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400215 @attr(type='gate')
Attila Fazekas11795b52013-02-24 15:49:08 +0100216 def test_index_max_size(self):
217 resp, images_list = self.client.image_list(size_max=42)
218 self.assertEqual(resp['status'], '200')
219 for image in images_list:
220 self.assertTrue(image['size'] <= 42)
221 result_set = set(map(lambda x: x['id'], images_list))
222 self.assertTrue(self.size42_set <= result_set)
223 self.assertFalse(self.created_set - self.size42_set <= result_set)
224
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400225 @attr(type='gate')
Attila Fazekas11795b52013-02-24 15:49:08 +0100226 def test_index_min_size(self):
227 resp, images_list = self.client.image_list(size_min=142)
228 self.assertEqual(resp['status'], '200')
229 for image in images_list:
230 self.assertTrue(image['size'] >= 142)
231 result_set = set(map(lambda x: x['id'], images_list))
232 self.assertTrue(self.size142_set <= result_set)
233 self.assertFalse(self.size42_set <= result_set)
234
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400235 @attr(type='gate')
Attila Fazekas11795b52013-02-24 15:49:08 +0100236 def test_index_status_active_detail(self):
237 resp, images_list = self.client.image_list_detail(status='active',
238 sort_key='size',
239 sort_dir='desc')
240 self.assertEqual(resp['status'], '200')
241 top_size = images_list[0]['size'] # We have non-zero sized images
242 for image in images_list:
243 size = image['size']
244 self.assertTrue(size <= top_size)
245 top_size = size
246 self.assertEqual(image['status'], 'active')
247
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400248 @attr(type='gate')
Attila Fazekas11795b52013-02-24 15:49:08 +0100249 def test_index_name(self):
250 resp, images_list = self.client.image_list_detail(
Sean Dague14c68182013-04-14 15:34:30 -0400251 name='New Remote Image dup')
Attila Fazekas11795b52013-02-24 15:49:08 +0100252 self.assertEqual(resp['status'], '200')
253 result_set = set(map(lambda x: x['id'], images_list))
254 for image in images_list:
255 self.assertEqual(image['name'], 'New Remote Image dup')
256 self.assertTrue(self.dup_set <= result_set)
257 self.assertFalse(self.created_set - self.dup_set <= result_set)