blob: ba70f34d92acc86692d57850a30a4e077764877d [file] [log] [blame]
Miguel Lavalle2492d782013-06-16 15:04:15 -05001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 OpenStack, LLC
4# 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
21from tempest.common.utils.data_utils import rand_name
22from tempest.test import attr
23
24
25class QuotasTest(base.BaseNetworkTest):
26
27 """
28 Tests the following operations in the Neutron API using the REST client for
29 Neutron:
30
31 list quotas for tenants who have non-default quota values
32 show quotas for a specified tenant
33 update quotas for a specified tenant
34 reset quotas to default values for a specified tenant
35
36 v2.0 of the API is assumed. It is also assumed that the following
37 option is defined in the [service_available] section of etc/tempest.conf:
38
39 neutron as True
40
41 Finally, it is assumed that the per-tenant quota extension API is
42 configured in /etc/neutron/neutron.conf as follows:
43
44 quota_driver = neutron.db.quota_db.DbQuotaDriver
45 """
46
47 @classmethod
48 def setUpClass(cls):
49 super(QuotasTest, cls).setUpClass()
50 admin_manager = clients.AdminManager()
51 cls.admin_client = admin_manager.network_client
52 cls.identity_admin_client = admin_manager.identity_client
53
54 @attr(type='gate')
55 def test_quotas(self):
56 # Add a tenant to conduct the test
57 test_tenant = rand_name('test_tenant_')
58 test_description = rand_name('desc_')
59 _, tenant = self.identity_admin_client.create_tenant(
60 name=test_tenant,
61 description=test_description)
62 tenant_id = tenant['id']
63 self.addCleanup(self.identity_admin_client.delete_tenant, tenant_id)
64 # Change quotas for tenant
65 new_quotas = {'network': 0, 'security_group': 0}
66 resp, quota_set = self.admin_client.update_quotas(tenant_id,
67 **new_quotas)
68 self.assertEqual('200', resp['status'])
69 self.addCleanup(self.admin_client.reset_quotas, tenant_id)
70 self.assertEqual(0, quota_set['network'])
71 self.assertEqual(0, quota_set['security_group'])
72 # Confirm our tenant is listed among tenants with non default quotas
73 resp, non_default_quotas = self.admin_client.list_quotas()
74 self.assertEqual('200', resp['status'])
75 found = False
76 for qs in non_default_quotas:
77 if qs['tenant_id'] == tenant_id:
78 found = True
79 self.assertTrue(found)
80 # Confirm from APi quotas were changed as requested for tenant
81 resp, quota_set = self.admin_client.show_quotas(tenant_id)
82 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'])
90 for q in non_default_quotas:
91 self.assertNotEqual(tenant_id, q['tenant_id'])