blob: 3e98029ecd3c04de34c9e8418d6c0354714775db [file] [log] [blame]
Rohit Karajgi07599c52012-11-02 05:35:16 -07001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
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
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -070019from tempest.common.utils.data_utils import rand_name
Rohit Karajgi07599c52012-11-02 05:35:16 -070020from tempest import exceptions
Chris Yeoh9465b0b2013-02-09 22:19:15 +103021from tempest.test import attr
gengjh083f8222013-05-24 23:31:46 +080022import testtools
Rohit Karajgi07599c52012-11-02 05:35:16 -070023
24
Attila Fazekas19044d52013-02-16 07:35:06 +010025class QuotasAdminTestJSON(base.BaseComputeAdminTest):
26 _interface = 'json'
Rohit Karajgi07599c52012-11-02 05:35:16 -070027
28 @classmethod
29 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010030 super(QuotasAdminTestJSON, cls).setUpClass()
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053031 cls.auth_url = cls.config.identity.uri
Rohit Karajgi07599c52012-11-02 05:35:16 -070032 cls.client = cls.os.quotas_client
Attila Fazekas4ba36582013-02-12 08:26:17 +010033 cls.adm_client = cls.os_adm.quotas_client
Rohit Karajgi07599c52012-11-02 05:35:16 -070034 cls.identity_admin_client = cls._get_identity_admin_client()
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -070035 cls.sg_client = cls.security_groups_client
Attila Fazekas4ba36582013-02-12 08:26:17 +010036
Rohit Karajgi07599c52012-11-02 05:35:16 -070037 resp, tenants = cls.identity_admin_client.list_tenants()
38
Attila Fazekas4ba36582013-02-12 08:26:17 +010039 #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
Rohit Karajgi07599c52012-11-02 05:35:16 -070041 if cls.config.compute.allow_tenant_isolation:
42 cls.demo_tenant_id = cls.isolated_creds[0][0]['tenantId']
43 else:
44 cls.demo_tenant_id = [tnt['id'] for tnt in tenants if tnt['name']
Attila Fazekascadcb1f2013-01-21 23:10:53 +010045 == cls.config.identity.tenant_name][0]
Rohit Karajgi07599c52012-11-02 05:35:16 -070046
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020047 cls.default_quota_set = set(('injected_file_content_bytes',
48 'metadata_items', 'injected_files',
49 'ram', 'floating_ips',
50 'fixed_ips', 'key_pairs',
51 'injected_file_path_bytes',
52 'instances', 'security_group_rules',
53 'cores', 'security_groups'))
Rohit Karajgi07599c52012-11-02 05:35:16 -070054
55 @classmethod
ivan-zhu1feeb382013-01-24 10:14:39 +080056 def tearDownClass(cls):
Rohit Karajgi07599c52012-11-02 05:35:16 -070057 for server in cls.servers:
58 try:
59 cls.servers_client.delete_server(server['id'])
60 except exceptions.NotFound:
61 continue
Attila Fazekas19044d52013-02-16 07:35:06 +010062 super(QuotasAdminTestJSON, cls).tearDownClass()
Rohit Karajgi07599c52012-11-02 05:35:16 -070063
64 @attr(type='smoke')
65 def test_get_default_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050066 # Admin can get the default resource quota set for a tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020067 expected_quota_set = self.default_quota_set | set(['id'])
Leo Toyoda87a52b72013-04-09 10:34:40 +090068 resp, quota_set = self.client.get_default_quota_set(
69 self.demo_tenant_id)
70 self.assertEqual(200, resp.status)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020071 self.assertEqual(sorted(expected_quota_set),
72 sorted(quota_set.keys()))
73 self.assertEqual(quota_set['id'], self.demo_tenant_id)
Rohit Karajgi07599c52012-11-02 05:35:16 -070074
gengjh083f8222013-05-24 23:31:46 +080075 @testtools.skip("Skipped until the Bug #1160749 is resolved")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040076 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -070077 def test_update_all_quota_resources_for_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050078 # Admin can update all the resource quota limits for a tenant
gengjh07fe8302013-04-17 16:15:22 +080079 new_quota_set = {'force': True,
80 'injected_file_content_bytes': 20480,
Rohit Karajgi07599c52012-11-02 05:35:16 -070081 'metadata_items': 256, 'injected_files': 10,
Michael Still9ac5bd02013-03-15 04:32:46 +110082 'ram': 10240, 'floating_ips': 20, 'fixed_ips': 10,
83 'key_pairs': 200, 'injected_file_path_bytes': 512,
84 'instances': 20, 'security_group_rules': 20,
85 'cores': 2, 'security_groups': 20}
Rohit Karajgi07599c52012-11-02 05:35:16 -070086 try:
87 # Update limits for all quota resources
88 resp, quota_set = self.adm_client.update_quota_set(
89 self.demo_tenant_id,
90 **new_quota_set)
Leo Toyodad5407792013-03-28 14:57:15 +090091 self.addCleanup(self.adm_client.update_quota_set,
92 self.demo_tenant_id, **self.default_quota_set)
Rohit Karajgi07599c52012-11-02 05:35:16 -070093 self.assertEqual(200, resp.status)
Michael J Fork7a313652013-02-11 23:23:02 +000094 self.assertEqual(new_quota_set, quota_set)
Matthew Treinish05d9fb92012-12-07 16:14:05 -050095 except Exception:
Rohit Karajgi07599c52012-11-02 05:35:16 -070096 self.fail("Admin could not update quota set for the tenant")
97 finally:
98 # Reset quota resource limits to default values
99 resp, quota_set = self.adm_client.update_quota_set(
100 self.demo_tenant_id,
101 **self.default_quota_set)
102 self.assertEqual(200, resp.status, "Failed to reset quota "
103 "defaults")
104
Attila Fazekas4ba36582013-02-12 08:26:17 +0100105 #TODO(afazekas): merge these test cases
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400106 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700107 def test_get_updated_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500108 # Verify that GET shows the updated quota set
Attila Fazekasd9aef1e2013-07-13 17:33:45 +0200109 tenant_name = rand_name('cpu_quota_tenant_')
110 tenant_desc = tenant_name + '-desc'
111 identity_client = self.os_adm.identity_client
112 _, tenant = identity_client.create_tenant(name=tenant_name,
113 description=tenant_desc)
114 tenant_id = tenant['id']
115 self.addCleanup(identity_client.delete_tenant,
116 tenant_id)
Rohit Karajgi07599c52012-11-02 05:35:16 -0700117
Attila Fazekasd9aef1e2013-07-13 17:33:45 +0200118 self.adm_client.update_quota_set(tenant_id,
119 ram='5120')
120 resp, quota_set = self.adm_client.get_quota_set(tenant_id)
121 self.assertEqual(200, resp.status)
122 self.assertEqual(quota_set['ram'], 5120)
123
124 #TODO(afazekas): Add dedicated tenant to the skiped quota tests
125 # it can be moved into the setUpClass as well
gengjh083f8222013-05-24 23:31:46 +0800126 @testtools.skip("Skipped until the Bug #1160749 is resolved")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400127 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700128 def test_create_server_when_cpu_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500129 # Disallow server creation when tenant's vcpu quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700130 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
131 default_vcpu_quota = quota_set['cores']
132 vcpu_quota = 0 # Set the quota to zero to conserve resources
133
134 resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
gengjh07fe8302013-04-17 16:15:22 +0800135 force=True,
Rohit Karajgi07599c52012-11-02 05:35:16 -0700136 cores=vcpu_quota)
hi2sureshaab7b482013-03-12 04:41:38 +0000137
138 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
139 cores=default_vcpu_quota)
140 self.assertRaises(exceptions.OverLimit, self.create_server)
Rohit Karajgi07599c52012-11-02 05:35:16 -0700141
gengjh083f8222013-05-24 23:31:46 +0800142 @testtools.skip("Skipped until the Bug #1160749 is resolved")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400143 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700144 def test_create_server_when_memory_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500145 # Disallow server creation when tenant's memory quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700146 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
147 default_mem_quota = quota_set['ram']
148 mem_quota = 0 # Set the quota to zero to conserve resources
149
150 self.adm_client.update_quota_set(self.demo_tenant_id,
gengjh07fe8302013-04-17 16:15:22 +0800151 force=True,
Rohit Karajgi07599c52012-11-02 05:35:16 -0700152 ram=mem_quota)
hi2sureshda748f12013-03-13 03:31:14 +0000153
154 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
155 ram=default_mem_quota)
156 self.assertRaises(exceptions.OverLimit, self.create_server)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530157
Attila Fazekas4ba36582013-02-12 08:26:17 +0100158#TODO(afazekas): Add test that tried to update the quota_set as a regular user
159
gengjh083f8222013-05-24 23:31:46 +0800160 @testtools.skip("Skipped until the Bug #1160749 is resolved")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400161 @attr(type=['negative', 'gate'])
hi2sureshb546db02013-02-21 10:21:32 +0000162 def test_create_server_when_instances_quota_is_full(self):
163 #Once instances quota limit is reached, disallow server creation
164 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
165 default_instances_quota = quota_set['instances']
166 instances_quota = 0 # Set quota to zero to disallow server creation
167
168 self.adm_client.update_quota_set(self.demo_tenant_id,
gengjh07fe8302013-04-17 16:15:22 +0800169 force=True,
hi2sureshb546db02013-02-21 10:21:32 +0000170 instances=instances_quota)
171 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
172 instances=default_instances_quota)
173 self.assertRaises(exceptions.OverLimit, self.create_server)
174
gengjh083f8222013-05-24 23:31:46 +0800175 @testtools.skip("Skipped until the Bug #1160749 is resolved")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400176 @attr(type=['negative', 'gate'])
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700177 def test_security_groups_exceed_limit(self):
178 # Negative test: Creation Security Groups over limit should FAIL
179
180 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
181 default_sg_quota = quota_set['security_groups']
182 sg_quota = 0 # Set the quota to zero to conserve resources
183
184 resp, quota_set =\
185 self.adm_client.update_quota_set(self.demo_tenant_id,
186 security_groups=sg_quota)
187
188 self.addCleanup(self.adm_client.update_quota_set,
189 self.demo_tenant_id,
190 security_groups=default_sg_quota)
191
192 # Check we cannot create anymore
193 self.assertRaises(exceptions.OverLimit,
194 self.sg_client.create_security_group,
195 "sg-overlimit", "sg-desc")
196
gengjh083f8222013-05-24 23:31:46 +0800197 @testtools.skip("Skipped until the Bug #1160749 is resolved")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400198 @attr(type=['negative', 'gate'])
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700199 def test_security_groups_rules_exceed_limit(self):
200 # Negative test: Creation of Security Group Rules should FAIL
201 # when we reach limit maxSecurityGroupRules
202
203 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
204 default_sg_rules_quota = quota_set['security_group_rules']
205 sg_rules_quota = 0 # Set the quota to zero to conserve resources
206
207 resp, quota_set =\
208 self.adm_client.update_quota_set(
209 self.demo_tenant_id,
210 security_group_rules=sg_rules_quota)
211
212 self.addCleanup(self.adm_client.update_quota_set,
213 self.demo_tenant_id,
214 security_group_rules=default_sg_rules_quota)
215
216 s_name = rand_name('securitygroup-')
217 s_description = rand_name('description-')
218 resp, securitygroup =\
219 self.sg_client.create_security_group(s_name, s_description)
220 self.addCleanup(self.sg_client.delete_security_group,
221 securitygroup['id'])
222
223 secgroup_id = securitygroup['id']
224 ip_protocol = 'tcp'
225
226 # Check we cannot create SG rule anymore
227 self.assertRaises(exceptions.OverLimit,
228 self.sg_client.create_security_group_rule,
229 secgroup_id, ip_protocol, 1025, 1025)
230
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530231
Attila Fazekas19044d52013-02-16 07:35:06 +0100232class QuotasAdminTestXML(QuotasAdminTestJSON):
233 _interface = 'xml'