blob: aa8b2dca999f74f43fe278e69fb34afc9cba4ca8 [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
Miguel Lavalle2492d782013-06-16 15:04:15 -050016from tempest.api.network import base
Ken'ichi Ohmichif50e4df2017-03-10 10:52:53 -080017from tempest.lib.common.utils import data_utils
Jordan Pittier9e227c52016-02-09 14:35:18 +010018from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080019from tempest.lib import decorators
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090020from tempest import test
Miguel Lavalle2492d782013-06-16 15:04:15 -050021
22
wanglianmin7a3b9702014-03-12 17:43:49 +080023class QuotasTest(base.BaseAdminNetworkTest):
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +000024 """Tests the following operations in the Neutron API:
Miguel Lavalle2492d782013-06-16 15:04:15 -050025
Sean Dagueed6e5862016-04-04 10:49:13 -040026 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 Lavalle2492d782013-06-16 15:04:15 -050030
wanglianmin7a3b9702014-03-12 17:43:49 +080031 v2.0 of the API is assumed.
Sean Dagueed6e5862016-04-04 10:49:13 -040032 It is also assumed that the per-project quota extension API is configured
wanglianmin7a3b9702014-03-12 17:43:49 +080033 in /etc/neutron/neutron.conf as follows:
Miguel Lavalle2492d782013-06-16 15:04:15 -050034
35 quota_driver = neutron.db.quota_db.DbQuotaDriver
36 """
37
38 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053039 def skip_checks(cls):
40 super(QuotasTest, cls).skip_checks()
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090041 if not test.is_extension_enabled('quotas', 'network'):
42 msg = "quotas extension not enabled."
43 raise cls.skipException(msg)
Rohan Kanadea565e452015-01-27 14:00:13 +053044
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090045 def _check_quotas(self, new_quotas):
Sean Dagueed6e5862016-04-04 10:49:13 -040046 # Add a project to conduct the test
Jamie Lennox15350172015-08-17 10:54:25 +100047 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 Ohmichieed5c782014-07-04 11:02:36 +090053
Sean Dagueed6e5862016-04-04 10:49:13 -040054 # Change quotas for project
Ken'ichi Ohmichi756d8ff2015-12-15 09:47:54 +000055 quota_set = self.admin_quotas_client.update_quotas(
56 project_id, **new_quotas)['quota']
Jordan Pittier9e227c52016-02-09 14:35:18 +010057 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
58 self.admin_quotas_client.reset_quotas, project_id)
guo yunxian7bbbec12016-08-21 20:03:10 +080059 for key, value in new_quotas.items():
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090060 self.assertEqual(value, quota_set[key])
61
Sean Dagueed6e5862016-04-04 10:49:13 -040062 # Confirm our project is listed among projects with non default quotas
Ken'ichi Ohmichi756d8ff2015-12-15 09:47:54 +000063 non_default_quotas = self.admin_quotas_client.list_quotas()
Miguel Lavalle2492d782013-06-16 15:04:15 -050064 found = False
Eugene Nikanorov909ded12013-12-15 17:45:37 +040065 for qs in non_default_quotas['quotas']:
Jamie Lennox15350172015-08-17 10:54:25 +100066 if qs['tenant_id'] == project_id:
Miguel Lavalle2492d782013-06-16 15:04:15 -050067 found = True
68 self.assertTrue(found)
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090069
Sean Dagueed6e5862016-04-04 10:49:13 -040070 # Confirm from API quotas were changed as requested for project
Ken'ichi Ohmichi756d8ff2015-12-15 09:47:54 +000071 quota_set = self.admin_quotas_client.show_quotas(project_id)
Eugene Nikanorov909ded12013-12-15 17:45:37 +040072 quota_set = quota_set['quota']
guo yunxian7bbbec12016-08-21 20:03:10 +080073 for key, value in new_quotas.items():
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090074 self.assertEqual(value, quota_set[key])
75
Miguel Lavalle2492d782013-06-16 15:04:15 -050076 # Reset quotas to default and confirm
Ken'ichi Ohmichi756d8ff2015-12-15 09:47:54 +000077 self.admin_quotas_client.reset_quotas(project_id)
78 non_default_quotas = self.admin_quotas_client.list_quotas()
Eugene Nikanorov909ded12013-12-15 17:45:37 +040079 for q in non_default_quotas['quotas']:
Jamie Lennox15350172015-08-17 10:54:25 +100080 self.assertNotEqual(project_id, q['tenant_id'])
Evgeny Fedorukbff1c062013-12-04 07:43:22 -080081
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080082 @decorators.idempotent_id('2390f766-836d-40ef-9aeb-e810d78207fb')
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090083 def test_quotas(self):
zhufl4765ce72016-09-18 17:18:19 +080084 new_quotas = {'network': 0, 'port': 0}
Ken'ichi Ohmichieed5c782014-07-04 11:02:36 +090085 self._check_quotas(new_quotas)