blob: f6d8b3f8bc5b4bc3a9ebf884109a12753c5c0236 [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
Matt Riedemann848805f2014-06-16 13:23:51 -070017from tempest.common import tempest_fixtures as fixtures
ivan-zhub6d69ee2013-12-17 14:16:31 +080018from tempest import test
ivan-zhu24358182013-11-27 15:08:06 +080019
20
Ken'ichi Ohmichi7f508ed2014-01-30 22:35:20 +090021class QuotasV3Test(base.BaseV3ComputeTest):
ivan-zhu24358182013-11-27 15:08:06 +080022
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(QuotasV3Test, self).setUp()
27
ivan-zhu24358182013-11-27 15:08:06 +080028 @classmethod
Andrea Frittoli3d3efba2014-09-15 12:36:30 +010029 def resource_setup(cls):
30 super(QuotasV3Test, cls).resource_setup()
ivan-zhu24358182013-11-27 15:08:06 +080031 cls.client = cls.quotas_client
Andrea Frittoli9612e812014-03-13 10:57:26 +000032 cls.tenant_id = cls.client.tenant_id
33 cls.user_id = cls.client.user_id
ivan-zhub6d69ee2013-12-17 14:16:31 +080034 cls.default_quota_set = set(('metadata_items',
ivan-zhu24358182013-11-27 15:08:06 +080035 'ram', 'floating_ips',
36 'fixed_ips', 'key_pairs',
ivan-zhu24358182013-11-27 15:08:06 +080037 'instances', 'security_group_rules',
38 'cores', 'security_groups'))
39
ivan-zhub6d69ee2013-12-17 14:16:31 +080040 @test.attr(type='smoke')
ivan-zhu24358182013-11-27 15:08:06 +080041 def test_get_quotas(self):
42 # User can get the quota set for it's tenant
43 expected_quota_set = self.default_quota_set | set(['id'])
44 resp, quota_set = self.client.get_quota_set(self.tenant_id)
45 self.assertEqual(200, resp.status)
46 self.assertEqual(sorted(expected_quota_set),
47 sorted(quota_set.keys()))
48 self.assertEqual(quota_set['id'], self.tenant_id)
49
Zhi Kun Liu90e41312014-03-06 14:56:01 +080050 # get the quota set using user id
51 resp, quota_set = self.client.get_quota_set(self.tenant_id,
52 self.user_id)
53 self.assertEqual(200, resp.status)
54 self.assertEqual(sorted(expected_quota_set),
55 sorted(quota_set.keys()))
56 self.assertEqual(quota_set['id'], self.tenant_id)
57
ivan-zhub6d69ee2013-12-17 14:16:31 +080058 @test.attr(type='smoke')
ivan-zhu24358182013-11-27 15:08:06 +080059 def test_get_default_quotas(self):
60 # User can get the default quota set for it's tenant
61 expected_quota_set = self.default_quota_set | set(['id'])
62 resp, quota_set = self.client.get_default_quota_set(self.tenant_id)
63 self.assertEqual(200, resp.status)
64 self.assertEqual(sorted(expected_quota_set),
65 sorted(quota_set.keys()))
66 self.assertEqual(quota_set['id'], self.tenant_id)
67
ivan-zhub6d69ee2013-12-17 14:16:31 +080068 @test.attr(type='smoke')
ivan-zhu24358182013-11-27 15:08:06 +080069 def test_compare_tenant_quotas_with_default_quotas(self):
70 # Tenants are created with the default quota values
71 resp, defualt_quota_set = \
72 self.client.get_default_quota_set(self.tenant_id)
73 self.assertEqual(200, resp.status)
74 resp, tenant_quota_set = self.client.get_quota_set(self.tenant_id)
75 self.assertEqual(200, resp.status)
76 self.assertEqual(defualt_quota_set, tenant_quota_set)