blob: 0c138bb541c692b60a9254a435a1307758c86505 [file] [log] [blame]
ivan-zhub6d69ee2013-12-17 14:16:31 +08001# Copyright 2013 OpenStack Foundation
ivan-zhu24358182013-11-27 15:08:06 +08002# 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
17from tempest.common.utils import data_utils
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000018from tempest import config
ivan-zhub6d69ee2013-12-17 14:16:31 +080019from tempest import test
Sean Dague86bd8422013-12-20 09:56:44 -050020
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000021CONF = config.CONF
22
ivan-zhu24358182013-11-27 15:08:06 +080023
Ken'ichi Ohmichi7f508ed2014-01-30 22:35:20 +090024class QuotasAdminV3Test(base.BaseV3ComputeAdminTest):
ivan-zhu24358182013-11-27 15:08:06 +080025 force_tenant_isolation = True
26
27 @classmethod
28 def setUpClass(cls):
Ken'ichi Ohmichi7f508ed2014-01-30 22:35:20 +090029 super(QuotasAdminV3Test, cls).setUpClass()
ivan-zhub6d69ee2013-12-17 14:16:31 +080030 cls.client = cls.quotas_client
31 cls.adm_client = cls.quotas_admin_client
ivan-zhu24358182013-11-27 15:08:06 +080032
33 # NOTE(afazekas): these test cases should always create and use a new
34 # tenant most of them should be skipped if we can't do that
35 cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get(
36 'tenantId')
37
ivan-zhub6d69ee2013-12-17 14:16:31 +080038 cls.default_quota_set = set(('metadata_items',
ivan-zhu24358182013-11-27 15:08:06 +080039 'ram', 'floating_ips',
40 'fixed_ips', 'key_pairs',
ivan-zhu24358182013-11-27 15:08:06 +080041 'instances', 'security_group_rules',
42 'cores', 'security_groups'))
43
ivan-zhub6d69ee2013-12-17 14:16:31 +080044 @test.attr(type='smoke')
ivan-zhu24358182013-11-27 15:08:06 +080045 def test_get_default_quotas(self):
46 # Admin can get the default resource quota set for a tenant
47 expected_quota_set = self.default_quota_set | set(['id'])
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +080048 resp, quota_set = self.adm_client.get_default_quota_set(
ivan-zhu24358182013-11-27 15:08:06 +080049 self.demo_tenant_id)
50 self.assertEqual(200, resp.status)
51 self.assertEqual(sorted(expected_quota_set),
52 sorted(quota_set.keys()))
53 self.assertEqual(quota_set['id'], self.demo_tenant_id)
54
Ken'ichi Ohmichi776cda62014-02-18 21:21:23 +090055 @test.attr(type='smoke')
56 def test_get_quota_set_detail(self):
57 # Admin can get the detail of resource quota set for a tenant
58 expected_quota_set = self.default_quota_set | set(['id'])
59 expected_detail = {'reserved', 'limit', 'in_use'}
60 resp, quota_set = self.adm_client.get_quota_set_detail(
61 self.demo_tenant_id)
62 self.assertEqual(200, resp.status)
63 self.assertEqual(sorted(expected_quota_set), sorted(quota_set.keys()))
64 self.assertEqual(quota_set['id'], self.demo_tenant_id)
65 for quota in quota_set:
66 if quota == 'id':
67 continue
68 self.assertEqual(sorted(expected_detail),
69 sorted(quota_set[quota].keys()))
70
ivan-zhub6d69ee2013-12-17 14:16:31 +080071 @test.attr(type='gate')
ivan-zhu24358182013-11-27 15:08:06 +080072 def test_update_all_quota_resources_for_tenant(self):
73 # Admin can update all the resource quota limits for a tenant
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +080074 resp, default_quota_set = self.adm_client.get_default_quota_set(
ivan-zhu24358182013-11-27 15:08:06 +080075 self.demo_tenant_id)
ivan-zhub6d69ee2013-12-17 14:16:31 +080076 new_quota_set = {'metadata_items': 256,
ivan-zhu24358182013-11-27 15:08:06 +080077 'ram': 10240, 'floating_ips': 20, 'fixed_ips': 10,
ivan-zhub6d69ee2013-12-17 14:16:31 +080078 'key_pairs': 200,
ivan-zhu24358182013-11-27 15:08:06 +080079 'instances': 20, 'security_group_rules': 20,
80 'cores': 2, 'security_groups': 20}
81 # Update limits for all quota resources
82 resp, quota_set = self.adm_client.update_quota_set(
83 self.demo_tenant_id,
84 force=True,
85 **new_quota_set)
86
87 default_quota_set.pop('id')
88 self.addCleanup(self.adm_client.update_quota_set,
89 self.demo_tenant_id, **default_quota_set)
90 self.assertEqual(200, resp.status)
ivan-zhub6d69ee2013-12-17 14:16:31 +080091 quota_set.pop('id')
ivan-zhu24358182013-11-27 15:08:06 +080092 self.assertEqual(new_quota_set, quota_set)
93
94 # TODO(afazekas): merge these test cases
ivan-zhub6d69ee2013-12-17 14:16:31 +080095 @test.attr(type='gate')
ivan-zhu24358182013-11-27 15:08:06 +080096 def test_get_updated_quotas(self):
97 # Verify that GET shows the updated quota set
98 tenant_name = data_utils.rand_name('cpu_quota_tenant_')
99 tenant_desc = tenant_name + '-desc'
100 identity_client = self.os_adm.identity_client
101 _, tenant = identity_client.create_tenant(name=tenant_name,
102 description=tenant_desc)
103 tenant_id = tenant['id']
104 self.addCleanup(identity_client.delete_tenant,
105 tenant_id)
106
107 self.adm_client.update_quota_set(tenant_id,
108 ram='5120')
109 resp, quota_set = self.adm_client.get_quota_set(tenant_id)
110 self.assertEqual(200, resp.status)
111 self.assertEqual(quota_set['ram'], 5120)