blob: 9f37143a90b003ce56d246933614bc636f642961 [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
Yuiko Takadae9999d62014-03-06 09:22:54 +000018from tempest import test
Rohit Karajgi07599c52012-11-02 05:35:16 -070019
20
ivan-zhuf2b00502013-10-18 10:06:52 +080021class QuotasTestJSON(base.BaseV2ComputeTest):
Rohit Karajgi07599c52012-11-02 05:35:16 -070022
Lajos Katona3e601cd2015-07-08 13:53:12 +020023 @classmethod
24 def skip_checks(cls):
25 super(QuotasTestJSON, cls).skip_checks()
26 if not test.is_extension_enabled('os-quota-sets', 'compute'):
27 msg = "quotas extension not enabled."
28 raise cls.skipException(msg)
29
Matt Riedemann848805f2014-06-16 13:23:51 -070030 def setUp(self):
31 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
32 self.useFixture(fixtures.LockFixture('compute_quotas'))
33 super(QuotasTestJSON, self).setUp()
34
Rohit Karajgi07599c52012-11-02 05:35:16 -070035 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053036 def setup_clients(cls):
37 super(QuotasTestJSON, cls).setup_clients()
38 cls.client = cls.quotas_client
39
40 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010041 def resource_setup(cls):
42 super(QuotasTestJSON, cls).resource_setup()
Andrea Frittoli9612e812014-03-13 10:57:26 +000043 cls.tenant_id = cls.client.tenant_id
44 cls.user_id = cls.client.user_id
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020045 cls.default_quota_set = set(('injected_file_content_bytes',
46 'metadata_items', 'injected_files',
47 'ram', 'floating_ips',
48 'fixed_ips', 'key_pairs',
49 'injected_file_path_bytes',
50 'instances', 'security_group_rules',
51 'cores', 'security_groups'))
Leo Toyoda87a52b72013-04-09 10:34:40 +090052
Chris Hoge7579c1a2015-02-26 14:12:15 -080053 @test.idempotent_id('f1ef0a97-dbbb-4cca-adc5-c9fbc4f76107')
Leo Toyoda87a52b72013-04-09 10:34:40 +090054 def test_get_quotas(self):
55 # User can get the quota set for it's tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020056 expected_quota_set = self.default_quota_set | set(['id'])
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +000057 quota_set = self.client.show_quota_set(self.tenant_id)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020058 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000059 for quota in expected_quota_set:
60 self.assertIn(quota, quota_set.keys())
Rohit Karajgi07599c52012-11-02 05:35:16 -070061
Zhi Kun Liu90e41312014-03-06 14:56:01 +080062 # get the quota set using user id
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +000063 quota_set = self.client.show_quota_set(self.tenant_id,
64 self.user_id)
Zhi Kun Liu90e41312014-03-06 14:56:01 +080065 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000066 for quota in expected_quota_set:
67 self.assertIn(quota, quota_set.keys())
Zhi Kun Liu90e41312014-03-06 14:56:01 +080068
Chris Hoge7579c1a2015-02-26 14:12:15 -080069 @test.idempotent_id('9bfecac7-b966-4f47-913f-1a9e2c12134a')
Rohit Karajgi07599c52012-11-02 05:35:16 -070070 def test_get_default_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050071 # User can get the default quota set for it's tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020072 expected_quota_set = self.default_quota_set | set(['id'])
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +000073 quota_set = self.client.show_default_quota_set(self.tenant_id)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020074 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000075 for quota in expected_quota_set:
76 self.assertIn(quota, quota_set.keys())
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053077
Chris Hoge7579c1a2015-02-26 14:12:15 -080078 @test.idempotent_id('cd65d997-f7e4-4966-a7e9-d5001b674fdc')
Daniel Korn6653c4e2013-10-28 10:51:23 +020079 def test_compare_tenant_quotas_with_default_quotas(self):
80 # Tenants are created with the default quota values
David Kranz3e4c28b2015-02-09 12:35:18 -050081 defualt_quota_set = \
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +000082 self.client.show_default_quota_set(self.tenant_id)
83 tenant_quota_set = self.client.show_quota_set(self.tenant_id)
Daniel Korn6653c4e2013-10-28 10:51:23 +020084 self.assertEqual(defualt_quota_set, tenant_quota_set)