blob: 38784d810f5f55f40110d5c16bdd7de0e097d0d4 [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
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090020from tempest import test
Miguel Lavalle2492d782013-06-16 15:04:15 -050021
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()
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090049 if not test.is_extension_enabled('quotas', 'network'):
50 msg = "quotas extension not enabled."
51 raise cls.skipException(msg)
Miguel Lavalle2492d782013-06-16 15:04:15 -050052 admin_manager = clients.AdminManager()
53 cls.admin_client = admin_manager.network_client
54 cls.identity_admin_client = admin_manager.identity_client
55
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090056 @test.attr(type='gate')
Miguel Lavalle2492d782013-06-16 15:04:15 -050057 def test_quotas(self):
58 # Add a tenant to conduct the test
Masayuki Igawa259c1132013-10-31 17:48:44 +090059 test_tenant = data_utils.rand_name('test_tenant_')
60 test_description = data_utils.rand_name('desc_')
Miguel Lavalle2492d782013-06-16 15:04:15 -050061 _, tenant = self.identity_admin_client.create_tenant(
62 name=test_tenant,
63 description=test_description)
64 tenant_id = tenant['id']
65 self.addCleanup(self.identity_admin_client.delete_tenant, tenant_id)
66 # Change quotas for tenant
67 new_quotas = {'network': 0, 'security_group': 0}
68 resp, quota_set = self.admin_client.update_quotas(tenant_id,
69 **new_quotas)
70 self.assertEqual('200', resp['status'])
71 self.addCleanup(self.admin_client.reset_quotas, tenant_id)
72 self.assertEqual(0, quota_set['network'])
73 self.assertEqual(0, quota_set['security_group'])
74 # Confirm our tenant is listed among tenants with non default quotas
75 resp, non_default_quotas = self.admin_client.list_quotas()
76 self.assertEqual('200', resp['status'])
77 found = False
Eugene Nikanorov909ded12013-12-15 17:45:37 +040078 for qs in non_default_quotas['quotas']:
Miguel Lavalle2492d782013-06-16 15:04:15 -050079 if qs['tenant_id'] == tenant_id:
80 found = True
81 self.assertTrue(found)
82 # Confirm from APi quotas were changed as requested for tenant
83 resp, quota_set = self.admin_client.show_quotas(tenant_id)
Eugene Nikanorov909ded12013-12-15 17:45:37 +040084 quota_set = quota_set['quota']
Miguel Lavalle2492d782013-06-16 15:04:15 -050085 self.assertEqual('200', resp['status'])
86 self.assertEqual(0, quota_set['network'])
87 self.assertEqual(0, quota_set['security_group'])
88 # Reset quotas to default and confirm
89 resp, body = self.admin_client.reset_quotas(tenant_id)
90 self.assertEqual('204', resp['status'])
91 resp, non_default_quotas = self.admin_client.list_quotas()
92 self.assertEqual('200', resp['status'])
Eugene Nikanorov909ded12013-12-15 17:45:37 +040093 for q in non_default_quotas['quotas']:
Miguel Lavalle2492d782013-06-16 15:04:15 -050094 self.assertNotEqual(tenant_id, q['tenant_id'])