blob: 7cf90ae8c369c1ed36eb672b8c36a9bd9997ff83 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Rohit Karajgi07599c52012-11-02 05:35:16 -07002# 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
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.compute import base
Matt Riedemann848805f2014-06-16 13:23:51 -070017from tempest.common import tempest_fixtures as fixtures
Andrea Frittolicd368412017-08-14 21:37:56 +010018from tempest.common import utils
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080019from tempest.lib import decorators
Rohit Karajgi07599c52012-11-02 05:35:16 -070020
21
ivan-zhuf2b00502013-10-18 10:06:52 +080022class QuotasTestJSON(base.BaseV2ComputeTest):
Rohit Karajgi07599c52012-11-02 05:35:16 -070023
Lajos Katona3e601cd2015-07-08 13:53:12 +020024 @classmethod
25 def skip_checks(cls):
26 super(QuotasTestJSON, cls).skip_checks()
Andrea Frittolicd368412017-08-14 21:37:56 +010027 if not utils.is_extension_enabled('os-quota-sets', 'compute'):
Lajos Katona3e601cd2015-07-08 13:53:12 +020028 msg = "quotas extension not enabled."
29 raise cls.skipException(msg)
30
Matt Riedemann848805f2014-06-16 13:23:51 -070031 def setUp(self):
32 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
33 self.useFixture(fixtures.LockFixture('compute_quotas'))
34 super(QuotasTestJSON, self).setUp()
35
Rohit Karajgi07599c52012-11-02 05:35:16 -070036 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053037 def setup_clients(cls):
38 super(QuotasTestJSON, cls).setup_clients()
39 cls.client = cls.quotas_client
40
41 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010042 def resource_setup(cls):
43 super(QuotasTestJSON, cls).resource_setup()
Andrea Frittoli9612e812014-03-13 10:57:26 +000044 cls.tenant_id = cls.client.tenant_id
45 cls.user_id = cls.client.user_id
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020046 cls.default_quota_set = set(('injected_file_content_bytes',
47 'metadata_items', 'injected_files',
48 'ram', 'floating_ips',
49 'fixed_ips', 'key_pairs',
50 'injected_file_path_bytes',
51 'instances', 'security_group_rules',
zhufl05e043c2016-12-07 16:03:28 +080052 'cores', 'security_groups',
53 'server_group_members', 'server_groups'))
Leo Toyoda87a52b72013-04-09 10:34:40 +090054
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080055 @decorators.idempotent_id('f1ef0a97-dbbb-4cca-adc5-c9fbc4f76107')
Leo Toyoda87a52b72013-04-09 10:34:40 +090056 def test_get_quotas(self):
57 # User can get the quota set for it's tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020058 expected_quota_set = self.default_quota_set | set(['id'])
ghanshyam52657872015-08-24 16:39:10 +090059 quota_set = self.client.show_quota_set(self.tenant_id)['quota_set']
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020060 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000061 for quota in expected_quota_set:
62 self.assertIn(quota, quota_set.keys())
Rohit Karajgi07599c52012-11-02 05:35:16 -070063
Zhi Kun Liu90e41312014-03-06 14:56:01 +080064 # get the quota set using user id
Felipe Monteiro3f52a4a2017-02-07 12:05:54 -050065 quota_set = self.client.show_quota_set(
66 self.tenant_id, user_id=self.user_id)['quota_set']
Zhi Kun Liu90e41312014-03-06 14:56:01 +080067 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000068 for quota in expected_quota_set:
69 self.assertIn(quota, quota_set.keys())
Zhi Kun Liu90e41312014-03-06 14:56:01 +080070
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080071 @decorators.idempotent_id('9bfecac7-b966-4f47-913f-1a9e2c12134a')
Rohit Karajgi07599c52012-11-02 05:35:16 -070072 def test_get_default_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050073 # User can get the default quota set for it's tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020074 expected_quota_set = self.default_quota_set | set(['id'])
ghanshyam52657872015-08-24 16:39:10 +090075 quota_set = (self.client.show_default_quota_set(self.tenant_id)
76 ['quota_set'])
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020077 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000078 for quota in expected_quota_set:
79 self.assertIn(quota, quota_set.keys())
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053080
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080081 @decorators.idempotent_id('cd65d997-f7e4-4966-a7e9-d5001b674fdc')
Daniel Korn6653c4e2013-10-28 10:51:23 +020082 def test_compare_tenant_quotas_with_default_quotas(self):
83 # Tenants are created with the default quota values
Gleb Stepanov831516f2016-03-25 14:52:33 +020084 default_quota_set = \
ghanshyam52657872015-08-24 16:39:10 +090085 self.client.show_default_quota_set(self.tenant_id)['quota_set']
86 tenant_quota_set = (self.client.show_quota_set(self.tenant_id)
87 ['quota_set'])
Gleb Stepanov831516f2016-03-25 14:52:33 +020088 self.assertEqual(default_quota_set, tenant_quota_set)