blob: ea4daaa43aeca98fb2eb37d599373c97b2eaa371 [file] [log] [blame]
Rohit Karajgi07599c52012-11-02 05:35:16 -07001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Rohit Karajgi07599c52012-11-02 05:35:16 -07004# 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
Matt Riedemann6ac8a102013-10-16 13:39:07 -070020from tempest import config
Rohit Karajgi07599c52012-11-02 05:35:16 -070021from tempest import exceptions
Chris Yeoh9465b0b2013-02-09 22:19:15 +103022from tempest.test import attr
Matt Riedemann6ac8a102013-10-16 13:39:07 -070023from tempest.test import skip_because
Rohit Karajgi07599c52012-11-02 05:35:16 -070024
25
Attila Fazekas19044d52013-02-16 07:35:06 +010026class QuotasAdminTestJSON(base.BaseComputeAdminTest):
27 _interface = 'json'
Attila Fazekas430dae32013-10-17 15:19:32 +020028 force_tenant_isolation = True
Rohit Karajgi07599c52012-11-02 05:35:16 -070029
30 @classmethod
31 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010032 super(QuotasAdminTestJSON, cls).setUpClass()
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053033 cls.auth_url = cls.config.identity.uri
Rohit Karajgi07599c52012-11-02 05:35:16 -070034 cls.client = cls.os.quotas_client
Attila Fazekas4ba36582013-02-12 08:26:17 +010035 cls.adm_client = cls.os_adm.quotas_client
Rohit Karajgi07599c52012-11-02 05:35:16 -070036 cls.identity_admin_client = cls._get_identity_admin_client()
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -070037 cls.sg_client = cls.security_groups_client
Attila Fazekas4ba36582013-02-12 08:26:17 +010038
Rohit Karajgi07599c52012-11-02 05:35:16 -070039 resp, tenants = cls.identity_admin_client.list_tenants()
40
Attila Fazekasf7f34f92013-08-01 17:01:44 +020041 # NOTE(afazekas): these test cases should always create and use a new
Attila Fazekas4ba36582013-02-12 08:26:17 +010042 # tenant most of them should be skipped if we can't do that
Attila Fazekas430dae32013-10-17 15:19:32 +020043 cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get(
44 'tenantId')
Rohit Karajgi07599c52012-11-02 05:35:16 -070045
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020046 cls.default_quota_set = set(('injected_file_content_bytes',
47 'metadata_items', 'injected_files',
48 'ram', 'floating_ips',
49 'fixed_ips', 'key_pairs',
50 'injected_file_path_bytes',
51 'instances', 'security_group_rules',
52 'cores', 'security_groups'))
Rohit Karajgi07599c52012-11-02 05:35:16 -070053
Rohit Karajgi07599c52012-11-02 05:35:16 -070054 @attr(type='smoke')
55 def test_get_default_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050056 # Admin can get the default resource quota set for a tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020057 expected_quota_set = self.default_quota_set | set(['id'])
Leo Toyoda87a52b72013-04-09 10:34:40 +090058 resp, quota_set = self.client.get_default_quota_set(
59 self.demo_tenant_id)
60 self.assertEqual(200, resp.status)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020061 self.assertEqual(sorted(expected_quota_set),
62 sorted(quota_set.keys()))
63 self.assertEqual(quota_set['id'], self.demo_tenant_id)
Rohit Karajgi07599c52012-11-02 05:35:16 -070064
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040065 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -070066 def test_update_all_quota_resources_for_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050067 # Admin can update all the resource quota limits for a tenant
gengjh01ba9cc2013-06-15 10:14:48 +080068 resp, default_quota_set = self.client.get_default_quota_set(
69 self.demo_tenant_id)
70 new_quota_set = {'injected_file_content_bytes': 20480,
Rohit Karajgi07599c52012-11-02 05:35:16 -070071 'metadata_items': 256, 'injected_files': 10,
Michael Still9ac5bd02013-03-15 04:32:46 +110072 'ram': 10240, 'floating_ips': 20, 'fixed_ips': 10,
73 'key_pairs': 200, 'injected_file_path_bytes': 512,
74 'instances': 20, 'security_group_rules': 20,
75 'cores': 2, 'security_groups': 20}
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070076 # Update limits for all quota resources
77 resp, quota_set = self.adm_client.update_quota_set(
78 self.demo_tenant_id,
gengjh01ba9cc2013-06-15 10:14:48 +080079 force=True,
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070080 **new_quota_set)
gengjh01ba9cc2013-06-15 10:14:48 +080081
82 default_quota_set.pop('id')
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070083 self.addCleanup(self.adm_client.update_quota_set,
gengjh01ba9cc2013-06-15 10:14:48 +080084 self.demo_tenant_id, **default_quota_set)
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070085 self.assertEqual(200, resp.status)
86 self.assertEqual(new_quota_set, quota_set)
Rohit Karajgi07599c52012-11-02 05:35:16 -070087
Attila Fazekasf7f34f92013-08-01 17:01:44 +020088 # TODO(afazekas): merge these test cases
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040089 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -070090 def test_get_updated_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050091 # Verify that GET shows the updated quota set
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020092 tenant_name = rand_name('cpu_quota_tenant_')
93 tenant_desc = tenant_name + '-desc'
94 identity_client = self.os_adm.identity_client
95 _, tenant = identity_client.create_tenant(name=tenant_name,
96 description=tenant_desc)
97 tenant_id = tenant['id']
98 self.addCleanup(identity_client.delete_tenant,
99 tenant_id)
Rohit Karajgi07599c52012-11-02 05:35:16 -0700100
Attila Fazekasd9aef1e2013-07-13 17:33:45 +0200101 self.adm_client.update_quota_set(tenant_id,
102 ram='5120')
103 resp, quota_set = self.adm_client.get_quota_set(tenant_id)
104 self.assertEqual(200, resp.status)
105 self.assertEqual(quota_set['ram'], 5120)
106
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200107 # TODO(afazekas): Add dedicated tenant to the skiped quota tests
Attila Fazekasd9aef1e2013-07-13 17:33:45 +0200108 # it can be moved into the setUpClass as well
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400109 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700110 def test_create_server_when_cpu_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500111 # Disallow server creation when tenant's vcpu quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700112 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
113 default_vcpu_quota = quota_set['cores']
114 vcpu_quota = 0 # Set the quota to zero to conserve resources
115
116 resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
gengjh07fe8302013-04-17 16:15:22 +0800117 force=True,
Rohit Karajgi07599c52012-11-02 05:35:16 -0700118 cores=vcpu_quota)
hi2sureshaab7b482013-03-12 04:41:38 +0000119
120 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
121 cores=default_vcpu_quota)
122 self.assertRaises(exceptions.OverLimit, self.create_server)
Rohit Karajgi07599c52012-11-02 05:35:16 -0700123
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400124 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700125 def test_create_server_when_memory_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500126 # Disallow server creation when tenant's memory quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700127 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
128 default_mem_quota = quota_set['ram']
129 mem_quota = 0 # Set the quota to zero to conserve resources
130
131 self.adm_client.update_quota_set(self.demo_tenant_id,
gengjh07fe8302013-04-17 16:15:22 +0800132 force=True,
Rohit Karajgi07599c52012-11-02 05:35:16 -0700133 ram=mem_quota)
hi2sureshda748f12013-03-13 03:31:14 +0000134
135 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
136 ram=default_mem_quota)
137 self.assertRaises(exceptions.OverLimit, self.create_server)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530138
gengjh01ba9cc2013-06-15 10:14:48 +0800139 @attr(type='gate')
140 def test_update_quota_normal_user(self):
141 self.assertRaises(exceptions.Unauthorized,
142 self.client.update_quota_set,
143 self.demo_tenant_id,
144 ram=0)
Attila Fazekas4ba36582013-02-12 08:26:17 +0100145
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400146 @attr(type=['negative', 'gate'])
hi2sureshb546db02013-02-21 10:21:32 +0000147 def test_create_server_when_instances_quota_is_full(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200148 # Once instances quota limit is reached, disallow server creation
hi2sureshb546db02013-02-21 10:21:32 +0000149 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
150 default_instances_quota = quota_set['instances']
151 instances_quota = 0 # Set quota to zero to disallow server creation
152
153 self.adm_client.update_quota_set(self.demo_tenant_id,
gengjh07fe8302013-04-17 16:15:22 +0800154 force=True,
hi2sureshb546db02013-02-21 10:21:32 +0000155 instances=instances_quota)
156 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
157 instances=default_instances_quota)
158 self.assertRaises(exceptions.OverLimit, self.create_server)
159
Matt Riedemann6ac8a102013-10-16 13:39:07 -0700160 @skip_because(bug="1186354",
161 condition=config.TempestConfig().service_available.neutron)
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400162 @attr(type=['negative', 'gate'])
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700163 def test_security_groups_exceed_limit(self):
164 # Negative test: Creation Security Groups over limit should FAIL
165
166 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
167 default_sg_quota = quota_set['security_groups']
168 sg_quota = 0 # Set the quota to zero to conserve resources
169
170 resp, quota_set =\
171 self.adm_client.update_quota_set(self.demo_tenant_id,
gengjh01ba9cc2013-06-15 10:14:48 +0800172 force=True,
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700173 security_groups=sg_quota)
174
175 self.addCleanup(self.adm_client.update_quota_set,
176 self.demo_tenant_id,
177 security_groups=default_sg_quota)
178
179 # Check we cannot create anymore
180 self.assertRaises(exceptions.OverLimit,
181 self.sg_client.create_security_group,
182 "sg-overlimit", "sg-desc")
183
Matt Riedemann6ac8a102013-10-16 13:39:07 -0700184 @skip_because(bug="1186354",
185 condition=config.TempestConfig().service_available.neutron)
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400186 @attr(type=['negative', 'gate'])
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700187 def test_security_groups_rules_exceed_limit(self):
188 # Negative test: Creation of Security Group Rules should FAIL
189 # when we reach limit maxSecurityGroupRules
190
191 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
192 default_sg_rules_quota = quota_set['security_group_rules']
193 sg_rules_quota = 0 # Set the quota to zero to conserve resources
194
195 resp, quota_set =\
196 self.adm_client.update_quota_set(
197 self.demo_tenant_id,
gengjh01ba9cc2013-06-15 10:14:48 +0800198 force=True,
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700199 security_group_rules=sg_rules_quota)
200
201 self.addCleanup(self.adm_client.update_quota_set,
202 self.demo_tenant_id,
203 security_group_rules=default_sg_rules_quota)
204
205 s_name = rand_name('securitygroup-')
206 s_description = rand_name('description-')
207 resp, securitygroup =\
208 self.sg_client.create_security_group(s_name, s_description)
209 self.addCleanup(self.sg_client.delete_security_group,
210 securitygroup['id'])
211
212 secgroup_id = securitygroup['id']
213 ip_protocol = 'tcp'
214
215 # Check we cannot create SG rule anymore
216 self.assertRaises(exceptions.OverLimit,
217 self.sg_client.create_security_group_rule,
218 secgroup_id, ip_protocol, 1025, 1025)
219
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530220
Attila Fazekas19044d52013-02-16 07:35:06 +0100221class QuotasAdminTestXML(QuotasAdminTestJSON):
222 _interface = 'xml'