blob: 5fe0e3bf13cbbc95477f407c59526169fbe4516d [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):
zhufl4e726a62020-08-10 16:30:28 +080023 """Test compute quotas"""
Rohit Karajgi07599c52012-11-02 05:35:16 -070024
Lajos Katona3e601cd2015-07-08 13:53:12 +020025 @classmethod
26 def skip_checks(cls):
27 super(QuotasTestJSON, cls).skip_checks()
Andrea Frittolicd368412017-08-14 21:37:56 +010028 if not utils.is_extension_enabled('os-quota-sets', 'compute'):
Lajos Katona3e601cd2015-07-08 13:53:12 +020029 msg = "quotas extension not enabled."
30 raise cls.skipException(msg)
31
Matt Riedemann848805f2014-06-16 13:23:51 -070032 def setUp(self):
33 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
34 self.useFixture(fixtures.LockFixture('compute_quotas'))
35 super(QuotasTestJSON, self).setUp()
36
Rohit Karajgi07599c52012-11-02 05:35:16 -070037 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053038 def setup_clients(cls):
39 super(QuotasTestJSON, cls).setup_clients()
40 cls.client = cls.quotas_client
41
42 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010043 def resource_setup(cls):
44 super(QuotasTestJSON, cls).resource_setup()
Andrea Frittoli9612e812014-03-13 10:57:26 +000045 cls.tenant_id = cls.client.tenant_id
46 cls.user_id = cls.client.user_id
zhufl2766ca82018-03-28 17:47:45 +080047 cls.default_quota_set = set(('metadata_items', 'ram', 'key_pairs',
48 'instances', 'cores',
zhufl05e043c2016-12-07 16:03:28 +080049 'server_group_members', 'server_groups'))
zhufl2766ca82018-03-28 17:47:45 +080050 if cls.is_requested_microversion_compatible('2.35'):
51 cls.default_quota_set = \
52 cls.default_quota_set | set(['fixed_ips', 'floating_ips',
53 'security_group_rules',
54 'security_groups'])
55 if cls.is_requested_microversion_compatible('2.56'):
56 cls.default_quota_set = \
57 cls.default_quota_set | set(['injected_file_content_bytes',
58 'injected_file_path_bytes',
59 'injected_files'])
Leo Toyoda87a52b72013-04-09 10:34:40 +090060
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080061 @decorators.idempotent_id('f1ef0a97-dbbb-4cca-adc5-c9fbc4f76107')
Leo Toyoda87a52b72013-04-09 10:34:40 +090062 def test_get_quotas(self):
zhufl4e726a62020-08-10 16:30:28 +080063 """Test user can get the compute quota set for it's project"""
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020064 expected_quota_set = self.default_quota_set | set(['id'])
ghanshyam52657872015-08-24 16:39:10 +090065 quota_set = self.client.show_quota_set(self.tenant_id)['quota_set']
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020066 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000067 for quota in expected_quota_set:
68 self.assertIn(quota, quota_set.keys())
Rohit Karajgi07599c52012-11-02 05:35:16 -070069
Zhi Kun Liu90e41312014-03-06 14:56:01 +080070 # get the quota set using user id
Felipe Monteiro3f52a4a2017-02-07 12:05:54 -050071 quota_set = self.client.show_quota_set(
72 self.tenant_id, user_id=self.user_id)['quota_set']
Zhi Kun Liu90e41312014-03-06 14:56:01 +080073 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000074 for quota in expected_quota_set:
75 self.assertIn(quota, quota_set.keys())
Zhi Kun Liu90e41312014-03-06 14:56:01 +080076
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080077 @decorators.idempotent_id('9bfecac7-b966-4f47-913f-1a9e2c12134a')
Rohit Karajgi07599c52012-11-02 05:35:16 -070078 def test_get_default_quotas(self):
zhufl4e726a62020-08-10 16:30:28 +080079 """Test user can get the default compute quota set for it's project"""
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020080 expected_quota_set = self.default_quota_set | set(['id'])
ghanshyam52657872015-08-24 16:39:10 +090081 quota_set = (self.client.show_default_quota_set(self.tenant_id)
82 ['quota_set'])
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020083 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000084 for quota in expected_quota_set:
85 self.assertIn(quota, quota_set.keys())
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053086
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080087 @decorators.idempotent_id('cd65d997-f7e4-4966-a7e9-d5001b674fdc')
Daniel Korn6653c4e2013-10-28 10:51:23 +020088 def test_compare_tenant_quotas_with_default_quotas(self):
zhufl4e726a62020-08-10 16:30:28 +080089 """Test tenants are created with the default compute quota values"""
Gleb Stepanov831516f2016-03-25 14:52:33 +020090 default_quota_set = \
ghanshyam52657872015-08-24 16:39:10 +090091 self.client.show_default_quota_set(self.tenant_id)['quota_set']
92 tenant_quota_set = (self.client.show_quota_set(self.tenant_id)
93 ['quota_set'])
Gleb Stepanov831516f2016-03-25 14:52:33 +020094 self.assertEqual(default_quota_set, tenant_quota_set)