| ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2013 OpenStack Foundation | 
| Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 2 | # 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 |  | 
 | 17 | from tempest.api.network import base | 
 | 18 | from tempest import clients | 
| Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 19 | from tempest.common.utils import data_utils | 
| Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 20 | from tempest.test import attr | 
 | 21 |  | 
 | 22 |  | 
 | 23 | class QuotasTest(base.BaseNetworkTest): | 
| raiesmh08 | 6769832 | 2013-08-20 13:09:01 +0530 | [diff] [blame] | 24 |     _interface = 'json' | 
| Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 25 |  | 
 | 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 Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 56 |         test_tenant = data_utils.rand_name('test_tenant_') | 
 | 57 |         test_description = data_utils.rand_name('desc_') | 
| Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 58 |         _, 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 Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 75 |         for qs in non_default_quotas['quotas']: | 
| Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 76 |             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 Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 81 |         quota_set = quota_set['quota'] | 
| Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 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']) | 
| Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 90 |         for q in non_default_quotas['quotas']: | 
| Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 91 |             self.assertNotEqual(tenant_id, q['tenant_id']) |