blob: b2b515a5587cb0a21b110345ef945debe293e3b1 [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
18from nose.plugins.attrib import attr
19
Rohit Karajgi07599c52012-11-02 05:35:16 -070020from tempest import exceptions
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053021from tempest.services.compute.admin.json \
22 import quotas_client as adm_quotas_json
23from tempest.services.compute.admin.xml import quotas_client as adm_quotas_xml
24from tempest.tests import compute
25from tempest.tests.compute import base
Rohit Karajgi07599c52012-11-02 05:35:16 -070026
27
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053028class QuotasAdminTestBase(object):
Rohit Karajgi07599c52012-11-02 05:35:16 -070029
30 @classmethod
31 def setUpClass(cls):
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053032 cls.c_adm_user = cls.config.compute_admin.username
33 cls.c_adm_pass = cls.config.compute_admin.password
34 cls.c_adm_tenant = cls.config.compute_admin.tenant_name
35 cls.auth_url = cls.config.identity.uri
Rohit Karajgi07599c52012-11-02 05:35:16 -070036 cls.client = cls.os.quotas_client
37 cls.identity_admin_client = cls._get_identity_admin_client()
38 resp, tenants = cls.identity_admin_client.list_tenants()
39
40 if cls.config.compute.allow_tenant_isolation:
41 cls.demo_tenant_id = cls.isolated_creds[0][0]['tenantId']
42 else:
43 cls.demo_tenant_id = [tnt['id'] for tnt in tenants if tnt['name']
Attila Fazekascadcb1f2013-01-21 23:10:53 +010044 == cls.config.identity.tenant_name][0]
Rohit Karajgi07599c52012-11-02 05:35:16 -070045
46 cls.adm_tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
47 cls.config.compute_admin.tenant_name][0]
48
49 cls.default_quota_set = {'injected_file_content_bytes': 10240,
50 'metadata_items': 128, 'injected_files': 5,
51 'ram': 51200, 'floating_ips': 10,
52 'key_pairs': 100,
53 'injected_file_path_bytes': 255,
54 'instances': 10, 'security_group_rules': 20,
55 'cores': 20, 'security_groups': 10}
56
57 @classmethod
ivan-zhu1feeb382013-01-24 10:14:39 +080058 def tearDownClass(cls):
Rohit Karajgi07599c52012-11-02 05:35:16 -070059 for server in cls.servers:
60 try:
61 cls.servers_client.delete_server(server['id'])
62 except exceptions.NotFound:
63 continue
64
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
Rohit Karajgi07599c52012-11-02 05:35:16 -070068 expected_quota_set = self.default_quota_set.copy()
69 expected_quota_set['id'] = self.demo_tenant_id
70 try:
71 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
72 self.assertEqual(200, resp.status)
73 self.assertSequenceEqual(expected_quota_set, quota_set)
Matthew Treinish05d9fb92012-12-07 16:14:05 -050074 except Exception:
Rohit Karajgi07599c52012-11-02 05:35:16 -070075 self.fail("Admin could not get the default quota set for a tenant")
76
77 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
Rohit Karajgi07599c52012-11-02 05:35:16 -070079 new_quota_set = {'injected_file_content_bytes': 20480,
80 'metadata_items': 256, 'injected_files': 10,
81 'ram': 10240, 'floating_ips': 20, 'key_pairs': 200,
82 'injected_file_path_bytes': 512, 'instances': 20,
83 'security_group_rules': 20, 'cores': 2,
84 'security_groups': 20}
85 try:
86 # Update limits for all quota resources
87 resp, quota_set = self.adm_client.update_quota_set(
88 self.demo_tenant_id,
89 **new_quota_set)
90 self.assertEqual(200, resp.status)
91 self.assertSequenceEqual(new_quota_set, quota_set)
Matthew Treinish05d9fb92012-12-07 16:14:05 -050092 except Exception:
Rohit Karajgi07599c52012-11-02 05:35:16 -070093 self.fail("Admin could not update quota set for the tenant")
94 finally:
95 # Reset quota resource limits to default values
96 resp, quota_set = self.adm_client.update_quota_set(
97 self.demo_tenant_id,
98 **self.default_quota_set)
99 self.assertEqual(200, resp.status, "Failed to reset quota "
100 "defaults")
101
102 def test_get_updated_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500103 # Verify that GET shows the updated quota set
Rohit Karajgi07599c52012-11-02 05:35:16 -0700104 self.adm_client.update_quota_set(self.demo_tenant_id,
105 ram='5120')
106 try:
107 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
108 self.assertEqual(200, resp.status)
109 self.assertEqual(quota_set['ram'], 5120)
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500110 except Exception:
Rohit Karajgi07599c52012-11-02 05:35:16 -0700111 self.fail("Could not get the update quota limit for resource")
112 finally:
113 # Reset quota resource limits to default values
114 resp, quota_set = self.adm_client.update_quota_set(
115 self.demo_tenant_id,
116 **self.default_quota_set)
117 self.assertEqual(200, resp.status, "Failed to reset quota "
118 "defaults")
119
120 def test_create_server_when_cpu_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500121 # Disallow server creation when tenant's vcpu quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700122 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
123 default_vcpu_quota = quota_set['cores']
124 vcpu_quota = 0 # Set the quota to zero to conserve resources
125
126 resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
127 cores=vcpu_quota)
128 try:
129 self.create_server()
130 except exceptions.OverLimit:
131 pass
132 else:
133 self.fail("Could create servers over the VCPU quota limit")
134 finally:
135 self.adm_client.update_quota_set(self.demo_tenant_id,
136 cores=default_vcpu_quota)
137
138 def test_create_server_when_memory_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500139 # Disallow server creation when tenant's memory quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700140 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
141 default_mem_quota = quota_set['ram']
142 mem_quota = 0 # Set the quota to zero to conserve resources
143
144 self.adm_client.update_quota_set(self.demo_tenant_id,
145 ram=mem_quota)
146 try:
147 self.create_server()
148 except exceptions.OverLimit:
149 pass
150 else:
151 self.fail("Could create servers over the memory quota limit")
152 finally:
153 self.adm_client.update_quota_set(self.demo_tenant_id,
154 ram=default_mem_quota)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530155
156
157class QuotasAdminTestJSON(QuotasAdminTestBase, base.BaseComputeAdminTestJSON,
158 base.BaseComputeTest):
159
160 @classmethod
161 def setUpClass(cls):
162 base.BaseComputeAdminTestJSON.setUpClass()
163 base.BaseComputeTest.setUpClass()
164 super(QuotasAdminTestJSON, cls).setUpClass()
165
166 cls.adm_client = adm_quotas_json.AdminQuotasClientJSON(
167 cls.config, cls.c_adm_user, cls.c_adm_pass,
168 cls.auth_url, cls.c_adm_tenant)
169
170 @classmethod
171 def tearDownClass(cls):
172 super(QuotasAdminTestJSON, cls).tearDownClass()
173 base.BaseComputeTest.tearDownClass()
174
175
176class QuotasAdminTestXML(QuotasAdminTestBase, base.BaseComputeAdminTestXML,
177 base.BaseComputeTest):
178
179 @classmethod
180 def setUpClass(cls):
181 base.BaseComputeAdminTestXML.setUpClass()
182 base.BaseComputeTest.setUpClass()
183 super(QuotasAdminTestXML, cls).setUpClass()
184
185 cls.adm_client = adm_quotas_xml.AdminQuotasClientXML(cls.config,
186 cls.c_adm_user,
187 cls.c_adm_pass,
188 cls.auth_url,
189 cls.c_adm_tenant)
190
191 @classmethod
192 def tearDownClass(cls):
193 super(QuotasAdminTestXML, cls).tearDownClass()
194 base.BaseComputeTest.tearDownClass()