blob: df4624c738d63844697e6d401582b3e8c80552d0 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +090016import uuid
17
Matthew Treinish01472ff2015-02-20 17:26:52 -050018from tempest_lib.common.utils import data_utils
19from tempest_lib import exceptions as lib_exc
20
Sean Dague1937d092013-05-17 16:36:38 -040021from tempest.api.compute import base
Matthew Treinishe3d26142013-11-26 19:14:58 +000022from tempest import test
Rohit Karajgi03530292012-04-24 17:00:50 -070023
24
ivan-zhuf2b00502013-10-18 10:06:52 +080025class FlavorsAdminTestJSON(base.BaseV2ComputeAdminTest):
Rohit Karajgi03530292012-04-24 17:00:50 -070026
27 """
28 Tests Flavors API Create and Delete that require admin privileges
29 """
30
rajalakshmi-ganesanf344cc32012-12-31 20:02:27 +053031 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053032 def skip_checks(cls):
33 super(FlavorsAdminTestJSON, cls).skip_checks()
Ken'ichi Ohmichia7e68712014-05-06 10:47:26 +090034 if not test.is_extension_enabled('OS-FLV-EXT-DATA', 'compute'):
35 msg = "OS-FLV-EXT-DATA extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +080036 raise cls.skipException(msg)
Rohit Karajgi03530292012-04-24 17:00:50 -070037
Rohan Kanade60b73092015-02-04 17:58:19 +053038 @classmethod
39 def setup_clients(cls):
40 super(FlavorsAdminTestJSON, cls).setup_clients()
Attila Fazekas4ba36582013-02-12 08:26:17 +010041 cls.client = cls.os_adm.flavors_client
afazekascda40822013-03-25 16:50:41 +010042 cls.user_client = cls.os.flavors_client
Rohan Kanade60b73092015-02-04 17:58:19 +053043
44 @classmethod
45 def resource_setup(cls):
46 super(FlavorsAdminTestJSON, cls).resource_setup()
47
Chris Yeoh8abacf32013-01-21 17:08:32 +103048 cls.flavor_name_prefix = 'test_flavor_'
Jay Pipesf38eaac2012-06-21 13:37:35 -040049 cls.ram = 512
50 cls.vcpus = 1
51 cls.disk = 10
52 cls.ephemeral = 10
Jay Pipesf38eaac2012-06-21 13:37:35 -040053 cls.swap = 1024
rajalakshmi-ganesanf344cc32012-12-31 20:02:27 +053054 cls.rxtx = 2
Rohit Karajgi03530292012-04-24 17:00:50 -070055
Attila Fazekas2883fd52013-03-10 12:05:21 +010056 def flavor_clean_up(self, flavor_id):
David Kranz2fa77b22015-02-09 11:39:50 -050057 self.client.delete_flavor(flavor_id)
Attila Fazekas2883fd52013-03-10 12:05:21 +010058 self.client.wait_for_resource_deletion(flavor_id)
59
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +090060 def _create_flavor(self, flavor_id):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050061 # Create a flavor and ensure it is listed
62 # This operation requires the user to have 'admin' role
Masayuki Igawa259c1132013-10-31 17:48:44 +090063 flavor_name = data_utils.rand_name(self.flavor_name_prefix)
Chris Yeoh8abacf32013-01-21 17:08:32 +103064
Attila Fazekasf7f34f92013-08-01 17:01:44 +020065 # Create the flavor
David Kranz2fa77b22015-02-09 11:39:50 -050066 flavor = self.client.create_flavor(flavor_name,
67 self.ram, self.vcpus,
68 self.disk,
69 flavor_id,
70 ephemeral=self.ephemeral,
71 swap=self.swap,
72 rxtx=self.rxtx)
Attila Fazekas2883fd52013-03-10 12:05:21 +010073 self.addCleanup(self.flavor_clean_up, flavor['id'])
Attila Fazekas2883fd52013-03-10 12:05:21 +010074 self.assertEqual(flavor['name'], flavor_name)
75 self.assertEqual(flavor['vcpus'], self.vcpus)
76 self.assertEqual(flavor['disk'], self.disk)
77 self.assertEqual(flavor['ram'], self.ram)
Attila Fazekas2883fd52013-03-10 12:05:21 +010078 self.assertEqual(flavor['swap'], self.swap)
79 self.assertEqual(flavor['rxtx_factor'], self.rxtx)
80 self.assertEqual(flavor['OS-FLV-EXT-DATA:ephemeral'],
81 self.ephemeral)
ivan-zhuae7c7c52013-10-21 22:13:22 +080082 self.assertEqual(flavor['os-flavor-access:is_public'], True)
Rohit Karajgi03530292012-04-24 17:00:50 -070083
Attila Fazekasf7f34f92013-08-01 17:01:44 +020084 # Verify flavor is retrieved
David Kranz2fa77b22015-02-09 11:39:50 -050085 flavor = self.client.get_flavor_details(flavor['id'])
Attila Fazekas2883fd52013-03-10 12:05:21 +010086 self.assertEqual(flavor['name'], flavor_name)
Rohit Karajgi03530292012-04-24 17:00:50 -070087
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +090088 return flavor['id']
89
Matthew Treinishe3d26142013-11-26 19:14:58 +000090 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080091 @test.idempotent_id('8b4330e1-12c4-4554-9390-e6639971f086')
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +090092 def test_create_flavor_with_int_id(self):
93 flavor_id = data_utils.rand_int_id(start=1000)
94 new_flavor_id = self._create_flavor(flavor_id)
95 self.assertEqual(new_flavor_id, str(flavor_id))
96
Matthew Treinishe3d26142013-11-26 19:14:58 +000097 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080098 @test.idempotent_id('94c9bb4e-2c2a-4f3c-bb1f-5f0daf918e6d')
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +090099 def test_create_flavor_with_uuid_id(self):
100 flavor_id = str(uuid.uuid4())
101 new_flavor_id = self._create_flavor(flavor_id)
102 self.assertEqual(new_flavor_id, flavor_id)
103
Matthew Treinishe3d26142013-11-26 19:14:58 +0000104 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800105 @test.idempotent_id('f83fe669-6758-448a-a85e-32d351f36fe0')
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +0900106 def test_create_flavor_with_none_id(self):
107 # If nova receives a request with None as flavor_id,
108 # nova generates flavor_id of uuid.
109 flavor_id = None
110 new_flavor_id = self._create_flavor(flavor_id)
111 self.assertEqual(new_flavor_id, str(uuid.UUID(new_flavor_id)))
112
Matthew Treinishe3d26142013-11-26 19:14:58 +0000113 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800114 @test.idempotent_id('8261d7b0-be58-43ec-a2e5-300573c3f6c5')
Rohit Karajgi03530292012-04-24 17:00:50 -0700115 def test_create_flavor_verify_entry_in_list_details(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500116 # Create a flavor and ensure it's details are listed
117 # This operation requires the user to have 'admin' role
Masayuki Igawa259c1132013-10-31 17:48:44 +0900118 flavor_name = data_utils.rand_name(self.flavor_name_prefix)
119 new_flavor_id = data_utils.rand_int_id(start=1000)
Chris Yeoh8abacf32013-01-21 17:08:32 +1030120
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200121 # Create the flavor
David Kranz2fa77b22015-02-09 11:39:50 -0500122 flavor = self.client.create_flavor(flavor_name,
123 self.ram, self.vcpus,
124 self.disk,
125 new_flavor_id,
126 ephemeral=self.ephemeral,
127 swap=self.swap,
128 rxtx=self.rxtx)
Attila Fazekas2883fd52013-03-10 12:05:21 +0100129 self.addCleanup(self.flavor_clean_up, flavor['id'])
130 flag = False
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200131 # Verify flavor is retrieved
David Kranz2fa77b22015-02-09 11:39:50 -0500132 flavors = self.client.list_flavors_with_detail()
Attila Fazekas2883fd52013-03-10 12:05:21 +0100133 for flavor in flavors:
134 if flavor['name'] == flavor_name:
135 flag = True
136 self.assertTrue(flag)
Rohit Karajgi03530292012-04-24 17:00:50 -0700137
Matthew Treinishe3d26142013-11-26 19:14:58 +0000138 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800139 @test.idempotent_id('63dc64e6-2e79-4fdf-868f-85500d308d66')
rajalakshmi-ganesanf344cc32012-12-31 20:02:27 +0530140 def test_create_list_flavor_without_extra_data(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200141 # Create a flavor and ensure it is listed
142 # This operation requires the user to have 'admin' role
ivan-zhuae7c7c52013-10-21 22:13:22 +0800143
144 def verify_flavor_response_extension(flavor):
145 # check some extensions for the flavor create/show/detail response
146 self.assertEqual(flavor['swap'], '')
147 self.assertEqual(int(flavor['rxtx_factor']), 1)
148 self.assertEqual(int(flavor['OS-FLV-EXT-DATA:ephemeral']), 0)
149 self.assertEqual(flavor['os-flavor-access:is_public'], True)
150
Masayuki Igawa259c1132013-10-31 17:48:44 +0900151 flavor_name = data_utils.rand_name(self.flavor_name_prefix)
152 new_flavor_id = data_utils.rand_int_id(start=1000)
Chris Yeoh8abacf32013-01-21 17:08:32 +1030153
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200154 # Create the flavor
David Kranz2fa77b22015-02-09 11:39:50 -0500155 flavor = self.client.create_flavor(flavor_name,
156 self.ram, self.vcpus,
157 self.disk,
158 new_flavor_id)
Attila Fazekas2883fd52013-03-10 12:05:21 +0100159 self.addCleanup(self.flavor_clean_up, flavor['id'])
Attila Fazekas2883fd52013-03-10 12:05:21 +0100160 self.assertEqual(flavor['name'], flavor_name)
161 self.assertEqual(flavor['ram'], self.ram)
162 self.assertEqual(flavor['vcpus'], self.vcpus)
163 self.assertEqual(flavor['disk'], self.disk)
164 self.assertEqual(int(flavor['id']), new_flavor_id)
ivan-zhuae7c7c52013-10-21 22:13:22 +0800165 verify_flavor_response_extension(flavor)
rajalakshmi-ganesanf344cc32012-12-31 20:02:27 +0530166
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200167 # Verify flavor is retrieved
David Kranz2fa77b22015-02-09 11:39:50 -0500168 flavor = self.client.get_flavor_details(new_flavor_id)
Attila Fazekas2883fd52013-03-10 12:05:21 +0100169 self.assertEqual(flavor['name'], flavor_name)
ivan-zhuae7c7c52013-10-21 22:13:22 +0800170 verify_flavor_response_extension(flavor)
171
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200172 # Check if flavor is present in list
David Kranz2fa77b22015-02-09 11:39:50 -0500173 flavors = self.user_client.list_flavors_with_detail()
Attila Fazekas2883fd52013-03-10 12:05:21 +0100174 for flavor in flavors:
175 if flavor['name'] == flavor_name:
ivan-zhuae7c7c52013-10-21 22:13:22 +0800176 verify_flavor_response_extension(flavor)
Attila Fazekas2883fd52013-03-10 12:05:21 +0100177 flag = True
178 self.assertTrue(flag)
rajalakshmi-ganesanf344cc32012-12-31 20:02:27 +0530179
Matthew Treinishe3d26142013-11-26 19:14:58 +0000180 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800181 @test.idempotent_id('be6cc18c-7c5d-48c0-ac16-17eaf03c54eb')
Sumanth Nagadavalli3d955d92013-08-13 15:16:30 +0530182 def test_list_non_public_flavor(self):
Santiago Baldassin7f989162014-03-19 12:02:47 -0300183 # Create a flavor with os-flavor-access:is_public false.
184 # The flavor should not be present in list_details as the
185 # tenant is not automatically added access list.
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200186 # This operation requires the user to have 'admin' role
Masayuki Igawa259c1132013-10-31 17:48:44 +0900187 flavor_name = data_utils.rand_name(self.flavor_name_prefix)
188 new_flavor_id = data_utils.rand_int_id(start=1000)
Chris Yeoh8abacf32013-01-21 17:08:32 +1030189
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200190 # Create the flavor
David Kranz2fa77b22015-02-09 11:39:50 -0500191 flavor = self.client.create_flavor(flavor_name,
192 self.ram, self.vcpus,
193 self.disk,
194 new_flavor_id,
195 is_public="False")
Attila Fazekas2883fd52013-03-10 12:05:21 +0100196 self.addCleanup(self.flavor_clean_up, flavor['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200197 # Verify flavor is retrieved
Sumanth Nagadavalli3d955d92013-08-13 15:16:30 +0530198 flag = False
David Kranz2fa77b22015-02-09 11:39:50 -0500199 flavors = self.client.list_flavors_with_detail()
Attila Fazekas2883fd52013-03-10 12:05:21 +0100200 for flavor in flavors:
201 if flavor['name'] == flavor_name:
202 flag = True
Santiago Baldassin7f989162014-03-19 12:02:47 -0300203 self.assertFalse(flag)
Sumanth Nagadavalli3d955d92013-08-13 15:16:30 +0530204
205 # Verify flavor is not retrieved with other user
206 flag = False
David Kranz2fa77b22015-02-09 11:39:50 -0500207 flavors = self.user_client.list_flavors_with_detail()
Sumanth Nagadavalli3d955d92013-08-13 15:16:30 +0530208 for flavor in flavors:
209 if flavor['name'] == flavor_name:
210 flag = True
Attila Fazekas2883fd52013-03-10 12:05:21 +0100211 self.assertFalse(flag)
rajalakshmi-ganesanf344cc32012-12-31 20:02:27 +0530212
Matthew Treinishe3d26142013-11-26 19:14:58 +0000213 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800214 @test.idempotent_id('bcc418ef-799b-47cc-baa1-ce01368b8987')
Ken'ichi Ohmichi32b1e6c2013-09-06 12:07:07 +0900215 def test_create_server_with_non_public_flavor(self):
216 # Create a flavor with os-flavor-access:is_public false
Masayuki Igawa259c1132013-10-31 17:48:44 +0900217 flavor_name = data_utils.rand_name(self.flavor_name_prefix)
218 new_flavor_id = data_utils.rand_int_id(start=1000)
Ken'ichi Ohmichi32b1e6c2013-09-06 12:07:07 +0900219
220 # Create the flavor
David Kranz2fa77b22015-02-09 11:39:50 -0500221 flavor = self.client.create_flavor(flavor_name,
222 self.ram, self.vcpus,
223 self.disk,
224 new_flavor_id,
225 is_public="False")
Ken'ichi Ohmichi32b1e6c2013-09-06 12:07:07 +0900226 self.addCleanup(self.flavor_clean_up, flavor['id'])
Ken'ichi Ohmichi32b1e6c2013-09-06 12:07:07 +0900227
228 # Verify flavor is not used by other user
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900229 self.assertRaises(lib_exc.BadRequest,
Ken'ichi Ohmichi32b1e6c2013-09-06 12:07:07 +0900230 self.os.servers_client.create_server,
231 'test', self.image_ref, flavor['id'])
232
Matthew Treinishe3d26142013-11-26 19:14:58 +0000233 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800234 @test.idempotent_id('b345b196-bfbd-4231-8ac1-6d7fe15ff3a3')
rajalakshmi-ganesanf344cc32012-12-31 20:02:27 +0530235 def test_list_public_flavor_with_other_user(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200236 # Create a Flavor with public access.
237 # Try to List/Get flavor with another user
Masayuki Igawa259c1132013-10-31 17:48:44 +0900238 flavor_name = data_utils.rand_name(self.flavor_name_prefix)
239 new_flavor_id = data_utils.rand_int_id(start=1000)
Chris Yeoh8abacf32013-01-21 17:08:32 +1030240
Matthew Treinishc795b9e2014-06-09 17:01:10 -0400241 # Create the flavor
David Kranz2fa77b22015-02-09 11:39:50 -0500242 flavor = self.client.create_flavor(flavor_name,
243 self.ram, self.vcpus,
244 self.disk,
245 new_flavor_id,
246 is_public="True")
Attila Fazekas2883fd52013-03-10 12:05:21 +0100247 self.addCleanup(self.flavor_clean_up, flavor['id'])
248 flag = False
249 self.new_client = self.flavors_client
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200250 # Verify flavor is retrieved with new user
David Kranz2fa77b22015-02-09 11:39:50 -0500251 flavors = self.new_client.list_flavors_with_detail()
Attila Fazekas2883fd52013-03-10 12:05:21 +0100252 for flavor in flavors:
253 if flavor['name'] == flavor_name:
254 flag = True
255 self.assertTrue(flag)
rajalakshmi-ganesanf344cc32012-12-31 20:02:27 +0530256
Matthew Treinishe3d26142013-11-26 19:14:58 +0000257 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800258 @test.idempotent_id('fb9cbde6-3a0e-41f2-a983-bdb0a823c44e')
Tiago Mello0d835d22013-02-06 13:57:50 -0500259 def test_is_public_string_variations(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +0900260 flavor_id_not_public = data_utils.rand_int_id(start=1000)
261 flavor_name_not_public = data_utils.rand_name(self.flavor_name_prefix)
262 flavor_id_public = data_utils.rand_int_id(start=1000)
263 flavor_name_public = data_utils.rand_name(self.flavor_name_prefix)
Tiago Mello0d835d22013-02-06 13:57:50 -0500264
Attila Fazekas2883fd52013-03-10 12:05:21 +0100265 # Create a non public flavor
David Kranz2fa77b22015-02-09 11:39:50 -0500266 flavor = self.client.create_flavor(flavor_name_not_public,
267 self.ram, self.vcpus,
268 self.disk,
269 flavor_id_not_public,
270 is_public="False")
Attila Fazekas2883fd52013-03-10 12:05:21 +0100271 self.addCleanup(self.flavor_clean_up, flavor['id'])
Tiago Mello0d835d22013-02-06 13:57:50 -0500272
Attila Fazekas2883fd52013-03-10 12:05:21 +0100273 # Create a public flavor
David Kranz2fa77b22015-02-09 11:39:50 -0500274 flavor = self.client.create_flavor(flavor_name_public,
275 self.ram, self.vcpus,
276 self.disk,
277 flavor_id_public,
278 is_public="True")
Attila Fazekas2883fd52013-03-10 12:05:21 +0100279 self.addCleanup(self.flavor_clean_up, flavor['id'])
Tiago Mello0d835d22013-02-06 13:57:50 -0500280
Attila Fazekas2883fd52013-03-10 12:05:21 +0100281 def _flavor_lookup(flavors, flavor_name):
282 for flavor in flavors:
283 if flavor['name'] == flavor_name:
284 return flavor
285 return None
Tiago Mello0d835d22013-02-06 13:57:50 -0500286
Attila Fazekas2883fd52013-03-10 12:05:21 +0100287 def _test_string_variations(variations, flavor_name):
288 for string in variations:
289 params = {'is_public': string}
David Kranz2fa77b22015-02-09 11:39:50 -0500290 flavors = self.client.list_flavors_with_detail(params)
Attila Fazekas2883fd52013-03-10 12:05:21 +0100291 flavor = _flavor_lookup(flavors, flavor_name)
Ionuț Arțăriși7f7d4522013-08-21 11:47:47 +0200292 self.assertIsNotNone(flavor)
Tiago Mello0d835d22013-02-06 13:57:50 -0500293
Attila Fazekas2883fd52013-03-10 12:05:21 +0100294 _test_string_variations(['f', 'false', 'no', '0'],
295 flavor_name_not_public)
Tiago Mello0d835d22013-02-06 13:57:50 -0500296
Attila Fazekas2883fd52013-03-10 12:05:21 +0100297 _test_string_variations(['t', 'true', 'yes', '1'],
298 flavor_name_public)
Tiago Mello0d835d22013-02-06 13:57:50 -0500299
Matthew Treinishe3d26142013-11-26 19:14:58 +0000300 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800301 @test.idempotent_id('3b541a2e-2ac2-4b42-8b8d-ba6e22fcd4da')
Zhi Kun Liu20f13222013-09-03 00:36:38 +0800302 def test_create_flavor_using_string_ram(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +0900303 flavor_name = data_utils.rand_name(self.flavor_name_prefix)
304 new_flavor_id = data_utils.rand_int_id(start=1000)
Zhi Kun Liu20f13222013-09-03 00:36:38 +0800305
Ken'ichi Ohmichi2d2d4d92014-10-29 05:10:24 +0000306 ram = "1024"
David Kranz2fa77b22015-02-09 11:39:50 -0500307 flavor = self.client.create_flavor(flavor_name,
308 ram, self.vcpus,
309 self.disk,
310 new_flavor_id)
Zhi Kun Liu20f13222013-09-03 00:36:38 +0800311 self.addCleanup(self.flavor_clean_up, flavor['id'])
Zhi Kun Liu20f13222013-09-03 00:36:38 +0800312 self.assertEqual(flavor['name'], flavor_name)
313 self.assertEqual(flavor['vcpus'], self.vcpus)
314 self.assertEqual(flavor['disk'], self.disk)
315 self.assertEqual(flavor['ram'], int(ram))
316 self.assertEqual(int(flavor['id']), new_flavor_id)