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