blob: 4e42dd0cb0fa564984b2657fa599f406c484de5f [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 Fazekasf7f34f92013-08-01 17:01:44 +020039 # NOTE(afazekas): these test cases should always create and use a new
Attila Fazekas4ba36582013-02-12 08:26:17 +010040 # 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:
Matthew Treinishb86cda92013-07-29 11:22:23 -040042 cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get(
43 'tenantId')
Rohit Karajgi07599c52012-11-02 05:35:16 -070044 else:
45 cls.demo_tenant_id = [tnt['id'] for tnt in tenants if tnt['name']
Attila Fazekascadcb1f2013-01-21 23:10:53 +010046 == cls.config.identity.tenant_name][0]
Rohit Karajgi07599c52012-11-02 05:35:16 -070047
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020048 cls.default_quota_set = set(('injected_file_content_bytes',
49 'metadata_items', 'injected_files',
50 'ram', 'floating_ips',
51 'fixed_ips', 'key_pairs',
52 'injected_file_path_bytes',
53 'instances', 'security_group_rules',
54 'cores', 'security_groups'))
Rohit Karajgi07599c52012-11-02 05:35:16 -070055
56 @classmethod
ivan-zhu1feeb382013-01-24 10:14:39 +080057 def tearDownClass(cls):
Rohit Karajgi07599c52012-11-02 05:35:16 -070058 for server in cls.servers:
59 try:
60 cls.servers_client.delete_server(server['id'])
61 except exceptions.NotFound:
62 continue
Attila Fazekas19044d52013-02-16 07:35:06 +010063 super(QuotasAdminTestJSON, cls).tearDownClass()
Rohit Karajgi07599c52012-11-02 05:35:16 -070064
65 @attr(type='smoke')
66 def test_get_default_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050067 # Admin can get the default resource quota set for a tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020068 expected_quota_set = self.default_quota_set | set(['id'])
Leo Toyoda87a52b72013-04-09 10:34:40 +090069 resp, quota_set = self.client.get_default_quota_set(
70 self.demo_tenant_id)
71 self.assertEqual(200, resp.status)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020072 self.assertEqual(sorted(expected_quota_set),
73 sorted(quota_set.keys()))
74 self.assertEqual(quota_set['id'], self.demo_tenant_id)
Rohit Karajgi07599c52012-11-02 05:35:16 -070075
gengjh083f8222013-05-24 23:31:46 +080076 @testtools.skip("Skipped until the Bug #1160749 is resolved")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040077 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -070078 def test_update_all_quota_resources_for_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050079 # Admin can update all the resource quota limits for a tenant
gengjh07fe8302013-04-17 16:15:22 +080080 new_quota_set = {'force': True,
81 'injected_file_content_bytes': 20480,
Rohit Karajgi07599c52012-11-02 05:35:16 -070082 'metadata_items': 256, 'injected_files': 10,
Michael Still9ac5bd02013-03-15 04:32:46 +110083 'ram': 10240, 'floating_ips': 20, 'fixed_ips': 10,
84 'key_pairs': 200, 'injected_file_path_bytes': 512,
85 'instances': 20, 'security_group_rules': 20,
86 'cores': 2, 'security_groups': 20}
Rohit Karajgi07599c52012-11-02 05:35:16 -070087 try:
88 # Update limits for all quota resources
89 resp, quota_set = self.adm_client.update_quota_set(
90 self.demo_tenant_id,
91 **new_quota_set)
Leo Toyodad5407792013-03-28 14:57:15 +090092 self.addCleanup(self.adm_client.update_quota_set,
93 self.demo_tenant_id, **self.default_quota_set)
Rohit Karajgi07599c52012-11-02 05:35:16 -070094 self.assertEqual(200, resp.status)
Michael J Fork7a313652013-02-11 23:23:02 +000095 self.assertEqual(new_quota_set, quota_set)
Matthew Treinish05d9fb92012-12-07 16:14:05 -050096 except Exception:
Rohit Karajgi07599c52012-11-02 05:35:16 -070097 self.fail("Admin could not update quota set for the tenant")
98 finally:
99 # Reset quota resource limits to default values
100 resp, quota_set = self.adm_client.update_quota_set(
101 self.demo_tenant_id,
102 **self.default_quota_set)
103 self.assertEqual(200, resp.status, "Failed to reset quota "
104 "defaults")
105
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200106 # TODO(afazekas): merge these test cases
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400107 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700108 def test_get_updated_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500109 # Verify that GET shows the updated quota set
Attila Fazekasd9aef1e2013-07-13 17:33:45 +0200110 tenant_name = rand_name('cpu_quota_tenant_')
111 tenant_desc = tenant_name + '-desc'
112 identity_client = self.os_adm.identity_client
113 _, tenant = identity_client.create_tenant(name=tenant_name,
114 description=tenant_desc)
115 tenant_id = tenant['id']
116 self.addCleanup(identity_client.delete_tenant,
117 tenant_id)
Rohit Karajgi07599c52012-11-02 05:35:16 -0700118
Attila Fazekasd9aef1e2013-07-13 17:33:45 +0200119 self.adm_client.update_quota_set(tenant_id,
120 ram='5120')
121 resp, quota_set = self.adm_client.get_quota_set(tenant_id)
122 self.assertEqual(200, resp.status)
123 self.assertEqual(quota_set['ram'], 5120)
124
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200125 # TODO(afazekas): Add dedicated tenant to the skiped quota tests
Attila Fazekasd9aef1e2013-07-13 17:33:45 +0200126 # it can be moved into the setUpClass as well
gengjh083f8222013-05-24 23:31:46 +0800127 @testtools.skip("Skipped until the Bug #1160749 is resolved")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400128 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700129 def test_create_server_when_cpu_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500130 # Disallow server creation when tenant's vcpu quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700131 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
132 default_vcpu_quota = quota_set['cores']
133 vcpu_quota = 0 # Set the quota to zero to conserve resources
134
135 resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
gengjh07fe8302013-04-17 16:15:22 +0800136 force=True,
Rohit Karajgi07599c52012-11-02 05:35:16 -0700137 cores=vcpu_quota)
hi2sureshaab7b482013-03-12 04:41:38 +0000138
139 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
140 cores=default_vcpu_quota)
141 self.assertRaises(exceptions.OverLimit, self.create_server)
Rohit Karajgi07599c52012-11-02 05:35:16 -0700142
gengjh083f8222013-05-24 23:31:46 +0800143 @testtools.skip("Skipped until the Bug #1160749 is resolved")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400144 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700145 def test_create_server_when_memory_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500146 # Disallow server creation when tenant's memory quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700147 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
148 default_mem_quota = quota_set['ram']
149 mem_quota = 0 # Set the quota to zero to conserve resources
150
151 self.adm_client.update_quota_set(self.demo_tenant_id,
gengjh07fe8302013-04-17 16:15:22 +0800152 force=True,
Rohit Karajgi07599c52012-11-02 05:35:16 -0700153 ram=mem_quota)
hi2sureshda748f12013-03-13 03:31:14 +0000154
155 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
156 ram=default_mem_quota)
157 self.assertRaises(exceptions.OverLimit, self.create_server)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530158
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200159# TODO(afazekas): Add test that tried to update the quota_set as a regular user
Attila Fazekas4ba36582013-02-12 08:26:17 +0100160
gengjh083f8222013-05-24 23:31:46 +0800161 @testtools.skip("Skipped until the Bug #1160749 is resolved")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400162 @attr(type=['negative', 'gate'])
hi2sureshb546db02013-02-21 10:21:32 +0000163 def test_create_server_when_instances_quota_is_full(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200164 # Once instances quota limit is reached, disallow server creation
hi2sureshb546db02013-02-21 10:21:32 +0000165 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
166 default_instances_quota = quota_set['instances']
167 instances_quota = 0 # Set quota to zero to disallow server creation
168
169 self.adm_client.update_quota_set(self.demo_tenant_id,
gengjh07fe8302013-04-17 16:15:22 +0800170 force=True,
hi2sureshb546db02013-02-21 10:21:32 +0000171 instances=instances_quota)
172 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
173 instances=default_instances_quota)
174 self.assertRaises(exceptions.OverLimit, self.create_server)
175
gengjh083f8222013-05-24 23:31:46 +0800176 @testtools.skip("Skipped until the Bug #1160749 is resolved")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400177 @attr(type=['negative', 'gate'])
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700178 def test_security_groups_exceed_limit(self):
179 # Negative test: Creation Security Groups over limit should FAIL
180
181 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
182 default_sg_quota = quota_set['security_groups']
183 sg_quota = 0 # Set the quota to zero to conserve resources
184
185 resp, quota_set =\
186 self.adm_client.update_quota_set(self.demo_tenant_id,
187 security_groups=sg_quota)
188
189 self.addCleanup(self.adm_client.update_quota_set,
190 self.demo_tenant_id,
191 security_groups=default_sg_quota)
192
193 # Check we cannot create anymore
194 self.assertRaises(exceptions.OverLimit,
195 self.sg_client.create_security_group,
196 "sg-overlimit", "sg-desc")
197
gengjh083f8222013-05-24 23:31:46 +0800198 @testtools.skip("Skipped until the Bug #1160749 is resolved")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400199 @attr(type=['negative', 'gate'])
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700200 def test_security_groups_rules_exceed_limit(self):
201 # Negative test: Creation of Security Group Rules should FAIL
202 # when we reach limit maxSecurityGroupRules
203
204 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
205 default_sg_rules_quota = quota_set['security_group_rules']
206 sg_rules_quota = 0 # Set the quota to zero to conserve resources
207
208 resp, quota_set =\
209 self.adm_client.update_quota_set(
210 self.demo_tenant_id,
211 security_group_rules=sg_rules_quota)
212
213 self.addCleanup(self.adm_client.update_quota_set,
214 self.demo_tenant_id,
215 security_group_rules=default_sg_rules_quota)
216
217 s_name = rand_name('securitygroup-')
218 s_description = rand_name('description-')
219 resp, securitygroup =\
220 self.sg_client.create_security_group(s_name, s_description)
221 self.addCleanup(self.sg_client.delete_security_group,
222 securitygroup['id'])
223
224 secgroup_id = securitygroup['id']
225 ip_protocol = 'tcp'
226
227 # Check we cannot create SG rule anymore
228 self.assertRaises(exceptions.OverLimit,
229 self.sg_client.create_security_group_rule,
230 secgroup_id, ip_protocol, 1025, 1025)
231
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530232
Attila Fazekas19044d52013-02-16 07:35:06 +0100233class QuotasAdminTestXML(QuotasAdminTestJSON):
234 _interface = 'xml'