blob: 9fa54b1474592d7250ed7b725ba951e028eaad4c [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
16
17from tempest.api.network import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090018from tempest.common.utils import data_utils
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090019from tempest import test
Miguel Lavalle2492d782013-06-16 15:04:15 -050020
21
wanglianmin7a3b9702014-03-12 17:43:49 +080022class QuotasTest(base.BaseAdminNetworkTest):
raiesmh0867698322013-08-20 13:09:01 +053023 _interface = 'json'
Miguel Lavalle2492d782013-06-16 15:04:15 -050024
25 """
26 Tests the following operations in the Neutron API using the REST client for
27 Neutron:
28
29 list quotas for tenants who have non-default quota values
30 show quotas for a specified tenant
31 update quotas for a specified tenant
32 reset quotas to default values for a specified tenant
33
wanglianmin7a3b9702014-03-12 17:43:49 +080034 v2.0 of the API is assumed.
35 It is also assumed that the per-tenant quota extension API is configured
36 in /etc/neutron/neutron.conf as follows:
Miguel Lavalle2492d782013-06-16 15:04:15 -050037
38 quota_driver = neutron.db.quota_db.DbQuotaDriver
39 """
40
41 @classmethod
42 def setUpClass(cls):
43 super(QuotasTest, cls).setUpClass()
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090044 if not test.is_extension_enabled('quotas', 'network'):
45 msg = "quotas extension not enabled."
46 raise cls.skipException(msg)
wanglianmin7a3b9702014-03-12 17:43:49 +080047 cls.identity_admin_client = cls.os_adm.identity_client
Miguel Lavalle2492d782013-06-16 15:04:15 -050048
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090049 def _check_quotas(self, new_quotas):
Miguel Lavalle2492d782013-06-16 15:04:15 -050050 # Add a tenant to conduct the test
Masayuki Igawa259c1132013-10-31 17:48:44 +090051 test_tenant = data_utils.rand_name('test_tenant_')
52 test_description = data_utils.rand_name('desc_')
Miguel Lavalle2492d782013-06-16 15:04:15 -050053 _, tenant = self.identity_admin_client.create_tenant(
54 name=test_tenant,
55 description=test_description)
56 tenant_id = tenant['id']
57 self.addCleanup(self.identity_admin_client.delete_tenant, tenant_id)
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090058
Miguel Lavalle2492d782013-06-16 15:04:15 -050059 # Change quotas for tenant
Miguel Lavalle2492d782013-06-16 15:04:15 -050060 resp, quota_set = self.admin_client.update_quotas(tenant_id,
61 **new_quotas)
62 self.assertEqual('200', resp['status'])
63 self.addCleanup(self.admin_client.reset_quotas, tenant_id)
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090064 for key, value in new_quotas.iteritems():
65 self.assertEqual(value, quota_set[key])
66
Miguel Lavalle2492d782013-06-16 15:04:15 -050067 # Confirm our tenant is listed among tenants with non default quotas
68 resp, non_default_quotas = self.admin_client.list_quotas()
69 self.assertEqual('200', resp['status'])
70 found = False
Eugene Nikanorov909ded12013-12-15 17:45:37 +040071 for qs in non_default_quotas['quotas']:
Miguel Lavalle2492d782013-06-16 15:04:15 -050072 if qs['tenant_id'] == tenant_id:
73 found = True
74 self.assertTrue(found)
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090075
76 # Confirm from API quotas were changed as requested for tenant
Miguel Lavalle2492d782013-06-16 15:04:15 -050077 resp, quota_set = self.admin_client.show_quotas(tenant_id)
Eugene Nikanorov909ded12013-12-15 17:45:37 +040078 quota_set = quota_set['quota']
Miguel Lavalle2492d782013-06-16 15:04:15 -050079 self.assertEqual('200', resp['status'])
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090080 for key, value in new_quotas.iteritems():
81 self.assertEqual(value, quota_set[key])
82
Miguel Lavalle2492d782013-06-16 15:04:15 -050083 # Reset quotas to default and confirm
84 resp, body = self.admin_client.reset_quotas(tenant_id)
85 self.assertEqual('204', resp['status'])
86 resp, non_default_quotas = self.admin_client.list_quotas()
87 self.assertEqual('200', resp['status'])
Eugene Nikanorov909ded12013-12-15 17:45:37 +040088 for q in non_default_quotas['quotas']:
Miguel Lavalle2492d782013-06-16 15:04:15 -050089 self.assertNotEqual(tenant_id, q['tenant_id'])
Evgeny Fedorukbff1c062013-12-04 07:43:22 -080090
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090091 @test.attr(type='gate')
92 def test_quotas(self):
93 new_quotas = {'network': 0, 'security_group': 0}
94 self._check_quotas(new_quotas)
95
Evgeny Fedorukbff1c062013-12-04 07:43:22 -080096 @test.requires_ext(extension='lbaas', service='network')
97 @test.attr(type='gate')
98 def test_lbaas_quotas(self):
Evgeny Fedorukbff1c062013-12-04 07:43:22 -080099 new_quotas = {'vip': 1, 'pool': 2,
100 'member': 3, 'health_monitor': 4}
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +0900101 self._check_quotas(new_quotas)