blob: 70711f5580ca4990a33d60abe5b3f91dbf5c8348 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Rohit Karajgi07599c52012-11-02 05:35:16 -07002# 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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log as logging
melanie witt74fa5052021-05-06 22:41:30 +000017import testtools
Matt Riedemann848805f2014-06-16 13:23:51 -070018from testtools import matchers
19
Sean Dague1937d092013-05-17 16:36:38 -040020from tempest.api.compute import base
Andrea Frittolie1ed6952017-09-14 06:31:52 -060021from tempest.common import identity
Matt Riedemann848805f2014-06-16 13:23:51 -070022from tempest.common import tempest_fixtures as fixtures
melanie witt74fa5052021-05-06 22:41:30 +000023from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080024from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080025from tempest.lib import decorators
Sean Dague86bd8422013-12-20 09:56:44 -050026
melanie witt74fa5052021-05-06 22:41:30 +000027CONF = config.CONF
Matt Riedemann848805f2014-06-16 13:23:51 -070028LOG = logging.getLogger(__name__)
29
Rohit Karajgi07599c52012-11-02 05:35:16 -070030
zhuflac4e4442018-08-06 15:38:59 +080031class QuotasAdminTestBase(base.BaseV2ComputeAdminTest):
Attila Fazekas430dae32013-10-17 15:19:32 +020032 force_tenant_isolation = True
Rohit Karajgi07599c52012-11-02 05:35:16 -070033
Matt Riedemann848805f2014-06-16 13:23:51 -070034 def setUp(self):
35 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
36 self.useFixture(fixtures.LockFixture('compute_quotas'))
zhuflac4e4442018-08-06 15:38:59 +080037 super(QuotasAdminTestBase, self).setUp()
Matt Riedemann848805f2014-06-16 13:23:51 -070038
Rohit Karajgi07599c52012-11-02 05:35:16 -070039 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053040 def setup_clients(cls):
zhuflac4e4442018-08-06 15:38:59 +080041 super(QuotasAdminTestBase, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020042 cls.adm_client = cls.os_admin.quotas_client
Rohan Kanade60b73092015-02-04 17:58:19 +053043
zhuflac4e4442018-08-06 15:38:59 +080044 def _get_updated_quotas(self):
45 # Verify that GET shows the updated quota set of project
Martin Kopec213d0a42023-11-30 10:28:14 +010046 project_name = data_utils.rand_name(
47 prefix=CONF.resource_name_prefix,
48 name='cpu_quota_project')
zhuflac4e4442018-08-06 15:38:59 +080049 project_desc = project_name + '-desc'
50 project = identity.identity_utils(self.os_admin).create_project(
51 name=project_name, description=project_desc)
52 project_id = project['id']
53 self.addCleanup(identity.identity_utils(self.os_admin).delete_project,
54 project_id)
55
56 self.adm_client.update_quota_set(project_id, ram='5120')
57 # Call show_quota_set with detail=true to cover the
58 # get_quota_set_details response schema for microversion tests
59 quota_set = self.adm_client.show_quota_set(
60 project_id, detail=True)['quota_set']
61 self.assertEqual(5120, quota_set['ram']['limit'])
62
63 # Verify that GET shows the updated quota set of user
Martin Kopec213d0a42023-11-30 10:28:14 +010064 user_name = data_utils.rand_name(
65 prefix=CONF.resource_name_prefix,
66 name='cpu_quota_user')
zhuflac4e4442018-08-06 15:38:59 +080067 password = data_utils.rand_password()
68 email = user_name + '@testmail.tm'
69 user = identity.identity_utils(self.os_admin).create_user(
70 username=user_name, password=password, project=project,
71 email=email)
72 user_id = user['id']
73 self.addCleanup(identity.identity_utils(self.os_admin).delete_user,
74 user_id)
75
76 self.adm_client.update_quota_set(project_id,
77 user_id=user_id,
78 ram='2048')
79 quota_set = self.adm_client.show_quota_set(
80 project_id, user_id=user_id)['quota_set']
81 self.assertEqual(2048, quota_set['ram'])
82
Rohan Kanade60b73092015-02-04 17:58:19 +053083 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010084 def resource_setup(cls):
zhuflac4e4442018-08-06 15:38:59 +080085 super(QuotasAdminTestBase, cls).resource_setup()
Attila Fazekas4ba36582013-02-12 08:26:17 +010086
Attila Fazekasf7f34f92013-08-01 17:01:44 +020087 # NOTE(afazekas): these test cases should always create and use a new
Attila Fazekas4ba36582013-02-12 08:26:17 +010088 # tenant most of them should be skipped if we can't do that
Andrea Frittoli9612e812014-03-13 10:57:26 +000089 cls.demo_tenant_id = cls.quotas_client.tenant_id
Rohit Karajgi07599c52012-11-02 05:35:16 -070090
zhufl2766ca82018-03-28 17:47:45 +080091 cls.default_quota_set = set(('metadata_items', 'ram', 'key_pairs',
92 'instances', 'cores',
93 'server_group_members', 'server_groups'))
94 if cls.is_requested_microversion_compatible('2.35'):
95 cls.default_quota_set = \
96 cls.default_quota_set | set(['fixed_ips', 'floating_ips',
97 'security_group_rules',
98 'security_groups'])
99 if cls.is_requested_microversion_compatible('2.56'):
100 cls.default_quota_set = \
101 cls.default_quota_set | set(['injected_file_content_bytes',
102 'injected_file_path_bytes',
103 'injected_files'])
Rohit Karajgi07599c52012-11-02 05:35:16 -0700104
zhuflac4e4442018-08-06 15:38:59 +0800105
106class QuotasAdminTestJSON(QuotasAdminTestBase):
zhufl4e726a62020-08-10 16:30:28 +0800107 """Test compute quotas by admin user"""
108
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800109 @decorators.idempotent_id('3b0a7c8f-cf58-46b8-a60c-715a32a8ba7d')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700110 def test_get_default_quotas(self):
zhufl4e726a62020-08-10 16:30:28 +0800111 """Test admin can get the default compute quota set for a project"""
Attila Fazekasd9aef1e2013-07-13 17:33:45 +0200112 expected_quota_set = self.default_quota_set | set(['id'])
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +0000113 quota_set = self.adm_client.show_default_quota_set(
ghanshyam52657872015-08-24 16:39:10 +0900114 self.demo_tenant_id)['quota_set']
Attila Fazekasd9aef1e2013-07-13 17:33:45 +0200115 self.assertEqual(quota_set['id'], self.demo_tenant_id)
Phil Day5f615392014-09-10 12:10:16 +0000116 for quota in expected_quota_set:
117 self.assertIn(quota, quota_set.keys())
Rohit Karajgi07599c52012-11-02 05:35:16 -0700118
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800119 @decorators.idempotent_id('55fbe2bf-21a9-435b-bbd2-4162b0ed799a')
melanie witt74fa5052021-05-06 22:41:30 +0000120 @testtools.skipIf(CONF.compute_feature_enabled.unified_limits,
121 'Legacy quota update not available with unified limits')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700122 def test_update_all_quota_resources_for_tenant(self):
zhufl4e726a62020-08-10 16:30:28 +0800123 """Test admin can update all the compute quota limits for a project"""
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +0000124 default_quota_set = self.adm_client.show_default_quota_set(
ghanshyam52657872015-08-24 16:39:10 +0900125 self.demo_tenant_id)['quota_set']
zhufl2766ca82018-03-28 17:47:45 +0800126 new_quota_set = {'metadata_items': 256, 'ram': 10240,
127 'key_pairs': 200, 'instances': 20,
128 'server_groups': 20,
129 'server_group_members': 20, 'cores': 2}
130 if self.is_requested_microversion_compatible('2.35'):
131 new_quota_set.update({'fixed_ips': 10, 'floating_ips': 20,
132 'security_group_rules': 20,
133 'security_groups': 20})
134 if self.is_requested_microversion_compatible('2.56'):
135 new_quota_set.update({'injected_file_content_bytes': 20480,
136 'injected_file_path_bytes': 512,
137 'injected_files': 10})
138
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700139 # Update limits for all quota resources
David Kranz3e4c28b2015-02-09 12:35:18 -0500140 quota_set = self.adm_client.update_quota_set(
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700141 self.demo_tenant_id,
gengjh01ba9cc2013-06-15 10:14:48 +0800142 force=True,
ghanshyam52657872015-08-24 16:39:10 +0900143 **new_quota_set)['quota_set']
gengjh01ba9cc2013-06-15 10:14:48 +0800144
145 default_quota_set.pop('id')
Matt Riedemannbc8dbd32013-08-02 14:02:12 -0700146 self.addCleanup(self.adm_client.update_quota_set,
gengjh01ba9cc2013-06-15 10:14:48 +0800147 self.demo_tenant_id, **default_quota_set)
Phil Day5f615392014-09-10 12:10:16 +0000148 for quota in new_quota_set:
149 self.assertIn(quota, quota_set.keys())
Rohit Karajgi07599c52012-11-02 05:35:16 -0700150
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200151 # TODO(afazekas): merge these test cases
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800152 @decorators.idempotent_id('ce9e0815-8091-4abd-8345-7fe5b85faa1d')
melanie witt74fa5052021-05-06 22:41:30 +0000153 @testtools.skipIf(CONF.compute_feature_enabled.unified_limits,
154 'Legacy quota update not available with unified limits')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700155 def test_get_updated_quotas(self):
zhufl4e726a62020-08-10 16:30:28 +0800156 """Test that GET shows the updated quota set of project"""
zhuflac4e4442018-08-06 15:38:59 +0800157 self._get_updated_quotas()
Attila Fazekasd9aef1e2013-07-13 17:33:45 +0200158
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800159 @decorators.idempotent_id('389d04f0-3a41-405f-9317-e5f86e3c44f0')
melanie witt74fa5052021-05-06 22:41:30 +0000160 @testtools.skipIf(CONF.compute_feature_enabled.unified_limits,
161 'Legacy quota update not available with unified limits')
Yuiko Takada2209cf52014-02-27 12:03:49 +0000162 def test_delete_quota(self):
zhufl4e726a62020-08-10 16:30:28 +0800163 """Test admin can delete the compute quota set for a project"""
Martin Kopec213d0a42023-11-30 10:28:14 +0100164 project_name = data_utils.rand_name(
165 prefix=CONF.resource_name_prefix,
166 name='ram_quota_project')
Jamie Lennox15350172015-08-17 10:54:25 +1000167 project_desc = project_name + '-desc'
Andrea Frittolie1ed6952017-09-14 06:31:52 -0600168 project = identity.identity_utils(self.os_admin).create_project(
169 name=project_name, description=project_desc)
Jamie Lennox15350172015-08-17 10:54:25 +1000170 project_id = project['id']
Andrea Frittolie1ed6952017-09-14 06:31:52 -0600171 self.addCleanup(identity.identity_utils(self.os_admin).delete_project,
172 project_id)
Jamie Lennox15350172015-08-17 10:54:25 +1000173 quota_set_default = (self.adm_client.show_quota_set(project_id)
ghanshyam52657872015-08-24 16:39:10 +0900174 ['quota_set'])
Yuiko Takada2209cf52014-02-27 12:03:49 +0000175 ram_default = quota_set_default['ram']
176
Jamie Lennox15350172015-08-17 10:54:25 +1000177 self.adm_client.update_quota_set(project_id, ram='5120')
Yuiko Takada2209cf52014-02-27 12:03:49 +0000178
Jamie Lennox15350172015-08-17 10:54:25 +1000179 self.adm_client.delete_quota_set(project_id)
Yuiko Takada2209cf52014-02-27 12:03:49 +0000180
Jamie Lennox15350172015-08-17 10:54:25 +1000181 quota_set_new = self.adm_client.show_quota_set(project_id)['quota_set']
Yuiko Takada2209cf52014-02-27 12:03:49 +0000182 self.assertEqual(ram_default, quota_set_new['ram'])
183
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530184
zhuflac4e4442018-08-06 15:38:59 +0800185class QuotasAdminTestV236(QuotasAdminTestBase):
zhufl4e726a62020-08-10 16:30:28 +0800186 """Test compute quotas with microversion greater than 2.35
187
zhuflac4e4442018-08-06 15:38:59 +0800188 # NOTE(gmann): This test tests the Quota APIs response schema
189 # for 2.36 microversion. No specific assert or behaviour verification
190 # is needed.
zhufl4e726a62020-08-10 16:30:28 +0800191 """
192
193 min_microversion = '2.36'
zhuflac4e4442018-08-06 15:38:59 +0800194
195 @decorators.idempotent_id('4268b5c9-92e5-4adc-acf1-3a2798f3d803')
melanie witt74fa5052021-05-06 22:41:30 +0000196 @testtools.skipIf(CONF.compute_feature_enabled.unified_limits,
197 'Legacy quota update not available with unified limits')
zhuflac4e4442018-08-06 15:38:59 +0800198 def test_get_updated_quotas(self):
zhufl4e726a62020-08-10 16:30:28 +0800199 """Test compute quotas API with microversion greater than 2.35
200
201 Checking compute quota update, get, get details APIs response schema.
202 """
zhuflac4e4442018-08-06 15:38:59 +0800203 self._get_updated_quotas()
204
205
206class QuotasAdminTestV257(QuotasAdminTestBase):
zhufl4e726a62020-08-10 16:30:28 +0800207 """Test compute quotas with microversion greater than 2.56
208
zhuflac4e4442018-08-06 15:38:59 +0800209 # NOTE(gmann): This test tests the Quota APIs response schema
210 # for 2.57 microversion. No specific assert or behaviour verification
211 # is needed.
zhufl4e726a62020-08-10 16:30:28 +0800212 """
213
214 min_microversion = '2.57'
zhuflac4e4442018-08-06 15:38:59 +0800215
216 @decorators.idempotent_id('e641e6c6-e86c-41a4-9e5c-9493c0ae47ad')
melanie witt74fa5052021-05-06 22:41:30 +0000217 @testtools.skipIf(CONF.compute_feature_enabled.unified_limits,
218 'Legacy quota update not available with unified limits')
zhuflac4e4442018-08-06 15:38:59 +0800219 def test_get_updated_quotas(self):
zhufl4e726a62020-08-10 16:30:28 +0800220 """Test compute quotas API with microversion greater than 2.56
221
222 Checking compute quota update, get, get details APIs response schema.
223 """
zhuflac4e4442018-08-06 15:38:59 +0800224 self._get_updated_quotas()
225
226
Matt Riedemann848805f2014-06-16 13:23:51 -0700227class QuotaClassesAdminTestJSON(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +0000228 """Tests the os-quota-class-sets API to update default quotas."""
Matt Riedemann848805f2014-06-16 13:23:51 -0700229
230 def setUp(self):
231 # All test cases in this class need to externally lock on doing
232 # anything with default quota values.
233 self.useFixture(fixtures.LockFixture('compute_quotas'))
234 super(QuotaClassesAdminTestJSON, self).setUp()
235
236 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +0100237 def resource_setup(cls):
238 super(QuotaClassesAdminTestJSON, cls).resource_setup()
Jordan Pittier8160d312017-04-18 11:52:23 +0200239 cls.adm_client = cls.os_admin.quota_classes_client
Matt Riedemann848805f2014-06-16 13:23:51 -0700240
241 def _restore_default_quotas(self, original_defaults):
242 LOG.debug("restoring quota class defaults")
zhufl138d2792017-08-21 14:49:44 +0800243 self.adm_client.update_quota_class_set('default', **original_defaults)
Matt Riedemann848805f2014-06-16 13:23:51 -0700244
Sean Daguee3e9da72014-07-09 07:11:59 -0400245 # NOTE(sdague): this test is problematic as it changes
246 # global state, and possibly needs to be part of a set of
247 # tests that get run all by themselves at the end under a
248 # 'danger' flag.
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800249 @decorators.idempotent_id('7932ab0f-5136-4075-b201-c0e2338df51a')
melanie witt74fa5052021-05-06 22:41:30 +0000250 @testtools.skipIf(CONF.compute_feature_enabled.unified_limits,
251 'Legacy quota update not available with unified limits')
Matt Riedemann848805f2014-06-16 13:23:51 -0700252 def test_update_default_quotas(self):
zhufl4e726a62020-08-10 16:30:28 +0800253 """Test updating default compute quota class set"""
zhufl2b1751e2019-04-23 16:41:35 +0800254 # get the current 'default' quota class values
ghanshyam52657872015-08-24 16:39:10 +0900255 body = (self.adm_client.show_quota_class_set('default')
256 ['quota_class_set'])
Matt Riedemann848805f2014-06-16 13:23:51 -0700257 self.assertEqual('default', body.pop('id'))
258 # restore the defaults when the test is done
259 self.addCleanup(self._restore_default_quotas, body.copy())
260 # increment all of the values for updating the default quota class
guo yunxian7bbbec12016-08-21 20:03:10 +0800261 for quota, default in body.items():
Sean Daguee3e9da72014-07-09 07:11:59 -0400262 # NOTE(sdague): we need to increment a lot, otherwise
zhufl0892cb22016-05-06 14:46:00 +0800263 # there is a real chance that we go from -1 (unlimited)
Sean Daguee3e9da72014-07-09 07:11:59 -0400264 # to a very small number which causes issues.
265 body[quota] = default + 100
zhufl2b1751e2019-04-23 16:41:35 +0800266 # update limits for the default quota class set
ghanshyam52657872015-08-24 16:39:10 +0900267 update_body = self.adm_client.update_quota_class_set(
268 'default', **body)['quota_class_set']
zhufl2b1751e2019-04-23 16:41:35 +0800269 # assert that the response has all of the changed values
Matt Riedemann848805f2014-06-16 13:23:51 -0700270 self.assertThat(update_body.items(),
271 matchers.ContainsAll(body.items()))
zhufl2b1751e2019-04-23 16:41:35 +0800272 # check quota values are changed
273 show_body = self.adm_client.show_quota_class_set(
274 'default')['quota_class_set']
275 self.assertThat(show_body.items(),
276 matchers.ContainsAll(body.items()))
Ghanshyam Manndc517e02021-12-16 15:36:31 -0600277
278
279class QuotaClassesAdmin257Test(QuotaClassesAdminTestJSON):
280 """Test compute quotas with microversion greater than 2.56
281
282 # NOTE(gmann): This test tests the Quota class APIs response schema
283 # for 2.57 microversion. No specific assert or behaviour verification
284 # is needed.
285 """
286
287 min_microversion = '2.57'