blob: f49aae4c46bc3a64567a302694a1a1e3a6e13e92 [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
Masayuki Igawa259c1132013-10-31 17:48:44 +090019from tempest.common.utils import data_utils
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
ivan-zhuf2b00502013-10-18 10:06:52 +080026class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010027 _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
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
Attila Fazekas430dae32013-10-17 15:19:32 +020041 cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get(
42 'tenantId')
Rohit Karajgi07599c52012-11-02 05:35:16 -070043
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020044 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'))
Rohit Karajgi07599c52012-11-02 05:35:16 -070051
Rohit Karajgi07599c52012-11-02 05:35:16 -070052 @attr(type='smoke')
53 def test_get_default_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050054 # Admin can get the default resource quota set for a tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020055 expected_quota_set = self.default_quota_set | set(['id'])
Leo Toyoda87a52b72013-04-09 10:34:40 +090056 resp, quota_set = self.client.get_default_quota_set(
57 self.demo_tenant_id)
58 self.assertEqual(200, resp.status)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020059 self.assertEqual(sorted(expected_quota_set),
60 sorted(quota_set.keys()))
61 self.assertEqual(quota_set['id'], self.demo_tenant_id)
Rohit Karajgi07599c52012-11-02 05:35:16 -070062
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040063 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -070064 def test_update_all_quota_resources_for_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050065 # Admin can update all the resource quota limits for a tenant
gengjh01ba9cc2013-06-15 10:14:48 +080066 resp, default_quota_set = self.client.get_default_quota_set(
67 self.demo_tenant_id)
68 new_quota_set = {'injected_file_content_bytes': 20480,
Rohit Karajgi07599c52012-11-02 05:35:16 -070069 'metadata_items': 256, 'injected_files': 10,
Michael Still9ac5bd02013-03-15 04:32:46 +110070 '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}
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070074 # Update limits for all quota resources
75 resp, quota_set = self.adm_client.update_quota_set(
76 self.demo_tenant_id,
gengjh01ba9cc2013-06-15 10:14:48 +080077 force=True,
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070078 **new_quota_set)
gengjh01ba9cc2013-06-15 10:14:48 +080079
80 default_quota_set.pop('id')
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070081 self.addCleanup(self.adm_client.update_quota_set,
gengjh01ba9cc2013-06-15 10:14:48 +080082 self.demo_tenant_id, **default_quota_set)
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070083 self.assertEqual(200, resp.status)
84 self.assertEqual(new_quota_set, quota_set)
Rohit Karajgi07599c52012-11-02 05:35:16 -070085
Attila Fazekasf7f34f92013-08-01 17:01:44 +020086 # TODO(afazekas): merge these test cases
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040087 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -070088 def test_get_updated_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050089 # Verify that GET shows the updated quota set
Masayuki Igawa259c1132013-10-31 17:48:44 +090090 tenant_name = data_utils.rand_name('cpu_quota_tenant_')
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020091 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)
Rohit Karajgi07599c52012-11-02 05:35:16 -070098
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020099 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
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200105 # TODO(afazekas): Add dedicated tenant to the skiped quota tests
Attila Fazekasd9aef1e2013-07-13 17:33:45 +0200106 # it can be moved into the setUpClass as well
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400107 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700108 def test_create_server_when_cpu_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500109 # Disallow server creation when tenant's vcpu quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700110 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,
gengjh07fe8302013-04-17 16:15:22 +0800115 force=True,
Rohit Karajgi07599c52012-11-02 05:35:16 -0700116 cores=vcpu_quota)
hi2sureshaab7b482013-03-12 04:41:38 +0000117
118 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
119 cores=default_vcpu_quota)
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +0900120 self.assertRaises(exceptions.OverLimit, self.create_test_server)
Rohit Karajgi07599c52012-11-02 05:35:16 -0700121
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400122 @attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -0700123 def test_create_server_when_memory_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500124 # Disallow server creation when tenant's memory quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700125 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,
gengjh07fe8302013-04-17 16:15:22 +0800130 force=True,
Rohit Karajgi07599c52012-11-02 05:35:16 -0700131 ram=mem_quota)
hi2sureshda748f12013-03-13 03:31:14 +0000132
133 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
134 ram=default_mem_quota)
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +0900135 self.assertRaises(exceptions.OverLimit, self.create_test_server)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530136
gengjh01ba9cc2013-06-15 10:14:48 +0800137 @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)
Attila Fazekas4ba36582013-02-12 08:26:17 +0100143
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400144 @attr(type=['negative', 'gate'])
hi2sureshb546db02013-02-21 10:21:32 +0000145 def test_create_server_when_instances_quota_is_full(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200146 # Once instances quota limit is reached, disallow server creation
hi2sureshb546db02013-02-21 10:21:32 +0000147 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,
gengjh07fe8302013-04-17 16:15:22 +0800152 force=True,
hi2sureshb546db02013-02-21 10:21:32 +0000153 instances=instances_quota)
154 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
155 instances=default_instances_quota)
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +0900156 self.assertRaises(exceptions.OverLimit, self.create_test_server)
hi2sureshb546db02013-02-21 10:21:32 +0000157
Matt Riedemann6ac8a102013-10-16 13:39:07 -0700158 @skip_because(bug="1186354",
159 condition=config.TempestConfig().service_available.neutron)
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400160 @attr(type=['negative', 'gate'])
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700161 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,
gengjh01ba9cc2013-06-15 10:14:48 +0800170 force=True,
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700171 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
Matt Riedemann6ac8a102013-10-16 13:39:07 -0700182 @skip_because(bug="1186354",
183 condition=config.TempestConfig().service_available.neutron)
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400184 @attr(type=['negative', 'gate'])
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700185 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,
gengjh01ba9cc2013-06-15 10:14:48 +0800196 force=True,
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700197 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
Masayuki Igawa259c1132013-10-31 17:48:44 +0900203 s_name = data_utils.rand_name('securitygroup-')
204 s_description = data_utils.rand_name('description-')
Vasyl Khomenko96d8ca32013-04-17 09:54:07 -0700205 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
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530218
Attila Fazekas19044d52013-02-16 07:35:06 +0100219class QuotasAdminTestXML(QuotasAdminTestJSON):
220 _interface = 'xml'