blob: ea3d59ab734bb3825c19b6366bf3441ea567be53 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2013 OpenStack Foundation
Miguel Lavalle2492d782013-06-16 15:04:15 -05002# 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 Treinish71426682015-04-23 11:19:38 -040016import six
Miguel Lavalle2492d782013-06-16 15:04:15 -050017
18from tempest.api.network import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120019from tempest.common.utils import data_utils
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050020from tempest.lib import exceptions as lib_exc
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090021from tempest import test
Miguel Lavalle2492d782013-06-16 15:04:15 -050022
23
wanglianmin7a3b9702014-03-12 17:43:49 +080024class QuotasTest(base.BaseAdminNetworkTest):
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +000025 """Tests the following operations in the Neutron API:
Miguel Lavalle2492d782013-06-16 15:04:15 -050026
Sean Dagueed6e5862016-04-04 10:49:13 -040027 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 Lavalle2492d782013-06-16 15:04:15 -050031
wanglianmin7a3b9702014-03-12 17:43:49 +080032 v2.0 of the API is assumed.
Sean Dagueed6e5862016-04-04 10:49:13 -040033 It is also assumed that the per-project quota extension API is configured
wanglianmin7a3b9702014-03-12 17:43:49 +080034 in /etc/neutron/neutron.conf as follows:
Miguel Lavalle2492d782013-06-16 15:04:15 -050035
36 quota_driver = neutron.db.quota_db.DbQuotaDriver
37 """
38
39 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053040 def skip_checks(cls):
41 super(QuotasTest, cls).skip_checks()
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090042 if not test.is_extension_enabled('quotas', 'network'):
43 msg = "quotas extension not enabled."
44 raise cls.skipException(msg)
Rohan Kanadea565e452015-01-27 14:00:13 +053045
46 @classmethod
47 def setup_clients(cls):
48 super(QuotasTest, cls).setup_clients()
wanglianmin7a3b9702014-03-12 17:43:49 +080049 cls.identity_admin_client = cls.os_adm.identity_client
Miguel Lavalle2492d782013-06-16 15:04:15 -050050
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090051 def _check_quotas(self, new_quotas):
Sean Dagueed6e5862016-04-04 10:49:13 -040052 # Add a project to conduct the test
Jamie Lennox15350172015-08-17 10:54:25 +100053 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 Ohmichieed5c782014-07-04 11:02:36 +090059
Sean Dagueed6e5862016-04-04 10:49:13 -040060 # Change quotas for project
Ken'ichi Ohmichi756d8ff2015-12-15 09:47:54 +000061 quota_set = self.admin_quotas_client.update_quotas(
62 project_id, **new_quotas)['quota']
reedipc509a152016-02-09 11:14:27 +090063 self.addCleanup(self._cleanup_quotas, project_id)
Matthew Treinish71426682015-04-23 11:19:38 -040064 for key, value in six.iteritems(new_quotas):
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090065 self.assertEqual(value, quota_set[key])
66
Sean Dagueed6e5862016-04-04 10:49:13 -040067 # Confirm our project is listed among projects with non default quotas
Ken'ichi Ohmichi756d8ff2015-12-15 09:47:54 +000068 non_default_quotas = self.admin_quotas_client.list_quotas()
Miguel Lavalle2492d782013-06-16 15:04:15 -050069 found = False
Eugene Nikanorov909ded12013-12-15 17:45:37 +040070 for qs in non_default_quotas['quotas']:
Jamie Lennox15350172015-08-17 10:54:25 +100071 if qs['tenant_id'] == project_id:
Miguel Lavalle2492d782013-06-16 15:04:15 -050072 found = True
73 self.assertTrue(found)
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090074
Sean Dagueed6e5862016-04-04 10:49:13 -040075 # Confirm from API quotas were changed as requested for project
Ken'ichi Ohmichi756d8ff2015-12-15 09:47:54 +000076 quota_set = self.admin_quotas_client.show_quotas(project_id)
Eugene Nikanorov909ded12013-12-15 17:45:37 +040077 quota_set = quota_set['quota']
Matthew Treinish71426682015-04-23 11:19:38 -040078 for key, value in six.iteritems(new_quotas):
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090079 self.assertEqual(value, quota_set[key])
80
Miguel Lavalle2492d782013-06-16 15:04:15 -050081 # Reset quotas to default and confirm
Ken'ichi Ohmichi756d8ff2015-12-15 09:47:54 +000082 self.admin_quotas_client.reset_quotas(project_id)
83 non_default_quotas = self.admin_quotas_client.list_quotas()
Eugene Nikanorov909ded12013-12-15 17:45:37 +040084 for q in non_default_quotas['quotas']:
Jamie Lennox15350172015-08-17 10:54:25 +100085 self.assertNotEqual(project_id, q['tenant_id'])
Evgeny Fedorukbff1c062013-12-04 07:43:22 -080086
Chris Hoge7579c1a2015-02-26 14:12:15 -080087 @test.idempotent_id('2390f766-836d-40ef-9aeb-e810d78207fb')
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090088 def test_quotas(self):
89 new_quotas = {'network': 0, 'security_group': 0}
90 self._check_quotas(new_quotas)
reedipc509a152016-02-09 11:14:27 +090091
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