blob: 7430a7cde0322b4ffe2cf99befeb21691ddabc4b [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
Rohit Karajgi07599c52012-11-02 05:35:16 -070018from tempest import exceptions
Chris Yeoh9465b0b2013-02-09 22:19:15 +103019from tempest.test import attr
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053020from tempest.tests.compute import base
Rohit Karajgi07599c52012-11-02 05:35:16 -070021
22
Attila Fazekas19044d52013-02-16 07:35:06 +010023class QuotasAdminTestJSON(base.BaseComputeAdminTest):
24 _interface = 'json'
Rohit Karajgi07599c52012-11-02 05:35:16 -070025
26 @classmethod
27 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010028 super(QuotasAdminTestJSON, cls).setUpClass()
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053029 cls.auth_url = cls.config.identity.uri
Rohit Karajgi07599c52012-11-02 05:35:16 -070030 cls.client = cls.os.quotas_client
Attila Fazekas4ba36582013-02-12 08:26:17 +010031 cls.adm_client = cls.os_adm.quotas_client
Rohit Karajgi07599c52012-11-02 05:35:16 -070032 cls.identity_admin_client = cls._get_identity_admin_client()
Attila Fazekas4ba36582013-02-12 08:26:17 +010033
Rohit Karajgi07599c52012-11-02 05:35:16 -070034 resp, tenants = cls.identity_admin_client.list_tenants()
35
Attila Fazekas4ba36582013-02-12 08:26:17 +010036 #NOTE(afazekas): these test cases should always create and use a new
37 # tenant most of them should be skipped if we can't do that
Rohit Karajgi07599c52012-11-02 05:35:16 -070038 if cls.config.compute.allow_tenant_isolation:
39 cls.demo_tenant_id = cls.isolated_creds[0][0]['tenantId']
40 else:
41 cls.demo_tenant_id = [tnt['id'] for tnt in tenants if tnt['name']
Attila Fazekascadcb1f2013-01-21 23:10:53 +010042 == cls.config.identity.tenant_name][0]
Rohit Karajgi07599c52012-11-02 05:35:16 -070043
Rohit Karajgi07599c52012-11-02 05:35:16 -070044 cls.default_quota_set = {'injected_file_content_bytes': 10240,
45 'metadata_items': 128, 'injected_files': 5,
46 'ram': 51200, 'floating_ips': 10,
47 'key_pairs': 100,
48 'injected_file_path_bytes': 255,
49 'instances': 10, 'security_group_rules': 20,
50 'cores': 20, 'security_groups': 10}
51
52 @classmethod
ivan-zhu1feeb382013-01-24 10:14:39 +080053 def tearDownClass(cls):
Rohit Karajgi07599c52012-11-02 05:35:16 -070054 for server in cls.servers:
55 try:
56 cls.servers_client.delete_server(server['id'])
57 except exceptions.NotFound:
58 continue
Attila Fazekas19044d52013-02-16 07:35:06 +010059 super(QuotasAdminTestJSON, cls).tearDownClass()
Rohit Karajgi07599c52012-11-02 05:35:16 -070060
61 @attr(type='smoke')
62 def test_get_default_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050063 # Admin can get the default resource quota set for a tenant
Rohit Karajgi07599c52012-11-02 05:35:16 -070064 expected_quota_set = self.default_quota_set.copy()
65 expected_quota_set['id'] = self.demo_tenant_id
66 try:
67 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
68 self.assertEqual(200, resp.status)
Michael J Fork7a313652013-02-11 23:23:02 +000069 self.assertEqual(expected_quota_set, quota_set)
Matthew Treinish05d9fb92012-12-07 16:14:05 -050070 except Exception:
Rohit Karajgi07599c52012-11-02 05:35:16 -070071 self.fail("Admin could not get the default quota set for a tenant")
72
73 def test_update_all_quota_resources_for_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050074 # Admin can update all the resource quota limits for a tenant
Rohit Karajgi07599c52012-11-02 05:35:16 -070075 new_quota_set = {'injected_file_content_bytes': 20480,
76 'metadata_items': 256, 'injected_files': 10,
77 'ram': 10240, 'floating_ips': 20, 'key_pairs': 200,
78 'injected_file_path_bytes': 512, 'instances': 20,
79 'security_group_rules': 20, 'cores': 2,
80 'security_groups': 20}
81 try:
82 # Update limits for all quota resources
83 resp, quota_set = self.adm_client.update_quota_set(
84 self.demo_tenant_id,
85 **new_quota_set)
86 self.assertEqual(200, resp.status)
Michael J Fork7a313652013-02-11 23:23:02 +000087 self.assertEqual(new_quota_set, quota_set)
Matthew Treinish05d9fb92012-12-07 16:14:05 -050088 except Exception:
Rohit Karajgi07599c52012-11-02 05:35:16 -070089 self.fail("Admin could not update quota set for the tenant")
90 finally:
91 # Reset quota resource limits to default values
92 resp, quota_set = self.adm_client.update_quota_set(
93 self.demo_tenant_id,
94 **self.default_quota_set)
95 self.assertEqual(200, resp.status, "Failed to reset quota "
96 "defaults")
97
Attila Fazekas4ba36582013-02-12 08:26:17 +010098 #TODO(afazekas): merge these test cases
Rohit Karajgi07599c52012-11-02 05:35:16 -070099 def test_get_updated_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500100 # Verify that GET shows the updated quota set
Rohit Karajgi07599c52012-11-02 05:35:16 -0700101 self.adm_client.update_quota_set(self.demo_tenant_id,
102 ram='5120')
103 try:
104 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
105 self.assertEqual(200, resp.status)
106 self.assertEqual(quota_set['ram'], 5120)
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500107 except Exception:
Rohit Karajgi07599c52012-11-02 05:35:16 -0700108 self.fail("Could not get the update quota limit for resource")
109 finally:
110 # Reset quota resource limits to default values
111 resp, quota_set = self.adm_client.update_quota_set(
112 self.demo_tenant_id,
113 **self.default_quota_set)
114 self.assertEqual(200, resp.status, "Failed to reset quota "
115 "defaults")
116
117 def test_create_server_when_cpu_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500118 # Disallow server creation when tenant's vcpu quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700119 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
120 default_vcpu_quota = quota_set['cores']
121 vcpu_quota = 0 # Set the quota to zero to conserve resources
122
123 resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
124 cores=vcpu_quota)
125 try:
126 self.create_server()
127 except exceptions.OverLimit:
128 pass
129 else:
130 self.fail("Could create servers over the VCPU quota limit")
131 finally:
132 self.adm_client.update_quota_set(self.demo_tenant_id,
133 cores=default_vcpu_quota)
134
135 def test_create_server_when_memory_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500136 # Disallow server creation when tenant's memory quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700137 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
138 default_mem_quota = quota_set['ram']
139 mem_quota = 0 # Set the quota to zero to conserve resources
140
141 self.adm_client.update_quota_set(self.demo_tenant_id,
142 ram=mem_quota)
143 try:
144 self.create_server()
145 except exceptions.OverLimit:
146 pass
147 else:
148 self.fail("Could create servers over the memory quota limit")
149 finally:
150 self.adm_client.update_quota_set(self.demo_tenant_id,
151 ram=default_mem_quota)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530152
Attila Fazekas4ba36582013-02-12 08:26:17 +0100153#TODO(afazekas): Add test that tried to update the quota_set as a regular user
154
hi2sureshb546db02013-02-21 10:21:32 +0000155 @attr(type='negative')
156 def test_create_server_when_instances_quota_is_full(self):
157 #Once instances quota limit is reached, disallow server creation
158 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
159 default_instances_quota = quota_set['instances']
160 instances_quota = 0 # Set quota to zero to disallow server creation
161
162 self.adm_client.update_quota_set(self.demo_tenant_id,
163 instances=instances_quota)
164 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
165 instances=default_instances_quota)
166 self.assertRaises(exceptions.OverLimit, self.create_server)
167
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530168
Attila Fazekas19044d52013-02-16 07:35:06 +0100169class QuotasAdminTestXML(QuotasAdminTestJSON):
170 _interface = 'xml'