blob: 4a252064407c7a35e637c55bc262aedeba7b1e82 [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
Matthew Treinish71426682015-04-23 11:19:38 -040016import six
Miguel Lavalle2492d782013-06-16 15:04:15 -050017
18from tempest.api.network import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120019from tempest.common.utils import data_utils
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090020from tempest import test
Miguel Lavalle2492d782013-06-16 15:04:15 -050021
22
wanglianmin7a3b9702014-03-12 17:43:49 +080023class QuotasTest(base.BaseAdminNetworkTest):
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +000024 """Tests the following operations in the Neutron API:
Miguel Lavalle2492d782013-06-16 15:04:15 -050025
26 list quotas for tenants who have non-default quota values
27 show quotas for a specified tenant
28 update quotas for a specified tenant
29 reset quotas to default values for a specified tenant
30
wanglianmin7a3b9702014-03-12 17:43:49 +080031 v2.0 of the API is assumed.
32 It is also assumed that the per-tenant quota extension API is configured
33 in /etc/neutron/neutron.conf as follows:
Miguel Lavalle2492d782013-06-16 15:04:15 -050034
35 quota_driver = neutron.db.quota_db.DbQuotaDriver
36 """
37
38 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053039 def skip_checks(cls):
40 super(QuotasTest, cls).skip_checks()
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090041 if not test.is_extension_enabled('quotas', 'network'):
42 msg = "quotas extension not enabled."
43 raise cls.skipException(msg)
Rohan Kanadea565e452015-01-27 14:00:13 +053044
45 @classmethod
46 def setup_clients(cls):
47 super(QuotasTest, cls).setup_clients()
wanglianmin7a3b9702014-03-12 17:43:49 +080048 cls.identity_admin_client = cls.os_adm.identity_client
Miguel Lavalle2492d782013-06-16 15:04:15 -050049
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090050 def _check_quotas(self, new_quotas):
Miguel Lavalle2492d782013-06-16 15:04:15 -050051 # Add a tenant to conduct the test
Jamie Lennox15350172015-08-17 10:54:25 +100052 project = data_utils.rand_name('test_project_')
53 description = data_utils.rand_name('desc_')
54 project = self.identity_utils.create_project(name=project,
55 description=description)
56 project_id = project['id']
57 self.addCleanup(self.identity_utils.delete_project, project_id)
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090058
Miguel Lavalle2492d782013-06-16 15:04:15 -050059 # Change quotas for tenant
Jamie Lennox15350172015-08-17 10:54:25 +100060 quota_set = self.admin_client.update_quotas(project_id,
ghanshyam4807dc12015-06-26 19:02:17 +090061 **new_quotas)['quota']
Jamie Lennox15350172015-08-17 10:54:25 +100062 self.addCleanup(self.admin_client.reset_quotas, project_id)
Matthew Treinish71426682015-04-23 11:19:38 -040063 for key, value in six.iteritems(new_quotas):
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090064 self.assertEqual(value, quota_set[key])
65
Miguel Lavalle2492d782013-06-16 15:04:15 -050066 # Confirm our tenant is listed among tenants with non default quotas
David Kranz34e88122014-12-11 15:24:05 -050067 non_default_quotas = self.admin_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
74 # Confirm from API quotas were changed as requested for tenant
Jamie Lennox15350172015-08-17 10:54:25 +100075 quota_set = self.admin_client.show_quotas(project_id)
Eugene Nikanorov909ded12013-12-15 17:45:37 +040076 quota_set = quota_set['quota']
Matthew Treinish71426682015-04-23 11:19:38 -040077 for key, value in six.iteritems(new_quotas):
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
Jamie Lennox15350172015-08-17 10:54:25 +100081 self.admin_client.reset_quotas(project_id)
David Kranz34e88122014-12-11 15:24:05 -050082 non_default_quotas = self.admin_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'])
Evgeny Fedorukbff1c062013-12-04 07:43:22 -080085
Chris Hoge7579c1a2015-02-26 14:12:15 -080086 @test.idempotent_id('2390f766-836d-40ef-9aeb-e810d78207fb')
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090087 def test_quotas(self):
88 new_quotas = {'network': 0, 'security_group': 0}
89 self._check_quotas(new_quotas)