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 | |
Matthew Treinish | 7142668 | 2015-04-23 11:19:38 -0400 | [diff] [blame] | 16 | import six |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 17 | |
| 18 | from tempest.api.network import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 19 | from tempest.common.utils import data_utils |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 20 | from tempest import test |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 21 | |
| 22 | |
wanglianmin | 7a3b970 | 2014-03-12 17:43:49 +0800 | [diff] [blame] | 23 | class QuotasTest(base.BaseAdminNetworkTest): |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 24 | """ |
| 25 | Tests the following operations in the Neutron API using the REST client for |
| 26 | Neutron: |
| 27 | |
| 28 | list quotas for tenants who have non-default quota values |
| 29 | show quotas for a specified tenant |
| 30 | update quotas for a specified tenant |
| 31 | reset quotas to default values for a specified tenant |
| 32 | |
wanglianmin | 7a3b970 | 2014-03-12 17:43:49 +0800 | [diff] [blame] | 33 | v2.0 of the API is assumed. |
| 34 | It is also assumed that the per-tenant quota extension API is configured |
| 35 | in /etc/neutron/neutron.conf as follows: |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 36 | |
| 37 | quota_driver = neutron.db.quota_db.DbQuotaDriver |
| 38 | """ |
| 39 | |
| 40 | @classmethod |
Rohan Kanade | a565e45 | 2015-01-27 14:00:13 +0530 | [diff] [blame] | 41 | def skip_checks(cls): |
| 42 | super(QuotasTest, cls).skip_checks() |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 43 | if not test.is_extension_enabled('quotas', 'network'): |
| 44 | msg = "quotas extension not enabled." |
| 45 | raise cls.skipException(msg) |
Rohan Kanade | a565e45 | 2015-01-27 14:00:13 +0530 | [diff] [blame] | 46 | |
| 47 | @classmethod |
| 48 | def setup_clients(cls): |
| 49 | super(QuotasTest, cls).setup_clients() |
wanglianmin | 7a3b970 | 2014-03-12 17:43:49 +0800 | [diff] [blame] | 50 | cls.identity_admin_client = cls.os_adm.identity_client |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 51 | |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 52 | def _check_quotas(self, new_quotas): |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 53 | # Add a tenant to conduct the test |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 54 | test_tenant = data_utils.rand_name('test_tenant_') |
| 55 | test_description = data_utils.rand_name('desc_') |
David Kranz | b7afa92 | 2014-12-30 10:56:26 -0500 | [diff] [blame] | 56 | tenant = self.identity_admin_client.create_tenant( |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 57 | name=test_tenant, |
| 58 | description=test_description) |
| 59 | tenant_id = tenant['id'] |
| 60 | self.addCleanup(self.identity_admin_client.delete_tenant, tenant_id) |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 61 | |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 62 | # Change quotas for tenant |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 63 | quota_set = self.admin_client.update_quotas(tenant_id, |
| 64 | **new_quotas) |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 65 | self.addCleanup(self.admin_client.reset_quotas, tenant_id) |
Matthew Treinish | 7142668 | 2015-04-23 11:19:38 -0400 | [diff] [blame] | 66 | for key, value in six.iteritems(new_quotas): |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 67 | self.assertEqual(value, quota_set[key]) |
| 68 | |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 69 | # Confirm our tenant is listed among tenants with non default quotas |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 70 | non_default_quotas = self.admin_client.list_quotas() |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 71 | found = False |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 72 | for qs in non_default_quotas['quotas']: |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 73 | if qs['tenant_id'] == tenant_id: |
| 74 | found = True |
| 75 | self.assertTrue(found) |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 76 | |
| 77 | # Confirm from API quotas were changed as requested for tenant |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 78 | quota_set = self.admin_client.show_quotas(tenant_id) |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 79 | quota_set = quota_set['quota'] |
Matthew Treinish | 7142668 | 2015-04-23 11:19:38 -0400 | [diff] [blame] | 80 | for key, value in six.iteritems(new_quotas): |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 81 | self.assertEqual(value, quota_set[key]) |
| 82 | |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 83 | # Reset quotas to default and confirm |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 84 | self.admin_client.reset_quotas(tenant_id) |
| 85 | non_default_quotas = self.admin_client.list_quotas() |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 86 | for q in non_default_quotas['quotas']: |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 87 | self.assertNotEqual(tenant_id, q['tenant_id']) |
Evgeny Fedoruk | bff1c06 | 2013-12-04 07:43:22 -0800 | [diff] [blame] | 88 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 89 | @test.idempotent_id('2390f766-836d-40ef-9aeb-e810d78207fb') |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 90 | def test_quotas(self): |
| 91 | new_quotas = {'network': 0, 'security_group': 0} |
| 92 | self._check_quotas(new_quotas) |