blob: a5be39540fa6aba72456119a1770df0d7f8a8689 [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
18from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090019from tempest.common.utils import data_utils
Miguel Lavalle2492d782013-06-16 15:04:15 -050020from tempest.test import attr
21
22
23class QuotasTest(base.BaseNetworkTest):
raiesmh0867698322013-08-20 13:09:01 +053024 _interface = 'json'
Miguel Lavalle2492d782013-06-16 15:04:15 -050025
26 """
27 Tests the following operations in the Neutron API using the REST client for
28 Neutron:
29
30 list quotas for tenants who have non-default quota values
31 show quotas for a specified tenant
32 update quotas for a specified tenant
33 reset quotas to default values for a specified tenant
34
35 v2.0 of the API is assumed. It is also assumed that the following
36 option is defined in the [service_available] section of etc/tempest.conf:
37
38 neutron as True
39
40 Finally, it is assumed that the per-tenant quota extension API is
41 configured in /etc/neutron/neutron.conf as follows:
42
43 quota_driver = neutron.db.quota_db.DbQuotaDriver
44 """
45
46 @classmethod
47 def setUpClass(cls):
48 super(QuotasTest, cls).setUpClass()
49 admin_manager = clients.AdminManager()
50 cls.admin_client = admin_manager.network_client
51 cls.identity_admin_client = admin_manager.identity_client
52
53 @attr(type='gate')
54 def test_quotas(self):
55 # Add a tenant to conduct the test
Masayuki Igawa259c1132013-10-31 17:48:44 +090056 test_tenant = data_utils.rand_name('test_tenant_')
57 test_description = data_utils.rand_name('desc_')
Miguel Lavalle2492d782013-06-16 15:04:15 -050058 _, tenant = self.identity_admin_client.create_tenant(
59 name=test_tenant,
60 description=test_description)
61 tenant_id = tenant['id']
62 self.addCleanup(self.identity_admin_client.delete_tenant, tenant_id)
63 # Change quotas for tenant
64 new_quotas = {'network': 0, 'security_group': 0}
65 resp, quota_set = self.admin_client.update_quotas(tenant_id,
66 **new_quotas)
67 self.assertEqual('200', resp['status'])
68 self.addCleanup(self.admin_client.reset_quotas, tenant_id)
69 self.assertEqual(0, quota_set['network'])
70 self.assertEqual(0, quota_set['security_group'])
71 # Confirm our tenant is listed among tenants with non default quotas
72 resp, non_default_quotas = self.admin_client.list_quotas()
73 self.assertEqual('200', resp['status'])
74 found = False
Eugene Nikanorov909ded12013-12-15 17:45:37 +040075 for qs in non_default_quotas['quotas']:
Miguel Lavalle2492d782013-06-16 15:04:15 -050076 if qs['tenant_id'] == tenant_id:
77 found = True
78 self.assertTrue(found)
79 # Confirm from APi quotas were changed as requested for tenant
80 resp, quota_set = self.admin_client.show_quotas(tenant_id)
Eugene Nikanorov909ded12013-12-15 17:45:37 +040081 quota_set = quota_set['quota']
Miguel Lavalle2492d782013-06-16 15:04:15 -050082 self.assertEqual('200', resp['status'])
83 self.assertEqual(0, quota_set['network'])
84 self.assertEqual(0, quota_set['security_group'])
85 # Reset quotas to default and confirm
86 resp, body = self.admin_client.reset_quotas(tenant_id)
87 self.assertEqual('204', resp['status'])
88 resp, non_default_quotas = self.admin_client.list_quotas()
89 self.assertEqual('200', resp['status'])
Eugene Nikanorov909ded12013-12-15 17:45:37 +040090 for q in non_default_quotas['quotas']:
Miguel Lavalle2492d782013-06-16 15:04:15 -050091 self.assertNotEqual(tenant_id, q['tenant_id'])