blob: cb113a7483b1ac90b28e6d683cede646dc63ca90 [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):
Miguel Lavalle2492d782013-06-16 15:04:15 -050024 """
25 Tests the following operations in the Neutron API using the REST client for
26 Neutron:
27
28 list quotas for tenants who have non-default quota values
29 show quotas for a specified tenant
30 update quotas for a specified tenant
31 reset quotas to default values for a specified tenant
32
wanglianmin7a3b9702014-03-12 17:43:49 +080033 v2.0 of the API is assumed.
34 It is also assumed that the per-tenant quota extension API is configured
35 in /etc/neutron/neutron.conf as follows:
Miguel Lavalle2492d782013-06-16 15:04:15 -050036
37 quota_driver = neutron.db.quota_db.DbQuotaDriver
38 """
39
40 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053041 def skip_checks(cls):
42 super(QuotasTest, cls).skip_checks()
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090043 if not test.is_extension_enabled('quotas', 'network'):
44 msg = "quotas extension not enabled."
45 raise cls.skipException(msg)
Rohan Kanadea565e452015-01-27 14:00:13 +053046
47 @classmethod
48 def setup_clients(cls):
49 super(QuotasTest, cls).setup_clients()
wanglianmin7a3b9702014-03-12 17:43:49 +080050 cls.identity_admin_client = cls.os_adm.identity_client
Miguel Lavalle2492d782013-06-16 15:04:15 -050051
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090052 def _check_quotas(self, new_quotas):
Miguel Lavalle2492d782013-06-16 15:04:15 -050053 # Add a tenant to conduct the test
Masayuki Igawa259c1132013-10-31 17:48:44 +090054 test_tenant = data_utils.rand_name('test_tenant_')
55 test_description = data_utils.rand_name('desc_')
David Kranzb7afa922014-12-30 10:56:26 -050056 tenant = self.identity_admin_client.create_tenant(
Miguel Lavalle2492d782013-06-16 15:04:15 -050057 name=test_tenant,
58 description=test_description)
59 tenant_id = tenant['id']
60 self.addCleanup(self.identity_admin_client.delete_tenant, tenant_id)
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090061
Miguel Lavalle2492d782013-06-16 15:04:15 -050062 # Change quotas for tenant
David Kranz34e88122014-12-11 15:24:05 -050063 quota_set = self.admin_client.update_quotas(tenant_id,
64 **new_quotas)
Miguel Lavalle2492d782013-06-16 15:04:15 -050065 self.addCleanup(self.admin_client.reset_quotas, tenant_id)
Matthew Treinish71426682015-04-23 11:19:38 -040066 for key, value in six.iteritems(new_quotas):
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090067 self.assertEqual(value, quota_set[key])
68
Miguel Lavalle2492d782013-06-16 15:04:15 -050069 # Confirm our tenant is listed among tenants with non default quotas
David Kranz34e88122014-12-11 15:24:05 -050070 non_default_quotas = self.admin_client.list_quotas()
Miguel Lavalle2492d782013-06-16 15:04:15 -050071 found = False
Eugene Nikanorov909ded12013-12-15 17:45:37 +040072 for qs in non_default_quotas['quotas']:
Miguel Lavalle2492d782013-06-16 15:04:15 -050073 if qs['tenant_id'] == tenant_id:
74 found = True
75 self.assertTrue(found)
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090076
77 # Confirm from API quotas were changed as requested for tenant
David Kranz34e88122014-12-11 15:24:05 -050078 quota_set = self.admin_client.show_quotas(tenant_id)
Eugene Nikanorov909ded12013-12-15 17:45:37 +040079 quota_set = quota_set['quota']
Matthew Treinish71426682015-04-23 11:19:38 -040080 for key, value in six.iteritems(new_quotas):
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090081 self.assertEqual(value, quota_set[key])
82
Miguel Lavalle2492d782013-06-16 15:04:15 -050083 # Reset quotas to default and confirm
David Kranz34e88122014-12-11 15:24:05 -050084 self.admin_client.reset_quotas(tenant_id)
85 non_default_quotas = self.admin_client.list_quotas()
Eugene Nikanorov909ded12013-12-15 17:45:37 +040086 for q in non_default_quotas['quotas']:
Miguel Lavalle2492d782013-06-16 15:04:15 -050087 self.assertNotEqual(tenant_id, q['tenant_id'])
Evgeny Fedorukbff1c062013-12-04 07:43:22 -080088
Chris Hoge7579c1a2015-02-26 14:12:15 -080089 @test.idempotent_id('2390f766-836d-40ef-9aeb-e810d78207fb')
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090090 def test_quotas(self):
91 new_quotas = {'network': 0, 'security_group': 0}
92 self._check_quotas(new_quotas)