blob: ef5ebb6b85d15fb7f030f027bee3d9f2a2420128 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2013 OpenStack Foundation
Miguel Lavalle2492d782013-06-16 15:04:15 -05002# 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
jeremy.zhang1ac13b22018-02-09 15:17:21 +080016import testtools
17
Miguel Lavalle2492d782013-06-16 15:04:15 -050018from tempest.api.network import base
Andrea Frittolie1ed6952017-09-14 06:31:52 -060019from tempest.common import identity
Andrea Frittolicd368412017-08-14 21:37:56 +010020from tempest.common import utils
Ken'ichi Ohmichif50e4df2017-03-10 10:52:53 -080021from tempest.lib.common.utils import data_utils
Jordan Pittier9e227c52016-02-09 14:35:18 +010022from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080023from tempest.lib import decorators
Miguel Lavalle2492d782013-06-16 15:04:15 -050024
25
wanglianmin7a3b9702014-03-12 17:43:49 +080026class QuotasTest(base.BaseAdminNetworkTest):
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +000027 """Tests the following operations in the Neutron API:
Miguel Lavalle2492d782013-06-16 15:04:15 -050028
Sean Dagueed6e5862016-04-04 10:49:13 -040029 list quotas for projects who have non-default quota values
30 show quotas for a specified project
31 update quotas for a specified project
32 reset quotas to default values for a specified project
Miguel Lavalle2492d782013-06-16 15:04:15 -050033
wanglianmin7a3b9702014-03-12 17:43:49 +080034 v2.0 of the API is assumed.
Sean Dagueed6e5862016-04-04 10:49:13 -040035 It is also assumed that the per-project quota extension API is configured
wanglianmin7a3b9702014-03-12 17:43:49 +080036 in /etc/neutron/neutron.conf as follows:
Miguel Lavalle2492d782013-06-16 15:04:15 -050037
Brian Haleyc2a0eb92019-02-27 16:22:40 -050038 quota_driver = neutron.db.quota.driver.DbQuotaDriver
Miguel Lavalle2492d782013-06-16 15:04:15 -050039 """
40
41 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053042 def skip_checks(cls):
43 super(QuotasTest, cls).skip_checks()
Andrea Frittolicd368412017-08-14 21:37:56 +010044 if not utils.is_extension_enabled('quotas', 'network'):
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090045 msg = "quotas extension not enabled."
46 raise cls.skipException(msg)
Rohan Kanadea565e452015-01-27 14:00:13 +053047
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090048 def _check_quotas(self, new_quotas):
Sean Dagueed6e5862016-04-04 10:49:13 -040049 # Add a project to conduct the test
Jamie Lennox15350172015-08-17 10:54:25 +100050 project = data_utils.rand_name('test_project_')
51 description = data_utils.rand_name('desc_')
Andrea Frittolie1ed6952017-09-14 06:31:52 -060052 project = identity.identity_utils(self.os_admin).create_project(
53 name=project, description=description)
Jamie Lennox15350172015-08-17 10:54:25 +100054 project_id = project['id']
Andrea Frittolie1ed6952017-09-14 06:31:52 -060055 self.addCleanup(identity.identity_utils(self.os_admin).delete_project,
56 project_id)
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090057
Sean Dagueed6e5862016-04-04 10:49:13 -040058 # Change quotas for project
Ken'ichi Ohmichi756d8ff2015-12-15 09:47:54 +000059 quota_set = self.admin_quotas_client.update_quotas(
60 project_id, **new_quotas)['quota']
Jordan Pittier9e227c52016-02-09 14:35:18 +010061 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
62 self.admin_quotas_client.reset_quotas, project_id)
guo yunxian7bbbec12016-08-21 20:03:10 +080063 for key, value in new_quotas.items():
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090064 self.assertEqual(value, quota_set[key])
65
Sean Dagueed6e5862016-04-04 10:49:13 -040066 # Confirm our project is listed among projects with non default quotas
Ken'ichi Ohmichi756d8ff2015-12-15 09:47:54 +000067 non_default_quotas = self.admin_quotas_client.list_quotas()
Miguel Lavalle2492d782013-06-16 15:04:15 -050068 found = False
Eugene Nikanorov909ded12013-12-15 17:45:37 +040069 for qs in non_default_quotas['quotas']:
Jamie Lennox15350172015-08-17 10:54:25 +100070 if qs['tenant_id'] == project_id:
Miguel Lavalle2492d782013-06-16 15:04:15 -050071 found = True
72 self.assertTrue(found)
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090073
Sean Dagueed6e5862016-04-04 10:49:13 -040074 # Confirm from API quotas were changed as requested for project
Ken'ichi Ohmichi756d8ff2015-12-15 09:47:54 +000075 quota_set = self.admin_quotas_client.show_quotas(project_id)
Eugene Nikanorov909ded12013-12-15 17:45:37 +040076 quota_set = quota_set['quota']
guo yunxian7bbbec12016-08-21 20:03:10 +080077 for key, value in new_quotas.items():
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090078 self.assertEqual(value, quota_set[key])
79
Miguel Lavalle2492d782013-06-16 15:04:15 -050080 # Reset quotas to default and confirm
Ken'ichi Ohmichi756d8ff2015-12-15 09:47:54 +000081 self.admin_quotas_client.reset_quotas(project_id)
82 non_default_quotas = self.admin_quotas_client.list_quotas()
Eugene Nikanorov909ded12013-12-15 17:45:37 +040083 for q in non_default_quotas['quotas']:
Jamie Lennox15350172015-08-17 10:54:25 +100084 self.assertNotEqual(project_id, q['tenant_id'])
jeremy.zhang6e695c92017-12-21 23:52:48 +080085 quota_set = self.admin_quotas_client.show_quotas(project_id)['quota']
86 default_quotas = self.admin_quotas_client.show_default_quotas(
87 project_id)['quota']
88 self.assertEqual(default_quotas, quota_set)
Evgeny Fedorukbff1c062013-12-04 07:43:22 -080089
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080090 @decorators.idempotent_id('2390f766-836d-40ef-9aeb-e810d78207fb')
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090091 def test_quotas(self):
zhufl4765ce72016-09-18 17:18:19 +080092 new_quotas = {'network': 0, 'port': 0}
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090093 self._check_quotas(new_quotas)
jeremy.zhang1ac13b22018-02-09 15:17:21 +080094
95 @testtools.skipUnless(utils.is_extension_enabled(
96 'quota_details', 'network'), 'Quota details extension not enabled.')
97 @decorators.idempotent_id('7b05ec5f-bf44-43cb-b28f-ddd72a824288')
98 def test_show_quota_details(self):
99 # Show quota details for an existing project
100 quota_details = self.admin_quotas_client.show_quota_details(
101 self.admin_quotas_client.tenant_id)['quota']
102 expected_keys = ['used', 'limit', 'reserved']
103 for resource_type in quota_details:
104 for key in expected_keys:
105 self.assertIn(key, quota_details[resource_type])