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 | |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 16 | from tempest.api.network import base |
Ken'ichi Ohmichi | f50e4df | 2017-03-10 10:52:53 -0800 | [diff] [blame] | 17 | from tempest.lib.common.utils import data_utils |
Jordan Pittier | 9e227c5 | 2016-02-09 14:35:18 +0100 | [diff] [blame] | 18 | from tempest.lib.common.utils import test_utils |
Ken'ichi Ohmichi | 53b9a63 | 2017-01-27 18:04:39 -0800 | [diff] [blame] | 19 | from tempest.lib import decorators |
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 | |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 26 | list quotas for projects who have non-default quota values |
| 27 | show quotas for a specified project |
| 28 | update quotas for a specified project |
| 29 | reset quotas to default values for a specified project |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 30 | |
wanglianmin | 7a3b970 | 2014-03-12 17:43:49 +0800 | [diff] [blame] | 31 | v2.0 of the API is assumed. |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 32 | It is also assumed that the per-project quota extension API is configured |
wanglianmin | 7a3b970 | 2014-03-12 17:43:49 +0800 | [diff] [blame] | 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 | |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 45 | def _check_quotas(self, new_quotas): |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 46 | # Add a project to conduct the test |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 47 | project = data_utils.rand_name('test_project_') |
| 48 | description = data_utils.rand_name('desc_') |
| 49 | project = self.identity_utils.create_project(name=project, |
| 50 | description=description) |
| 51 | project_id = project['id'] |
| 52 | self.addCleanup(self.identity_utils.delete_project, project_id) |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 53 | |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 54 | # Change quotas for project |
Ken'ichi Ohmichi | 756d8ff | 2015-12-15 09:47:54 +0000 | [diff] [blame] | 55 | quota_set = self.admin_quotas_client.update_quotas( |
| 56 | project_id, **new_quotas)['quota'] |
Jordan Pittier | 9e227c5 | 2016-02-09 14:35:18 +0100 | [diff] [blame] | 57 | self.addCleanup(test_utils.call_and_ignore_notfound_exc, |
| 58 | self.admin_quotas_client.reset_quotas, project_id) |
guo yunxian | 7bbbec1 | 2016-08-21 20:03:10 +0800 | [diff] [blame] | 59 | for key, value in new_quotas.items(): |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 60 | self.assertEqual(value, quota_set[key]) |
| 61 | |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 62 | # Confirm our project is listed among projects with non default quotas |
Ken'ichi Ohmichi | 756d8ff | 2015-12-15 09:47:54 +0000 | [diff] [blame] | 63 | non_default_quotas = self.admin_quotas_client.list_quotas() |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 64 | found = False |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 65 | for qs in non_default_quotas['quotas']: |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 66 | if qs['tenant_id'] == project_id: |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 67 | found = True |
| 68 | self.assertTrue(found) |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 69 | |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 70 | # Confirm from API quotas were changed as requested for project |
Ken'ichi Ohmichi | 756d8ff | 2015-12-15 09:47:54 +0000 | [diff] [blame] | 71 | quota_set = self.admin_quotas_client.show_quotas(project_id) |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 72 | quota_set = quota_set['quota'] |
guo yunxian | 7bbbec1 | 2016-08-21 20:03:10 +0800 | [diff] [blame] | 73 | for key, value in new_quotas.items(): |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 74 | self.assertEqual(value, quota_set[key]) |
| 75 | |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 76 | # Reset quotas to default and confirm |
Ken'ichi Ohmichi | 756d8ff | 2015-12-15 09:47:54 +0000 | [diff] [blame] | 77 | self.admin_quotas_client.reset_quotas(project_id) |
| 78 | non_default_quotas = self.admin_quotas_client.list_quotas() |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 79 | for q in non_default_quotas['quotas']: |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 80 | self.assertNotEqual(project_id, q['tenant_id']) |
Evgeny Fedoruk | bff1c06 | 2013-12-04 07:43:22 -0800 | [diff] [blame] | 81 | |
Ken'ichi Ohmichi | 53b9a63 | 2017-01-27 18:04:39 -0800 | [diff] [blame] | 82 | @decorators.idempotent_id('2390f766-836d-40ef-9aeb-e810d78207fb') |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 83 | def test_quotas(self): |
zhufl | 4765ce7 | 2016-09-18 17:18:19 +0800 | [diff] [blame] | 84 | new_quotas = {'network': 0, 'port': 0} |
Ken'ichi Ohmichi | eed5c78 | 2014-07-04 11:02:36 +0900 | [diff] [blame] | 85 | self._check_quotas(new_quotas) |