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