blob: 84bb6505a12d34123d65bcc34566f1e88d2f96b9 [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
Matthew Treinish481466b2012-12-20 17:16:01 -050020from tempest import clients
Matthew Treinish72ea4422013-02-07 14:42:49 -050021from tempest import exceptions
Attila Fazekas11795b52013-02-24 15:49:08 +010022import tempest.test
23from tempest.test import attr
Jay Pipes50677282012-01-06 15:39:20 -050024
25
Attila Fazekasdc216422013-01-29 15:12:14 +010026class CreateRegisterImagesTest(tempest.test.BaseTestCase):
Jay Pipes50677282012-01-06 15:39:20 -050027
28 """
29 Here we test the registration and creation of images
30 """
31
32 @classmethod
33 def setUpClass(cls):
Matthew Treinish72ea4422013-02-07 14:42:49 -050034 cls.os = clients.Manager()
35 cls.client = cls.os.image_client
Jay Pipes50677282012-01-06 15:39:20 -050036 cls.created_images = []
37
38 @classmethod
39 def tearDownClass(cls):
40 for image_id in cls.created_images:
Matthew Treinish72ea4422013-02-07 14:42:49 -050041 cls.client.delete(image_id)
Jay Pipes50677282012-01-06 15:39:20 -050042
Matthew Treinish72ea4422013-02-07 14:42:49 -050043 @attr(type='negative')
44 def test_register_with_invalid_container_format(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050045 # Negative tests for invalid data supplied to POST /images
Chris Yeohe04628e2013-02-25 17:12:21 +103046 self.assertRaises(exceptions.BadRequest, self.client.create_image,
47 'test', 'wrong', 'vhd')
Jay Pipes50677282012-01-06 15:39:20 -050048
Matthew Treinish72ea4422013-02-07 14:42:49 -050049 @attr(type='negative')
50 def test_register_with_invalid_disk_format(self):
Chris Yeohe04628e2013-02-25 17:12:21 +103051 self.assertRaises(exceptions.BadRequest, self.client.create_image,
52 'test', 'bare', 'wrong')
Jay Pipes50677282012-01-06 15:39:20 -050053
54 @attr(type='image')
55 def test_register_then_upload(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050056 # Register, then upload an image
Matthew Treinish72ea4422013-02-07 14:42:49 -050057 properties = {'prop1': 'val1'}
58 resp, body = self.client.create_image('New Name', 'bare', 'raw',
59 is_public=True,
60 properties=properties)
61 self.assertTrue('id' in body)
62 image_id = body.get('id')
Jay Pipes50677282012-01-06 15:39:20 -050063 self.created_images.append(image_id)
Matthew Treinish72ea4422013-02-07 14:42:49 -050064 self.assertTrue('name' in body)
65 self.assertEqual('New Name', body.get('name'))
66 self.assertTrue('is_public' in body)
67 self.assertTrue(body.get('is_public'))
68 self.assertTrue('status' in body)
69 self.assertEqual('queued', body.get('status'))
70 self.assertTrue('properties' in body)
71 for key, val in properties.items():
72 self.assertEqual(val, body.get('properties')[key])
Jay Pipes50677282012-01-06 15:39:20 -050073
74 # Now try uploading an image file
Matthew Treinish72ea4422013-02-07 14:42:49 -050075 image_file = StringIO.StringIO(('*' * 1024))
76 resp, body = self.client.update_image(image_id, data=image_file)
77 self.assertTrue('size' in body)
78 self.assertEqual(1024, body.get('size'))
Jay Pipes50677282012-01-06 15:39:20 -050079
80 @attr(type='image')
Jay Pipes50677282012-01-06 15:39:20 -050081 def test_register_remote_image(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050082 # Register a new remote image
Matthew Treinish72ea4422013-02-07 14:42:49 -050083 resp, body = self.client.create_image('New Remote Image', 'bare',
84 'raw', is_public=True,
85 location='http://example.com'
86 '/someimage.iso')
87 self.assertTrue('id' in body)
88 image_id = body.get('id')
Jay Pipes50677282012-01-06 15:39:20 -050089 self.created_images.append(image_id)
Matthew Treinish72ea4422013-02-07 14:42:49 -050090 self.assertTrue('name' in body)
91 self.assertEqual('New Remote Image', body.get('name'))
92 self.assertTrue('is_public' in body)
93 self.assertTrue(body.get('is_public'))
94 self.assertTrue('status' in body)
95 self.assertEqual('active', body.get('status'))
Jay Pipes50677282012-01-06 15:39:20 -050096
97
Attila Fazekasdc216422013-01-29 15:12:14 +010098class ListImagesTest(tempest.test.BaseTestCase):
Jay Pipes50677282012-01-06 15:39:20 -050099
100 """
101 Here we test the listing of image information
102 """
103
104 @classmethod
105 def setUpClass(cls):
Matthew Treinish72ea4422013-02-07 14:42:49 -0500106 cls.os = clients.Manager()
107 cls.client = cls.os.image_client
Jay Pipes50677282012-01-06 15:39:20 -0500108 cls.created_images = []
Jay Pipes50677282012-01-06 15:39:20 -0500109
110 # We add a few images here to test the listing functionality of
111 # the images API
Attila Fazekas11795b52013-02-24 15:49:08 +0100112 img1 = cls._create_remote_image('one', 'bare', 'raw')
113 img2 = cls._create_remote_image('two', 'ami', 'ami')
114 img3 = cls._create_remote_image('dup', 'bare', 'raw')
115 img4 = cls._create_remote_image('dup', 'bare', 'raw')
116 img5 = cls._create_standard_image('1', 'ami', 'ami', 42)
117 img6 = cls._create_standard_image('2', 'ami', 'ami', 142)
118 img7 = cls._create_standard_image('33', 'bare', 'raw', 142)
119 img8 = cls._create_standard_image('33', 'bare', 'raw', 142)
120 cls.created_set = set(cls.created_images)
121 # 4x-4x remote image
122 cls.remote_set = set((img1, img2, img3, img4))
123 cls.standard_set = set((img5, img6, img7, img8))
124 # 5x bare, 3x ami
125 cls.bare_set = set((img1, img3, img4, img7, img8))
126 cls.ami_set = set((img2, img5, img6))
127 # 1x with size 42
128 cls.size42_set = set((img5,))
129 # 3x with size 142
130 cls.size142_set = set((img6, img7, img8))
131 # dup named
132 cls.dup_set = set((img3, img4))
Jay Pipes50677282012-01-06 15:39:20 -0500133
134 @classmethod
135 def tearDownClass(cls):
136 for image_id in cls.created_images:
Matthew Treinish72ea4422013-02-07 14:42:49 -0500137 cls.client.delete_image(image_id)
138 cls.client.wait_for_resource_deletion(image_id)
Jay Pipes50677282012-01-06 15:39:20 -0500139
140 @classmethod
Attila Fazekas11795b52013-02-24 15:49:08 +0100141 def _create_remote_image(cls, name, container_format, disk_format):
Jay Pipes50677282012-01-06 15:39:20 -0500142 """
143 Create a new remote image and return the ID of the newly-registered
144 image
145 """
Attila Fazekas11795b52013-02-24 15:49:08 +0100146 name = 'New Remote Image %s' % name
147 location = 'http://example.com/someimage_%s.iso' % name
148 resp, image = cls.client.create_image(name,
149 container_format, disk_format,
150 is_public=True,
151 location=location)
152 image_id = image['id']
153 cls.created_images.append(image_id)
Jay Pipes50677282012-01-06 15:39:20 -0500154 return image_id
155
156 @classmethod
Attila Fazekas11795b52013-02-24 15:49:08 +0100157 def _create_standard_image(cls, name, container_format,
158 disk_format, size):
Jay Pipes50677282012-01-06 15:39:20 -0500159 """
160 Create a new standard image and return the ID of the newly-registered
161 image. Note that the size of the new image is a random number between
162 1024 and 4096
163 """
Attila Fazekas11795b52013-02-24 15:49:08 +0100164 image_file = StringIO.StringIO('*' * size)
165 name = 'New Standard Image %s' % name
166 resp, image = cls.client.create_image(name,
167 container_format, disk_format,
168 is_public=True, data=image_file)
169 image_id = image['id']
170 cls.created_images.append(image_id)
Jay Pipes50677282012-01-06 15:39:20 -0500171 return image_id
172
173 @attr(type='image')
174 def test_index_no_params(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500175 # Simple test to see all fixture images returned
Matthew Treinish72ea4422013-02-07 14:42:49 -0500176 resp, images_list = self.client.image_list()
177 self.assertEqual(resp['status'], '200')
178 image_list = map(lambda x: x['id'], images_list)
Attila Fazekas11795b52013-02-24 15:49:08 +0100179 for image_id in self.created_images:
180 self.assertTrue(image_id in image_list)
181
182 @attr(type='image')
183 def test_index_disk_format(self):
184 resp, images_list = self.client.image_list(disk_format='ami')
185 self.assertEqual(resp['status'], '200')
186 for image in images_list:
187 self.assertEqual(image['disk_format'], 'ami')
188 result_set = set(map(lambda x: x['id'], images_list))
189 self.assertTrue(self.ami_set <= result_set)
190 self.assertFalse(self.created_set - self.ami_set <= result_set)
191
192 @attr(type='image')
193 def test_index_container_format(self):
194 resp, images_list = self.client.image_list(container_format='bare')
195 self.assertEqual(resp['status'], '200')
196 for image in images_list:
197 self.assertEqual(image['container_format'], 'bare')
198 result_set = set(map(lambda x: x['id'], images_list))
199 self.assertTrue(self.bare_set <= result_set)
200 self.assertFalse(self.created_set - self.bare_set <= result_set)
201
202 @attr(type='image')
203 def test_index_max_size(self):
204 resp, images_list = self.client.image_list(size_max=42)
205 self.assertEqual(resp['status'], '200')
206 for image in images_list:
207 self.assertTrue(image['size'] <= 42)
208 result_set = set(map(lambda x: x['id'], images_list))
209 self.assertTrue(self.size42_set <= result_set)
210 self.assertFalse(self.created_set - self.size42_set <= result_set)
211
212 @attr(type='image')
213 def test_index_min_size(self):
214 resp, images_list = self.client.image_list(size_min=142)
215 self.assertEqual(resp['status'], '200')
216 for image in images_list:
217 self.assertTrue(image['size'] >= 142)
218 result_set = set(map(lambda x: x['id'], images_list))
219 self.assertTrue(self.size142_set <= result_set)
220 self.assertFalse(self.size42_set <= result_set)
221
222 @attr(type='image')
223 def test_index_status_active_detail(self):
224 resp, images_list = self.client.image_list_detail(status='active',
225 sort_key='size',
226 sort_dir='desc')
227 self.assertEqual(resp['status'], '200')
228 top_size = images_list[0]['size'] # We have non-zero sized images
229 for image in images_list:
230 size = image['size']
231 self.assertTrue(size <= top_size)
232 top_size = size
233 self.assertEqual(image['status'], 'active')
234
235 @attr(type='image')
236 def test_index_name(self):
237 resp, images_list = self.client.image_list_detail(
238 name='New Remote Image dup')
239 self.assertEqual(resp['status'], '200')
240 result_set = set(map(lambda x: x['id'], images_list))
241 for image in images_list:
242 self.assertEqual(image['name'], 'New Remote Image dup')
243 self.assertTrue(self.dup_set <= result_set)
244 self.assertFalse(self.created_set - self.dup_set <= result_set)