blob: f49aae4c46bc3a64567a302694a1a1e3a6e13e92 [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
19from tempest.common.utils import data_utils
20from tempest import config
21from tempest import exceptions
22from tempest.test import attr
23from tempest.test import skip_because
24
25
26class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest):
27 _interface = 'json'
28 force_tenant_isolation = True
29
30 @classmethod
31 def setUpClass(cls):
32 super(QuotasAdminTestJSON, cls).setUpClass()
33 cls.auth_url = cls.config.identity.uri
34 cls.client = cls.os.quotas_client
35 cls.adm_client = cls.os_adm.quotas_client
36 cls.identity_admin_client = cls._get_identity_admin_client()
37 cls.sg_client = cls.security_groups_client
38
39 # NOTE(afazekas): these test cases should always create and use a new
40 # tenant most of them should be skipped if we can't do that
41 cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get(
42 'tenantId')
43
44 cls.default_quota_set = set(('injected_file_content_bytes',
45 'metadata_items', 'injected_files',
46 'ram', 'floating_ips',
47 'fixed_ips', 'key_pairs',
48 'injected_file_path_bytes',
49 'instances', 'security_group_rules',
50 'cores', 'security_groups'))
51
52 @attr(type='smoke')
53 def test_get_default_quotas(self):
54 # Admin can get the default resource quota set for a tenant
55 expected_quota_set = self.default_quota_set | set(['id'])
56 resp, quota_set = self.client.get_default_quota_set(
57 self.demo_tenant_id)
58 self.assertEqual(200, resp.status)
59 self.assertEqual(sorted(expected_quota_set),
60 sorted(quota_set.keys()))
61 self.assertEqual(quota_set['id'], self.demo_tenant_id)
62
63 @attr(type='gate')
64 def test_update_all_quota_resources_for_tenant(self):
65 # Admin can update all the resource quota limits for a tenant
66 resp, default_quota_set = self.client.get_default_quota_set(
67 self.demo_tenant_id)
68 new_quota_set = {'injected_file_content_bytes': 20480,
69 'metadata_items': 256, 'injected_files': 10,
70 'ram': 10240, 'floating_ips': 20, 'fixed_ips': 10,
71 'key_pairs': 200, 'injected_file_path_bytes': 512,
72 'instances': 20, 'security_group_rules': 20,
73 'cores': 2, 'security_groups': 20}
74 # Update limits for all quota resources
75 resp, quota_set = self.adm_client.update_quota_set(
76 self.demo_tenant_id,
77 force=True,
78 **new_quota_set)
79
80 default_quota_set.pop('id')
81 self.addCleanup(self.adm_client.update_quota_set,
82 self.demo_tenant_id, **default_quota_set)
83 self.assertEqual(200, resp.status)
84 self.assertEqual(new_quota_set, quota_set)
85
86 # TODO(afazekas): merge these test cases
87 @attr(type='gate')
88 def test_get_updated_quotas(self):
89 # Verify that GET shows the updated quota set
90 tenant_name = data_utils.rand_name('cpu_quota_tenant_')
91 tenant_desc = tenant_name + '-desc'
92 identity_client = self.os_adm.identity_client
93 _, tenant = identity_client.create_tenant(name=tenant_name,
94 description=tenant_desc)
95 tenant_id = tenant['id']
96 self.addCleanup(identity_client.delete_tenant,
97 tenant_id)
98
99 self.adm_client.update_quota_set(tenant_id,
100 ram='5120')
101 resp, quota_set = self.adm_client.get_quota_set(tenant_id)
102 self.assertEqual(200, resp.status)
103 self.assertEqual(quota_set['ram'], 5120)
104
105 # TODO(afazekas): Add dedicated tenant to the skiped quota tests
106 # it can be moved into the setUpClass as well
107 @attr(type='gate')
108 def test_create_server_when_cpu_quota_is_full(self):
109 # Disallow server creation when tenant's vcpu quota is full
110 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
111 default_vcpu_quota = quota_set['cores']
112 vcpu_quota = 0 # Set the quota to zero to conserve resources
113
114 resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
115 force=True,
116 cores=vcpu_quota)
117
118 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
119 cores=default_vcpu_quota)
120 self.assertRaises(exceptions.OverLimit, self.create_test_server)
121
122 @attr(type='gate')
123 def test_create_server_when_memory_quota_is_full(self):
124 # Disallow server creation when tenant's memory quota is full
125 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
126 default_mem_quota = quota_set['ram']
127 mem_quota = 0 # Set the quota to zero to conserve resources
128
129 self.adm_client.update_quota_set(self.demo_tenant_id,
130 force=True,
131 ram=mem_quota)
132
133 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
134 ram=default_mem_quota)
135 self.assertRaises(exceptions.OverLimit, self.create_test_server)
136
137 @attr(type='gate')
138 def test_update_quota_normal_user(self):
139 self.assertRaises(exceptions.Unauthorized,
140 self.client.update_quota_set,
141 self.demo_tenant_id,
142 ram=0)
143
144 @attr(type=['negative', 'gate'])
145 def test_create_server_when_instances_quota_is_full(self):
146 # Once instances quota limit is reached, disallow server creation
147 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
148 default_instances_quota = quota_set['instances']
149 instances_quota = 0 # Set quota to zero to disallow server creation
150
151 self.adm_client.update_quota_set(self.demo_tenant_id,
152 force=True,
153 instances=instances_quota)
154 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
155 instances=default_instances_quota)
156 self.assertRaises(exceptions.OverLimit, self.create_test_server)
157
158 @skip_because(bug="1186354",
159 condition=config.TempestConfig().service_available.neutron)
160 @attr(type=['negative', 'gate'])
161 def test_security_groups_exceed_limit(self):
162 # Negative test: Creation Security Groups over limit should FAIL
163
164 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
165 default_sg_quota = quota_set['security_groups']
166 sg_quota = 0 # Set the quota to zero to conserve resources
167
168 resp, quota_set =\
169 self.adm_client.update_quota_set(self.demo_tenant_id,
170 force=True,
171 security_groups=sg_quota)
172
173 self.addCleanup(self.adm_client.update_quota_set,
174 self.demo_tenant_id,
175 security_groups=default_sg_quota)
176
177 # Check we cannot create anymore
178 self.assertRaises(exceptions.OverLimit,
179 self.sg_client.create_security_group,
180 "sg-overlimit", "sg-desc")
181
182 @skip_because(bug="1186354",
183 condition=config.TempestConfig().service_available.neutron)
184 @attr(type=['negative', 'gate'])
185 def test_security_groups_rules_exceed_limit(self):
186 # Negative test: Creation of Security Group Rules should FAIL
187 # when we reach limit maxSecurityGroupRules
188
189 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
190 default_sg_rules_quota = quota_set['security_group_rules']
191 sg_rules_quota = 0 # Set the quota to zero to conserve resources
192
193 resp, quota_set =\
194 self.adm_client.update_quota_set(
195 self.demo_tenant_id,
196 force=True,
197 security_group_rules=sg_rules_quota)
198
199 self.addCleanup(self.adm_client.update_quota_set,
200 self.demo_tenant_id,
201 security_group_rules=default_sg_rules_quota)
202
203 s_name = data_utils.rand_name('securitygroup-')
204 s_description = data_utils.rand_name('description-')
205 resp, securitygroup =\
206 self.sg_client.create_security_group(s_name, s_description)
207 self.addCleanup(self.sg_client.delete_security_group,
208 securitygroup['id'])
209
210 secgroup_id = securitygroup['id']
211 ip_protocol = 'tcp'
212
213 # Check we cannot create SG rule anymore
214 self.assertRaises(exceptions.OverLimit,
215 self.sg_client.create_security_group_rule,
216 secgroup_id, ip_protocol, 1025, 1025)
217
218
219class QuotasAdminTestXML(QuotasAdminTestJSON):
220 _interface = 'xml'