blob: 558e2ec132d33ee08bf6a8d34fa51b846196fdf7 [file] [log] [blame]
Jay Pipes50677282012-01-06 15:39:20 -05001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipes50677282012-01-06 15:39:20 -05004# 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
Attila Fazekas11795b52013-02-24 15:49:08 +010021from tempest.test import attr
Jay Pipes50677282012-01-06 15:39:20 -050022
23
Matthew Treinishce3ef922013-03-11 14:02:46 -040024class CreateRegisterImagesTest(base.BaseV1ImageTest):
25 """Here we test the registration and creation of images."""
Jay Pipes50677282012-01-06 15:39:20 -050026
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040027 @attr(type='gate')
Jay Pipes50677282012-01-06 15:39:20 -050028 def test_register_then_upload(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050029 # Register, then upload an image
Matthew Treinish72ea4422013-02-07 14:42:49 -050030 properties = {'prop1': 'val1'}
Matthew Treinishce3ef922013-03-11 14:02:46 -040031 resp, body = self.create_image(name='New Name',
32 container_format='bare',
33 disk_format='raw',
34 is_public=True,
35 properties=properties)
Attila Fazekase191cb12013-07-29 06:41:52 +020036 self.assertIn('id', body)
Matthew Treinish72ea4422013-02-07 14:42:49 -050037 image_id = body.get('id')
Matthew Treinish72ea4422013-02-07 14:42:49 -050038 self.assertEqual('New Name', body.get('name'))
Matthew Treinish72ea4422013-02-07 14:42:49 -050039 self.assertTrue(body.get('is_public'))
Matthew Treinish72ea4422013-02-07 14:42:49 -050040 self.assertEqual('queued', body.get('status'))
Matthew Treinish72ea4422013-02-07 14:42:49 -050041 for key, val in properties.items():
42 self.assertEqual(val, body.get('properties')[key])
Jay Pipes50677282012-01-06 15:39:20 -050043
44 # Now try uploading an image file
Matthew Treinish72ea4422013-02-07 14:42:49 -050045 image_file = StringIO.StringIO(('*' * 1024))
46 resp, body = self.client.update_image(image_id, data=image_file)
Attila Fazekase191cb12013-07-29 06:41:52 +020047 self.assertIn('size', body)
Matthew Treinish72ea4422013-02-07 14:42:49 -050048 self.assertEqual(1024, body.get('size'))
Jay Pipes50677282012-01-06 15:39:20 -050049
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040050 @attr(type='gate')
Jay Pipes50677282012-01-06 15:39:20 -050051 def test_register_remote_image(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050052 # Register a new remote image
Matthew Treinishce3ef922013-03-11 14:02:46 -040053 resp, body = self.create_image(name='New Remote Image',
54 container_format='bare',
55 disk_format='raw', is_public=True,
56 location='http://example.com'
afazekas4a96bf82013-03-25 16:07:38 +010057 '/someimage.iso',
58 properties={'key1': 'value1',
59 'key2': 'value2'})
Attila Fazekase191cb12013-07-29 06:41:52 +020060 self.assertIn('id', body)
Matthew Treinish72ea4422013-02-07 14:42:49 -050061 self.assertEqual('New Remote Image', body.get('name'))
Matthew Treinish72ea4422013-02-07 14:42:49 -050062 self.assertTrue(body.get('is_public'))
Matthew Treinish72ea4422013-02-07 14:42:49 -050063 self.assertEqual('active', body.get('status'))
afazekas4a96bf82013-03-25 16:07:38 +010064 properties = body.get('properties')
65 self.assertEqual(properties['key1'], 'value1')
66 self.assertEqual(properties['key2'], 'value2')
Jay Pipes50677282012-01-06 15:39:20 -050067
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040068 @attr(type='gate')
Attila Fazekase72b7cd2013-03-26 18:34:21 +010069 def test_register_http_image(self):
Attila Fazekase72b7cd2013-03-26 18:34:21 +010070 resp, body = self.create_image(name='New Http Image',
71 container_format='bare',
72 disk_format='raw', is_public=True,
Sean Dague83401992013-05-06 17:46:36 -040073 copy_from=self.config.images.http_image)
Attila Fazekase191cb12013-07-29 06:41:52 +020074 self.assertIn('id', body)
Attila Fazekase72b7cd2013-03-26 18:34:21 +010075 image_id = body.get('id')
Attila Fazekase72b7cd2013-03-26 18:34:21 +010076 self.assertEqual('New Http Image', body.get('name'))
77 self.assertTrue(body.get('is_public'))
78 self.client.wait_for_image_status(image_id, 'active')
79 resp, body = self.client.get_image(image_id)
80 self.assertEqual(resp['status'], '200')
Attila Fazekase72b7cd2013-03-26 18:34:21 +010081
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040082 @attr(type='gate')
hi2suresh75a20302013-04-09 09:17:06 +000083 def test_register_image_with_min_ram(self):
84 # Register an image with min ram
85 properties = {'prop1': 'val1'}
86 resp, body = self.create_image(name='New_image_with_min_ram',
87 container_format='bare',
88 disk_format='raw',
89 is_public=True,
90 min_ram=40,
91 properties=properties)
Attila Fazekase191cb12013-07-29 06:41:52 +020092 self.assertIn('id', body)
hi2suresh75a20302013-04-09 09:17:06 +000093 self.assertEqual('New_image_with_min_ram', body.get('name'))
94 self.assertTrue(body.get('is_public'))
95 self.assertEqual('queued', body.get('status'))
96 self.assertEqual(40, body.get('min_ram'))
97 for key, val in properties.items():
98 self.assertEqual(val, body.get('properties')[key])
ivan-zhu3867a1c2013-10-11 14:16:58 +080099 resp, body = self.client.delete_image(body['id'])
100 self.assertEqual('200', resp['status'])
hi2suresh75a20302013-04-09 09:17:06 +0000101
Jay Pipes50677282012-01-06 15:39:20 -0500102
Matthew Treinishce3ef922013-03-11 14:02:46 -0400103class ListImagesTest(base.BaseV1ImageTest):
Jay Pipes50677282012-01-06 15:39:20 -0500104
105 """
106 Here we test the listing of image information
107 """
108
109 @classmethod
110 def setUpClass(cls):
Matthew Treinishce3ef922013-03-11 14:02:46 -0400111 super(ListImagesTest, cls).setUpClass()
Jay Pipes50677282012-01-06 15:39:20 -0500112
113 # We add a few images here to test the listing functionality of
114 # the images API
Attila Fazekas11795b52013-02-24 15:49:08 +0100115 img1 = cls._create_remote_image('one', 'bare', 'raw')
116 img2 = cls._create_remote_image('two', 'ami', 'ami')
117 img3 = cls._create_remote_image('dup', 'bare', 'raw')
118 img4 = cls._create_remote_image('dup', 'bare', 'raw')
119 img5 = cls._create_standard_image('1', 'ami', 'ami', 42)
120 img6 = cls._create_standard_image('2', 'ami', 'ami', 142)
121 img7 = cls._create_standard_image('33', 'bare', 'raw', 142)
122 img8 = cls._create_standard_image('33', 'bare', 'raw', 142)
123 cls.created_set = set(cls.created_images)
124 # 4x-4x remote image
125 cls.remote_set = set((img1, img2, img3, img4))
126 cls.standard_set = set((img5, img6, img7, img8))
127 # 5x bare, 3x ami
128 cls.bare_set = set((img1, img3, img4, img7, img8))
129 cls.ami_set = set((img2, img5, img6))
130 # 1x with size 42
131 cls.size42_set = set((img5,))
132 # 3x with size 142
133 cls.size142_set = set((img6, img7, img8))
134 # dup named
135 cls.dup_set = set((img3, img4))
Jay Pipes50677282012-01-06 15:39:20 -0500136
137 @classmethod
Attila Fazekas11795b52013-02-24 15:49:08 +0100138 def _create_remote_image(cls, name, container_format, disk_format):
Jay Pipes50677282012-01-06 15:39:20 -0500139 """
140 Create a new remote image and return the ID of the newly-registered
141 image
142 """
Attila Fazekas11795b52013-02-24 15:49:08 +0100143 name = 'New Remote Image %s' % name
144 location = 'http://example.com/someimage_%s.iso' % name
Matthew Treinishce3ef922013-03-11 14:02:46 -0400145 resp, image = cls.create_image(name=name,
146 container_format=container_format,
147 disk_format=disk_format,
148 is_public=True,
149 location=location)
Attila Fazekas11795b52013-02-24 15:49:08 +0100150 image_id = image['id']
Jay Pipes50677282012-01-06 15:39:20 -0500151 return image_id
152
153 @classmethod
Attila Fazekas11795b52013-02-24 15:49:08 +0100154 def _create_standard_image(cls, name, container_format,
155 disk_format, size):
Jay Pipes50677282012-01-06 15:39:20 -0500156 """
157 Create a new standard image and return the ID of the newly-registered
158 image. Note that the size of the new image is a random number between
159 1024 and 4096
160 """
Attila Fazekas11795b52013-02-24 15:49:08 +0100161 image_file = StringIO.StringIO('*' * size)
162 name = 'New Standard Image %s' % name
Matthew Treinishce3ef922013-03-11 14:02:46 -0400163 resp, image = cls.create_image(name=name,
164 container_format=container_format,
165 disk_format=disk_format,
166 is_public=True, data=image_file)
Attila Fazekas11795b52013-02-24 15:49:08 +0100167 image_id = image['id']
Jay Pipes50677282012-01-06 15:39:20 -0500168 return image_id
169
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400170 @attr(type='gate')
Jay Pipes50677282012-01-06 15:39:20 -0500171 def test_index_no_params(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500172 # Simple test to see all fixture images returned
Matthew Treinish72ea4422013-02-07 14:42:49 -0500173 resp, images_list = self.client.image_list()
174 self.assertEqual(resp['status'], '200')
175 image_list = map(lambda x: x['id'], images_list)
Attila Fazekas11795b52013-02-24 15:49:08 +0100176 for image_id in self.created_images:
Attila Fazekase191cb12013-07-29 06:41:52 +0200177 self.assertIn(image_id, image_list)
Attila Fazekas11795b52013-02-24 15:49:08 +0100178
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400179 @attr(type='gate')
Attila Fazekas11795b52013-02-24 15:49:08 +0100180 def test_index_disk_format(self):
181 resp, images_list = self.client.image_list(disk_format='ami')
182 self.assertEqual(resp['status'], '200')
183 for image in images_list:
184 self.assertEqual(image['disk_format'], 'ami')
185 result_set = set(map(lambda x: x['id'], images_list))
186 self.assertTrue(self.ami_set <= result_set)
187 self.assertFalse(self.created_set - self.ami_set <= result_set)
188
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400189 @attr(type='gate')
Attila Fazekas11795b52013-02-24 15:49:08 +0100190 def test_index_container_format(self):
191 resp, images_list = self.client.image_list(container_format='bare')
192 self.assertEqual(resp['status'], '200')
193 for image in images_list:
194 self.assertEqual(image['container_format'], 'bare')
195 result_set = set(map(lambda x: x['id'], images_list))
196 self.assertTrue(self.bare_set <= result_set)
197 self.assertFalse(self.created_set - self.bare_set <= result_set)
198
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400199 @attr(type='gate')
Attila Fazekas11795b52013-02-24 15:49:08 +0100200 def test_index_max_size(self):
201 resp, images_list = self.client.image_list(size_max=42)
202 self.assertEqual(resp['status'], '200')
203 for image in images_list:
204 self.assertTrue(image['size'] <= 42)
205 result_set = set(map(lambda x: x['id'], images_list))
206 self.assertTrue(self.size42_set <= result_set)
207 self.assertFalse(self.created_set - self.size42_set <= result_set)
208
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400209 @attr(type='gate')
Attila Fazekas11795b52013-02-24 15:49:08 +0100210 def test_index_min_size(self):
211 resp, images_list = self.client.image_list(size_min=142)
212 self.assertEqual(resp['status'], '200')
213 for image in images_list:
214 self.assertTrue(image['size'] >= 142)
215 result_set = set(map(lambda x: x['id'], images_list))
216 self.assertTrue(self.size142_set <= result_set)
217 self.assertFalse(self.size42_set <= result_set)
218
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400219 @attr(type='gate')
Attila Fazekas11795b52013-02-24 15:49:08 +0100220 def test_index_status_active_detail(self):
221 resp, images_list = self.client.image_list_detail(status='active',
222 sort_key='size',
223 sort_dir='desc')
224 self.assertEqual(resp['status'], '200')
225 top_size = images_list[0]['size'] # We have non-zero sized images
226 for image in images_list:
227 size = image['size']
228 self.assertTrue(size <= top_size)
229 top_size = size
230 self.assertEqual(image['status'], 'active')
231
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -0400232 @attr(type='gate')
Attila Fazekas11795b52013-02-24 15:49:08 +0100233 def test_index_name(self):
234 resp, images_list = self.client.image_list_detail(
Sean Dague14c68182013-04-14 15:34:30 -0400235 name='New Remote Image dup')
Attila Fazekas11795b52013-02-24 15:49:08 +0100236 self.assertEqual(resp['status'], '200')
237 result_set = set(map(lambda x: x['id'], images_list))
238 for image in images_list:
239 self.assertEqual(image['name'], 'New Remote Image dup')
240 self.assertTrue(self.dup_set <= result_set)
241 self.assertFalse(self.created_set - self.dup_set <= result_set)