blob: 348666d8ea6f82c04a461ce13b828fcabaf5faf0 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Rohit Karajgi07599c52012-11-02 05:35:16 -07002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.compute import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090017from tempest.common.utils import data_utils
Haiwei Xuc367d912014-01-14 19:51:10 +090018from tempest import test
Sean Dague86bd8422013-12-20 09:56:44 -050019
Rohit Karajgi07599c52012-11-02 05:35:16 -070020
ivan-zhuf2b00502013-10-18 10:06:52 +080021class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest):
Attila Fazekas430dae32013-10-17 15:19:32 +020022 force_tenant_isolation = True
Rohit Karajgi07599c52012-11-02 05:35:16 -070023
24 @classmethod
25 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010026 super(QuotasAdminTestJSON, cls).setUpClass()
Attila Fazekas4ba36582013-02-12 08:26:17 +010027 cls.adm_client = cls.os_adm.quotas_client
Attila Fazekas4ba36582013-02-12 08:26:17 +010028
Attila Fazekasf7f34f92013-08-01 17:01:44 +020029 # NOTE(afazekas): these test cases should always create and use a new
Attila Fazekas4ba36582013-02-12 08:26:17 +010030 # tenant most of them should be skipped if we can't do that
Andrea Frittoli9612e812014-03-13 10:57:26 +000031 cls.demo_tenant_id = cls.quotas_client.tenant_id
Rohit Karajgi07599c52012-11-02 05:35:16 -070032
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020033 cls.default_quota_set = set(('injected_file_content_bytes',
34 'metadata_items', 'injected_files',
35 'ram', 'floating_ips',
36 'fixed_ips', 'key_pairs',
37 'injected_file_path_bytes',
38 'instances', 'security_group_rules',
39 'cores', 'security_groups'))
Rohit Karajgi07599c52012-11-02 05:35:16 -070040
Haiwei Xuc367d912014-01-14 19:51:10 +090041 @test.attr(type='smoke')
Rohit Karajgi07599c52012-11-02 05:35:16 -070042 def test_get_default_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050043 # Admin can get the default resource quota set for a tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020044 expected_quota_set = self.default_quota_set | set(['id'])
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +080045 resp, quota_set = self.adm_client.get_default_quota_set(
Leo Toyoda87a52b72013-04-09 10:34:40 +090046 self.demo_tenant_id)
47 self.assertEqual(200, resp.status)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020048 self.assertEqual(sorted(expected_quota_set),
49 sorted(quota_set.keys()))
50 self.assertEqual(quota_set['id'], self.demo_tenant_id)
Rohit Karajgi07599c52012-11-02 05:35:16 -070051
Haiwei Xuc367d912014-01-14 19:51:10 +090052 @test.attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -070053 def test_update_all_quota_resources_for_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050054 # Admin can update all the resource quota limits for a tenant
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +080055 resp, default_quota_set = self.adm_client.get_default_quota_set(
gengjh01ba9cc2013-06-15 10:14:48 +080056 self.demo_tenant_id)
57 new_quota_set = {'injected_file_content_bytes': 20480,
Rohit Karajgi07599c52012-11-02 05:35:16 -070058 'metadata_items': 256, 'injected_files': 10,
Michael Still9ac5bd02013-03-15 04:32:46 +110059 'ram': 10240, 'floating_ips': 20, 'fixed_ips': 10,
60 'key_pairs': 200, 'injected_file_path_bytes': 512,
61 'instances': 20, 'security_group_rules': 20,
62 'cores': 2, 'security_groups': 20}
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070063 # Update limits for all quota resources
64 resp, quota_set = self.adm_client.update_quota_set(
65 self.demo_tenant_id,
gengjh01ba9cc2013-06-15 10:14:48 +080066 force=True,
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070067 **new_quota_set)
gengjh01ba9cc2013-06-15 10:14:48 +080068
69 default_quota_set.pop('id')
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070070 self.addCleanup(self.adm_client.update_quota_set,
gengjh01ba9cc2013-06-15 10:14:48 +080071 self.demo_tenant_id, **default_quota_set)
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070072 self.assertEqual(200, resp.status)
73 self.assertEqual(new_quota_set, quota_set)
Rohit Karajgi07599c52012-11-02 05:35:16 -070074
Attila Fazekasf7f34f92013-08-01 17:01:44 +020075 # TODO(afazekas): merge these test cases
Haiwei Xuc367d912014-01-14 19:51:10 +090076 @test.attr(type='gate')
Rohit Karajgi07599c52012-11-02 05:35:16 -070077 def test_get_updated_quotas(self):
Zhi Kun Liu27e154f2014-03-24 03:51:12 -050078 # Verify that GET shows the updated quota set of tenant
Masayuki Igawa259c1132013-10-31 17:48:44 +090079 tenant_name = data_utils.rand_name('cpu_quota_tenant_')
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020080 tenant_desc = tenant_name + '-desc'
81 identity_client = self.os_adm.identity_client
82 _, tenant = identity_client.create_tenant(name=tenant_name,
83 description=tenant_desc)
84 tenant_id = tenant['id']
Zhi Kun Liu27e154f2014-03-24 03:51:12 -050085 self.addCleanup(identity_client.delete_tenant, tenant_id)
Rohit Karajgi07599c52012-11-02 05:35:16 -070086
Zhi Kun Liu27e154f2014-03-24 03:51:12 -050087 self.adm_client.update_quota_set(tenant_id, ram='5120')
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020088 resp, quota_set = self.adm_client.get_quota_set(tenant_id)
89 self.assertEqual(200, resp.status)
Zhi Kun Liu27e154f2014-03-24 03:51:12 -050090 self.assertEqual(5120, quota_set['ram'])
91
92 # Verify that GET shows the updated quota set of user
93 user_name = data_utils.rand_name('cpu_quota_user_')
94 password = data_utils.rand_name('password-')
95 email = user_name + '@testmail.tm'
96 _, user = identity_client.create_user(name=user_name,
97 password=password,
98 tenant_id=tenant_id,
99 email=email)
100 user_id = user['id']
101 self.addCleanup(identity_client.delete_user, user_id)
102
103 self.adm_client.update_quota_set(tenant_id,
104 user_id=user_id,
105 ram='2048')
106 resp, quota_set = self.adm_client.get_quota_set(tenant_id,
107 user_id=user_id)
108 self.assertEqual(200, resp.status)
109 self.assertEqual(2048, quota_set['ram'])
Attila Fazekasd9aef1e2013-07-13 17:33:45 +0200110
Yuiko Takada2209cf52014-02-27 12:03:49 +0000111 @test.attr(type='gate')
112 def test_delete_quota(self):
113 # Admin can delete the resource quota set for a tenant
114 tenant_name = data_utils.rand_name('ram_quota_tenant_')
115 tenant_desc = tenant_name + '-desc'
116 identity_client = self.os_adm.identity_client
117 _, tenant = identity_client.create_tenant(name=tenant_name,
118 description=tenant_desc)
119 tenant_id = tenant['id']
120 self.addCleanup(identity_client.delete_tenant, tenant_id)
121 resp, quota_set_default = self.adm_client.get_quota_set(tenant_id)
122 ram_default = quota_set_default['ram']
123
124 resp, body = self.adm_client.update_quota_set(tenant_id, ram='5120')
125 self.assertEqual(200, resp.status)
126
127 resp, body = self.adm_client.delete_quota_set(tenant_id)
128 self.assertEqual(202, resp.status)
129
130 resp, quota_set_new = self.adm_client.get_quota_set(tenant_id)
131 self.assertEqual(200, resp.status)
132 self.assertEqual(ram_default, quota_set_new['ram'])
133
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530134
Attila Fazekas19044d52013-02-16 07:35:06 +0100135class QuotasAdminTestXML(QuotasAdminTestJSON):
136 _interface = 'xml'