blob: 8b77637aa84d8508e7de0712f486cfe650400e76 [file] [log] [blame]
Miguel Lavalle2492d782013-06-16 15:04:15 -05001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2013 OpenStack Foundation
Miguel Lavalle2492d782013-06-16 15:04:15 -05004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18
19from tempest.api.network import base
20from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090021from tempest.common.utils import data_utils
Miguel Lavalle2492d782013-06-16 15:04:15 -050022from tempest.test import attr
23
24
25class QuotasTest(base.BaseNetworkTest):
raiesmh0867698322013-08-20 13:09:01 +053026 _interface = 'json'
Miguel Lavalle2492d782013-06-16 15:04:15 -050027
28 """
29 Tests the following operations in the Neutron API using the REST client for
30 Neutron:
31
32 list quotas for tenants who have non-default quota values
33 show quotas for a specified tenant
34 update quotas for a specified tenant
35 reset quotas to default values for a specified tenant
36
37 v2.0 of the API is assumed. It is also assumed that the following
38 option is defined in the [service_available] section of etc/tempest.conf:
39
40 neutron as True
41
42 Finally, it is assumed that the per-tenant quota extension API is
43 configured in /etc/neutron/neutron.conf as follows:
44
45 quota_driver = neutron.db.quota_db.DbQuotaDriver
46 """
47
48 @classmethod
49 def setUpClass(cls):
50 super(QuotasTest, cls).setUpClass()
51 admin_manager = clients.AdminManager()
52 cls.admin_client = admin_manager.network_client
53 cls.identity_admin_client = admin_manager.identity_client
54
55 @attr(type='gate')
56 def test_quotas(self):
57 # Add a tenant to conduct the test
Masayuki Igawa259c1132013-10-31 17:48:44 +090058 test_tenant = data_utils.rand_name('test_tenant_')
59 test_description = data_utils.rand_name('desc_')
Miguel Lavalle2492d782013-06-16 15:04:15 -050060 _, tenant = self.identity_admin_client.create_tenant(
61 name=test_tenant,
62 description=test_description)
63 tenant_id = tenant['id']
64 self.addCleanup(self.identity_admin_client.delete_tenant, tenant_id)
65 # Change quotas for tenant
66 new_quotas = {'network': 0, 'security_group': 0}
67 resp, quota_set = self.admin_client.update_quotas(tenant_id,
68 **new_quotas)
69 self.assertEqual('200', resp['status'])
70 self.addCleanup(self.admin_client.reset_quotas, tenant_id)
71 self.assertEqual(0, quota_set['network'])
72 self.assertEqual(0, quota_set['security_group'])
73 # Confirm our tenant is listed among tenants with non default quotas
74 resp, non_default_quotas = self.admin_client.list_quotas()
75 self.assertEqual('200', resp['status'])
76 found = False
Eugene Nikanorov909ded12013-12-15 17:45:37 +040077 for qs in non_default_quotas['quotas']:
Miguel Lavalle2492d782013-06-16 15:04:15 -050078 if qs['tenant_id'] == tenant_id:
79 found = True
80 self.assertTrue(found)
81 # Confirm from APi quotas were changed as requested for tenant
82 resp, quota_set = self.admin_client.show_quotas(tenant_id)
Eugene Nikanorov909ded12013-12-15 17:45:37 +040083 quota_set = quota_set['quota']
Miguel Lavalle2492d782013-06-16 15:04:15 -050084 self.assertEqual('200', resp['status'])
85 self.assertEqual(0, quota_set['network'])
86 self.assertEqual(0, quota_set['security_group'])
87 # Reset quotas to default and confirm
88 resp, body = self.admin_client.reset_quotas(tenant_id)
89 self.assertEqual('204', resp['status'])
90 resp, non_default_quotas = self.admin_client.list_quotas()
91 self.assertEqual('200', resp['status'])
Eugene Nikanorov909ded12013-12-15 17:45:37 +040092 for q in non_default_quotas['quotas']:
Miguel Lavalle2492d782013-06-16 15:04:15 -050093 self.assertNotEqual(tenant_id, q['tenant_id'])