blob: d2f80a575e81330edef239816805ad2870f4a4f8 [file] [log] [blame]
ivan-zhu24358182013-11-27 15:08:06 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack Foundation
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18from tempest.api.compute import base
ivan-zhub6d69ee2013-12-17 14:16:31 +080019from tempest import test
ivan-zhu24358182013-11-27 15:08:06 +080020
21
ivan-zhub6d69ee2013-12-17 14:16:31 +080022class QuotasV3TestJSON(base.BaseV3ComputeTest):
ivan-zhu24358182013-11-27 15:08:06 +080023 _interface = 'json'
24
25 @classmethod
26 def setUpClass(cls):
ivan-zhub6d69ee2013-12-17 14:16:31 +080027 super(QuotasV3TestJSON, cls).setUpClass()
ivan-zhu24358182013-11-27 15:08:06 +080028 cls.client = cls.quotas_client
29 cls.admin_client = cls._get_identity_admin_client()
30 resp, tenants = cls.admin_client.list_tenants()
31 cls.tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
32 cls.client.tenant_name][0]
ivan-zhub6d69ee2013-12-17 14:16:31 +080033 cls.default_quota_set = set(('metadata_items',
ivan-zhu24358182013-11-27 15:08:06 +080034 'ram', 'floating_ips',
35 'fixed_ips', 'key_pairs',
ivan-zhu24358182013-11-27 15:08:06 +080036 'instances', 'security_group_rules',
37 'cores', 'security_groups'))
38
ivan-zhub6d69ee2013-12-17 14:16:31 +080039 @test.attr(type='smoke')
ivan-zhu24358182013-11-27 15:08:06 +080040 def test_get_quotas(self):
41 # User can get the quota set for it's tenant
42 expected_quota_set = self.default_quota_set | set(['id'])
43 resp, quota_set = self.client.get_quota_set(self.tenant_id)
44 self.assertEqual(200, resp.status)
45 self.assertEqual(sorted(expected_quota_set),
46 sorted(quota_set.keys()))
47 self.assertEqual(quota_set['id'], self.tenant_id)
48
ivan-zhub6d69ee2013-12-17 14:16:31 +080049 @test.attr(type='smoke')
ivan-zhu24358182013-11-27 15:08:06 +080050 def test_get_default_quotas(self):
51 # User can get the default quota set for it's tenant
52 expected_quota_set = self.default_quota_set | set(['id'])
53 resp, quota_set = self.client.get_default_quota_set(self.tenant_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
ivan-zhub6d69ee2013-12-17 14:16:31 +080059 @test.attr(type='smoke')
ivan-zhu24358182013-11-27 15:08:06 +080060 def test_compare_tenant_quotas_with_default_quotas(self):
61 # Tenants are created with the default quota values
62 resp, defualt_quota_set = \
63 self.client.get_default_quota_set(self.tenant_id)
64 self.assertEqual(200, resp.status)
65 resp, tenant_quota_set = self.client.get_quota_set(self.tenant_id)
66 self.assertEqual(200, resp.status)
67 self.assertEqual(defualt_quota_set, tenant_quota_set)
68
69
ivan-zhub6d69ee2013-12-17 14:16:31 +080070class QuotasV3TestXML(QuotasV3TestJSON):
ivan-zhu24358182013-11-27 15:08:06 +080071 _interface = 'xml'