blob: 6a7a5eab9e547c1fef1852f7beced122c0eaeaa4 [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
Matthew Treinisha83a16e2012-12-07 13:44:02 -050021from tempest.services.compute.admin.json import quotas_client as adm_quotas
James E. Blaire6d8ee12013-01-18 21:33:45 +000022from tempest.tests.compute.base import BaseComputeTest
Rohit Karajgi07599c52012-11-02 05:35:16 -070023
24
James E. Blaire6d8ee12013-01-18 21:33:45 +000025class QuotasTest(BaseComputeTest):
Rohit Karajgi07599c52012-11-02 05:35:16 -070026
27 @classmethod
28 def setUpClass(cls):
29 super(QuotasTest, cls).setUpClass()
Attila Fazekascadcb1f2013-01-21 23:10:53 +010030 c_adm_user = cls.config.compute_admin.username
31 c_adm_pass = cls.config.compute_admin.password
32 c_adm_tenant = cls.config.compute_admin.tenant_name
Jay Pipes7c88eb22013-01-16 21:32:43 -050033 auth_url = cls.config.identity.uri
Rohit Karajgi07599c52012-11-02 05:35:16 -070034
Attila Fazekascadcb1f2013-01-21 23:10:53 +010035 cls.adm_client = adm_quotas.AdminQuotasClient(cls.config, c_adm_user,
36 c_adm_pass, auth_url,
37 c_adm_tenant)
Rohit Karajgi07599c52012-11-02 05:35:16 -070038 cls.client = cls.os.quotas_client
39 cls.identity_admin_client = cls._get_identity_admin_client()
40 resp, tenants = cls.identity_admin_client.list_tenants()
41
42 if cls.config.compute.allow_tenant_isolation:
43 cls.demo_tenant_id = cls.isolated_creds[0][0]['tenantId']
44 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
48 cls.adm_tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
49 cls.config.compute_admin.tenant_name][0]
50
51 cls.default_quota_set = {'injected_file_content_bytes': 10240,
52 'metadata_items': 128, 'injected_files': 5,
53 'ram': 51200, 'floating_ips': 10,
54 'key_pairs': 100,
55 'injected_file_path_bytes': 255,
56 'instances': 10, 'security_group_rules': 20,
57 'cores': 20, 'security_groups': 10}
58
59 @classmethod
ivan-zhu1feeb382013-01-24 10:14:39 +080060 def tearDownClass(cls):
Rohit Karajgi07599c52012-11-02 05:35:16 -070061 for server in cls.servers:
62 try:
63 cls.servers_client.delete_server(server['id'])
64 except exceptions.NotFound:
65 continue
ivan-zhu1feeb382013-01-24 10:14:39 +080066 super(QuotasTest, cls).tearDownClass()
Rohit Karajgi07599c52012-11-02 05:35:16 -070067
68 @attr(type='smoke')
69 def test_get_default_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050070 # Admin can get the default resource quota set for a tenant
Rohit Karajgi07599c52012-11-02 05:35:16 -070071 expected_quota_set = self.default_quota_set.copy()
72 expected_quota_set['id'] = self.demo_tenant_id
73 try:
74 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
75 self.assertEqual(200, resp.status)
76 self.assertSequenceEqual(expected_quota_set, quota_set)
Matthew Treinish05d9fb92012-12-07 16:14:05 -050077 except Exception:
Rohit Karajgi07599c52012-11-02 05:35:16 -070078 self.fail("Admin could not get the default quota set for a tenant")
79
80 def test_update_all_quota_resources_for_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050081 # Admin can update all the resource quota limits for a tenant
Rohit Karajgi07599c52012-11-02 05:35:16 -070082 new_quota_set = {'injected_file_content_bytes': 20480,
83 'metadata_items': 256, 'injected_files': 10,
84 'ram': 10240, 'floating_ips': 20, 'key_pairs': 200,
85 'injected_file_path_bytes': 512, 'instances': 20,
86 'security_group_rules': 20, 'cores': 2,
87 'security_groups': 20}
88 try:
89 # Update limits for all quota resources
90 resp, quota_set = self.adm_client.update_quota_set(
91 self.demo_tenant_id,
92 **new_quota_set)
93 self.assertEqual(200, resp.status)
94 self.assertSequenceEqual(new_quota_set, quota_set)
Matthew Treinish05d9fb92012-12-07 16:14:05 -050095 except Exception:
Rohit Karajgi07599c52012-11-02 05:35:16 -070096 self.fail("Admin could not update quota set for the tenant")
97 finally:
98 # Reset quota resource limits to default values
99 resp, quota_set = self.adm_client.update_quota_set(
100 self.demo_tenant_id,
101 **self.default_quota_set)
102 self.assertEqual(200, resp.status, "Failed to reset quota "
103 "defaults")
104
105 def test_get_updated_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500106 # Verify that GET shows the updated quota set
Rohit Karajgi07599c52012-11-02 05:35:16 -0700107 self.adm_client.update_quota_set(self.demo_tenant_id,
108 ram='5120')
109 try:
110 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
111 self.assertEqual(200, resp.status)
112 self.assertEqual(quota_set['ram'], 5120)
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500113 except Exception:
Rohit Karajgi07599c52012-11-02 05:35:16 -0700114 self.fail("Could not get the update quota limit for resource")
115 finally:
116 # Reset quota resource limits to default values
117 resp, quota_set = self.adm_client.update_quota_set(
118 self.demo_tenant_id,
119 **self.default_quota_set)
120 self.assertEqual(200, resp.status, "Failed to reset quota "
121 "defaults")
122
123 def test_create_server_when_cpu_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500124 # Disallow server creation when tenant's vcpu 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_vcpu_quota = quota_set['cores']
127 vcpu_quota = 0 # Set the quota to zero to conserve resources
128
129 resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
130 cores=vcpu_quota)
131 try:
132 self.create_server()
133 except exceptions.OverLimit:
134 pass
135 else:
136 self.fail("Could create servers over the VCPU quota limit")
137 finally:
138 self.adm_client.update_quota_set(self.demo_tenant_id,
139 cores=default_vcpu_quota)
140
141 def test_create_server_when_memory_quota_is_full(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500142 # Disallow server creation when tenant's memory quota is full
Rohit Karajgi07599c52012-11-02 05:35:16 -0700143 resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
144 default_mem_quota = quota_set['ram']
145 mem_quota = 0 # Set the quota to zero to conserve resources
146
147 self.adm_client.update_quota_set(self.demo_tenant_id,
148 ram=mem_quota)
149 try:
150 self.create_server()
151 except exceptions.OverLimit:
152 pass
153 else:
154 self.fail("Could create servers over the memory quota limit")
155 finally:
156 self.adm_client.update_quota_set(self.demo_tenant_id,
157 ram=default_mem_quota)