blob: 86bf5fa2fddf7be151652f6fa21076c114419d20 [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
Matt Riedemann848805f2014-06-16 13:23:51 -070023 def setUp(self):
24 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
25 self.useFixture(fixtures.LockFixture('compute_quotas'))
26 super(QuotasTestJSON, self).setUp()
27
Rohit Karajgi07599c52012-11-02 05:35:16 -070028 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053029 def setup_clients(cls):
30 super(QuotasTestJSON, cls).setup_clients()
31 cls.client = cls.quotas_client
32
33 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010034 def resource_setup(cls):
35 super(QuotasTestJSON, cls).resource_setup()
Andrea Frittoli9612e812014-03-13 10:57:26 +000036 cls.tenant_id = cls.client.tenant_id
37 cls.user_id = cls.client.user_id
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020038 cls.default_quota_set = set(('injected_file_content_bytes',
39 'metadata_items', 'injected_files',
40 'ram', 'floating_ips',
41 'fixed_ips', 'key_pairs',
42 'injected_file_path_bytes',
43 'instances', 'security_group_rules',
44 'cores', 'security_groups'))
Leo Toyoda87a52b72013-04-09 10:34:40 +090045
Yuiko Takadae9999d62014-03-06 09:22:54 +000046 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080047 @test.idempotent_id('f1ef0a97-dbbb-4cca-adc5-c9fbc4f76107')
Leo Toyoda87a52b72013-04-09 10:34:40 +090048 def test_get_quotas(self):
49 # User can get the quota set for it's tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020050 expected_quota_set = self.default_quota_set | set(['id'])
David Kranz3e4c28b2015-02-09 12:35:18 -050051 quota_set = self.client.get_quota_set(self.tenant_id)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020052 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000053 for quota in expected_quota_set:
54 self.assertIn(quota, quota_set.keys())
Rohit Karajgi07599c52012-11-02 05:35:16 -070055
Zhi Kun Liu90e41312014-03-06 14:56:01 +080056 # get the quota set using user id
David Kranz3e4c28b2015-02-09 12:35:18 -050057 quota_set = self.client.get_quota_set(self.tenant_id,
58 self.user_id)
Zhi Kun Liu90e41312014-03-06 14:56:01 +080059 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000060 for quota in expected_quota_set:
61 self.assertIn(quota, quota_set.keys())
Zhi Kun Liu90e41312014-03-06 14:56:01 +080062
Yuiko Takadae9999d62014-03-06 09:22:54 +000063 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080064 @test.idempotent_id('9bfecac7-b966-4f47-913f-1a9e2c12134a')
Rohit Karajgi07599c52012-11-02 05:35:16 -070065 def test_get_default_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050066 # User can get the default quota set for it's tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020067 expected_quota_set = self.default_quota_set | set(['id'])
David Kranz3e4c28b2015-02-09 12:35:18 -050068 quota_set = self.client.get_default_quota_set(self.tenant_id)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020069 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000070 for quota in expected_quota_set:
71 self.assertIn(quota, quota_set.keys())
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053072
Yuiko Takadae9999d62014-03-06 09:22:54 +000073 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080074 @test.idempotent_id('cd65d997-f7e4-4966-a7e9-d5001b674fdc')
Daniel Korn6653c4e2013-10-28 10:51:23 +020075 def test_compare_tenant_quotas_with_default_quotas(self):
76 # Tenants are created with the default quota values
David Kranz3e4c28b2015-02-09 12:35:18 -050077 defualt_quota_set = \
Daniel Korn6653c4e2013-10-28 10:51:23 +020078 self.client.get_default_quota_set(self.tenant_id)
David Kranz3e4c28b2015-02-09 12:35:18 -050079 tenant_quota_set = self.client.get_quota_set(self.tenant_id)
Daniel Korn6653c4e2013-10-28 10:51:23 +020080 self.assertEqual(defualt_quota_set, tenant_quota_set)