blob: 1cbfa2baca6e2af568187eb0b95f8f2df4650f7d [file] [log] [blame]
ivan-zhu24358182013-11-27 15:08:06 +08001# Copyright 2012 OpenStack Foundation
2# 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
16from tempest.api.compute import base
ivan-zhub6d69ee2013-12-17 14:16:31 +080017from tempest import test
ivan-zhu24358182013-11-27 15:08:06 +080018
19
ivan-zhub6d69ee2013-12-17 14:16:31 +080020class QuotasV3TestJSON(base.BaseV3ComputeTest):
ivan-zhu24358182013-11-27 15:08:06 +080021 _interface = 'json'
22
23 @classmethod
24 def setUpClass(cls):
ivan-zhub6d69ee2013-12-17 14:16:31 +080025 super(QuotasV3TestJSON, cls).setUpClass()
ivan-zhu24358182013-11-27 15:08:06 +080026 cls.client = cls.quotas_client
27 cls.admin_client = cls._get_identity_admin_client()
28 resp, tenants = cls.admin_client.list_tenants()
29 cls.tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
30 cls.client.tenant_name][0]
ivan-zhub6d69ee2013-12-17 14:16:31 +080031 cls.default_quota_set = set(('metadata_items',
ivan-zhu24358182013-11-27 15:08:06 +080032 'ram', 'floating_ips',
33 'fixed_ips', 'key_pairs',
ivan-zhu24358182013-11-27 15:08:06 +080034 'instances', 'security_group_rules',
35 'cores', 'security_groups'))
36
ivan-zhub6d69ee2013-12-17 14:16:31 +080037 @test.attr(type='smoke')
ivan-zhu24358182013-11-27 15:08:06 +080038 def test_get_quotas(self):
39 # User can get the quota set for it's tenant
40 expected_quota_set = self.default_quota_set | set(['id'])
41 resp, quota_set = self.client.get_quota_set(self.tenant_id)
42 self.assertEqual(200, resp.status)
43 self.assertEqual(sorted(expected_quota_set),
44 sorted(quota_set.keys()))
45 self.assertEqual(quota_set['id'], self.tenant_id)
46
ivan-zhub6d69ee2013-12-17 14:16:31 +080047 @test.attr(type='smoke')
ivan-zhu24358182013-11-27 15:08:06 +080048 def test_get_default_quotas(self):
49 # User can get the default quota set for it's tenant
50 expected_quota_set = self.default_quota_set | set(['id'])
51 resp, quota_set = self.client.get_default_quota_set(self.tenant_id)
52 self.assertEqual(200, resp.status)
53 self.assertEqual(sorted(expected_quota_set),
54 sorted(quota_set.keys()))
55 self.assertEqual(quota_set['id'], self.tenant_id)
56
ivan-zhub6d69ee2013-12-17 14:16:31 +080057 @test.attr(type='smoke')
ivan-zhu24358182013-11-27 15:08:06 +080058 def test_compare_tenant_quotas_with_default_quotas(self):
59 # Tenants are created with the default quota values
60 resp, defualt_quota_set = \
61 self.client.get_default_quota_set(self.tenant_id)
62 self.assertEqual(200, resp.status)
63 resp, tenant_quota_set = self.client.get_quota_set(self.tenant_id)
64 self.assertEqual(200, resp.status)
65 self.assertEqual(defualt_quota_set, tenant_quota_set)