blob: 4db8c56899b819b430bb2265305757bb3360072b [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
Yuiko Takadae9999d62014-03-06 09:22:54 +000017from tempest import test
Rohit Karajgi07599c52012-11-02 05:35:16 -070018
19
ivan-zhuf2b00502013-10-18 10:06:52 +080020class QuotasTestJSON(base.BaseV2ComputeTest):
Rohit Karajgi07599c52012-11-02 05:35:16 -070021
22 @classmethod
23 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010024 super(QuotasTestJSON, cls).setUpClass()
Rohit Karajgi07599c52012-11-02 05:35:16 -070025 cls.client = cls.quotas_client
26 cls.admin_client = cls._get_identity_admin_client()
27 resp, tenants = cls.admin_client.list_tenants()
28 cls.tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
29 cls.client.tenant_name][0]
Zhi Kun Liu90e41312014-03-06 14:56:01 +080030 resp, users = cls.admin_client.list_users_for_tenant(cls.tenant_id)
31 cls.user_id = [user['id'] for user in users if user['name'] ==
32 cls.client.user][0]
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020033 cls.default_quota_set = set(('injected_file_content_bytes',
34 'metadata_items', 'injected_files',
35 'ram', 'floating_ips',
36 'fixed_ips', 'key_pairs',
37 'injected_file_path_bytes',
38 'instances', 'security_group_rules',
39 'cores', 'security_groups'))
Leo Toyoda87a52b72013-04-09 10:34:40 +090040
Yuiko Takadae9999d62014-03-06 09:22:54 +000041 @test.attr(type='smoke')
Leo Toyoda87a52b72013-04-09 10:34:40 +090042 def test_get_quotas(self):
43 # User can get the quota set for it's tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020044 expected_quota_set = self.default_quota_set | set(['id'])
Leo Toyoda87a52b72013-04-09 10:34:40 +090045 resp, quota_set = self.client.get_quota_set(self.tenant_id)
46 self.assertEqual(200, resp.status)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020047 self.assertEqual(sorted(expected_quota_set),
48 sorted(quota_set.keys()))
49 self.assertEqual(quota_set['id'], self.tenant_id)
Rohit Karajgi07599c52012-11-02 05:35:16 -070050
Zhi Kun Liu90e41312014-03-06 14:56:01 +080051 # get the quota set using user id
52 resp, quota_set = self.client.get_quota_set(self.tenant_id,
53 self.user_id)
54 self.assertEqual(200, resp.status)
55 self.assertEqual(sorted(expected_quota_set),
56 sorted(quota_set.keys()))
57 self.assertEqual(quota_set['id'], self.tenant_id)
58
Yuiko Takadae9999d62014-03-06 09:22:54 +000059 @test.attr(type='smoke')
Rohit Karajgi07599c52012-11-02 05:35:16 -070060 def test_get_default_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050061 # User can get the default quota set for it's tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020062 expected_quota_set = self.default_quota_set | set(['id'])
Leo Toyoda87a52b72013-04-09 10:34:40 +090063 resp, quota_set = self.client.get_default_quota_set(self.tenant_id)
64 self.assertEqual(200, resp.status)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020065 self.assertEqual(sorted(expected_quota_set),
66 sorted(quota_set.keys()))
67 self.assertEqual(quota_set['id'], self.tenant_id)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053068
Yuiko Takadae9999d62014-03-06 09:22:54 +000069 @test.attr(type='smoke')
Daniel Korn6653c4e2013-10-28 10:51:23 +020070 def test_compare_tenant_quotas_with_default_quotas(self):
71 # Tenants are created with the default quota values
72 resp, defualt_quota_set = \
73 self.client.get_default_quota_set(self.tenant_id)
74 self.assertEqual(200, resp.status)
75 resp, tenant_quota_set = self.client.get_quota_set(self.tenant_id)
76 self.assertEqual(200, resp.status)
77 self.assertEqual(defualt_quota_set, tenant_quota_set)
78
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053079
Attila Fazekas19044d52013-02-16 07:35:06 +010080class QuotasTestXML(QuotasTestJSON):
81 _interface = 'xml'