blob: 7ba46bbde87bab23801ae1f2a4bc785fbae1df74 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipesf38eaac2012-06-21 13:37:35 -04002# 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
llg821243b20502014-02-22 10:32:49 +080016from six import moves
17
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.identity import base
huangtianhuab0993eb2013-09-30 18:07:15 +080019from tempest.common.utils import data_utils
Chris Yeoh01cb2792013-02-09 22:25:37 +103020from tempest.test import attr
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070021
22
Matthew Treinishdb2c5972014-01-31 22:18:59 +000023class TenantsTestJSON(base.BaseIdentityV2AdminTest):
Attila Fazekas0d0c6162013-02-24 09:14:23 +010024 _interface = 'json'
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070025
Giampaolo Lauriaea294952013-05-15 08:52:04 -040026 @attr(type='gate')
Attila Fazekas40ec1232013-01-08 11:45:32 +010027 def test_tenant_list_delete(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050028 # Create several tenants and delete them
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070029 tenants = []
llg821243b20502014-02-22 10:32:49 +080030 for _ in moves.xrange(3):
huangtianhuab0993eb2013-09-30 18:07:15 +080031 tenant_name = data_utils.rand_name(name='tenant-new')
32 resp, tenant = self.client.create_tenant(tenant_name)
33 self.assertEqual(200, resp.status)
Attila Fazekas40ec1232013-01-08 11:45:32 +010034 self.data.tenants.append(tenant)
35 tenants.append(tenant)
36 tenant_ids = map(lambda x: x['id'], tenants)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070037 resp, body = self.client.list_tenants()
Ken'ichi Ohmichiaa8974e2014-03-18 17:19:07 +090038 self.assertEqual(200, resp.status)
Attila Fazekas40ec1232013-01-08 11:45:32 +010039 found = [tenant for tenant in body if tenant['id'] in tenant_ids]
40 self.assertEqual(len(found), len(tenants), 'Tenants not created')
41
42 for tenant in tenants:
43 resp, body = self.client.delete_tenant(tenant['id'])
Ken'ichi Ohmichiaa8974e2014-03-18 17:19:07 +090044 self.assertEqual(204, resp.status)
Attila Fazekas40ec1232013-01-08 11:45:32 +010045 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070046
47 resp, body = self.client.list_tenants()
Attila Fazekas40ec1232013-01-08 11:45:32 +010048 found = [tenant for tenant in body if tenant['id'] in tenant_ids]
49 self.assertFalse(any(found), 'Tenants failed to delete')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070050
Giampaolo Lauriaea294952013-05-15 08:52:04 -040051 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070052 def test_tenant_create_with_description(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050053 # Create tenant with a description
huangtianhuab0993eb2013-09-30 18:07:15 +080054 tenant_name = data_utils.rand_name(name='tenant-')
55 tenant_desc = data_utils.rand_name(name='desc-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070056 resp, body = self.client.create_tenant(tenant_name,
57 description=tenant_desc)
Attila Fazekas40ec1232013-01-08 11:45:32 +010058 tenant = body
59 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070060 tenant_id = body['id']
61 desc1 = body['description']
Ken'ichi Ohmichiaa8974e2014-03-18 17:19:07 +090062 self.assertEqual(200, resp.status)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070063 self.assertEqual(desc1, tenant_desc, 'Description should have '
Zhongyue Luo79d8d362012-09-25 13:49:27 +080064 'been sent in response for create')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070065 resp, body = self.client.get_tenant(tenant_id)
66 desc2 = body['description']
67 self.assertEqual(desc2, tenant_desc, 'Description does not appear'
Zhongyue Luo79d8d362012-09-25 13:49:27 +080068 'to be set')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070069 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +010070 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070071
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040072 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070073 def test_tenant_create_enabled(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050074 # Create a tenant that is enabled
huangtianhuab0993eb2013-09-30 18:07:15 +080075 tenant_name = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070076 resp, body = self.client.create_tenant(tenant_name, enabled=True)
Attila Fazekas40ec1232013-01-08 11:45:32 +010077 tenant = body
78 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070079 tenant_id = body['id']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070080 en1 = body['enabled']
Ken'ichi Ohmichiaa8974e2014-03-18 17:19:07 +090081 self.assertEqual(200, resp.status)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070082 self.assertTrue(en1, 'Enable should be True in response')
83 resp, body = self.client.get_tenant(tenant_id)
84 en2 = body['enabled']
85 self.assertTrue(en2, 'Enable should be True in lookup')
86 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +010087 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070088
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040089 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070090 def test_tenant_create_not_enabled(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050091 # Create a tenant that is not enabled
huangtianhuab0993eb2013-09-30 18:07:15 +080092 tenant_name = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070093 resp, body = self.client.create_tenant(tenant_name, enabled=False)
Attila Fazekas40ec1232013-01-08 11:45:32 +010094 tenant = body
95 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070096 tenant_id = body['id']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070097 en1 = body['enabled']
Ken'ichi Ohmichiaa8974e2014-03-18 17:19:07 +090098 self.assertEqual(200, resp.status)
Vincent Hou6b8a7b72012-08-25 01:24:33 +080099 self.assertEqual('false', str(en1).lower(),
100 'Enable should be False in response')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700101 resp, body = self.client.get_tenant(tenant_id)
102 en2 = body['enabled']
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800103 self.assertEqual('false', str(en2).lower(),
104 'Enable should be False in lookup')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700105 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100106 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700107
Giampaolo Lauriaea294952013-05-15 08:52:04 -0400108 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700109 def test_tenant_update_name(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500110 # Update name attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800111 t_name1 = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700112 resp, body = self.client.create_tenant(t_name1)
huangtianhuab0993eb2013-09-30 18:07:15 +0800113 self.assertEqual(200, resp.status)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100114 tenant = body
115 self.data.tenants.append(tenant)
116
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700117 t_id = body['id']
118 resp1_name = body['name']
119
huangtianhuab0993eb2013-09-30 18:07:15 +0800120 t_name2 = data_utils.rand_name(name='tenant2-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700121 resp, body = self.client.update_tenant(t_id, name=t_name2)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700122 resp2_name = body['name']
Ken'ichi Ohmichiaa8974e2014-03-18 17:19:07 +0900123 self.assertEqual(200, resp.status)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700124 self.assertNotEqual(resp1_name, resp2_name)
125
126 resp, body = self.client.get_tenant(t_id)
127 resp3_name = body['name']
128
129 self.assertNotEqual(resp1_name, resp3_name)
130 self.assertEqual(t_name1, resp1_name)
131 self.assertEqual(resp2_name, resp3_name)
132
133 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100134 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700135
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400136 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700137 def test_tenant_update_desc(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500138 # Update description attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800139 t_name = data_utils.rand_name(name='tenant-')
140 t_desc = data_utils.rand_name(name='desc-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700141 resp, body = self.client.create_tenant(t_name, description=t_desc)
huangtianhuab0993eb2013-09-30 18:07:15 +0800142 self.assertEqual(200, resp.status)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100143 tenant = body
144 self.data.tenants.append(tenant)
145
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700146 t_id = body['id']
147 resp1_desc = body['description']
148
huangtianhuab0993eb2013-09-30 18:07:15 +0800149 t_desc2 = data_utils.rand_name(name='desc2-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700150 resp, body = self.client.update_tenant(t_id, description=t_desc2)
Gordon Chungad873602013-02-18 19:26:27 -0500151 resp2_desc = body['description']
Ken'ichi Ohmichiaa8974e2014-03-18 17:19:07 +0900152 self.assertEqual(200, resp.status)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700153 self.assertNotEqual(resp1_desc, resp2_desc)
154
155 resp, body = self.client.get_tenant(t_id)
156 resp3_desc = body['description']
157
158 self.assertNotEqual(resp1_desc, resp3_desc)
159 self.assertEqual(t_desc, resp1_desc)
160 self.assertEqual(resp2_desc, resp3_desc)
161
162 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100163 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700164
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400165 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700166 def test_tenant_update_enable(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500167 # Update the enabled attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800168 t_name = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700169 t_en = False
170 resp, body = self.client.create_tenant(t_name, enabled=t_en)
huangtianhuab0993eb2013-09-30 18:07:15 +0800171 self.assertEqual(200, resp.status)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100172 tenant = body
173 self.data.tenants.append(tenant)
174
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700175 t_id = body['id']
176 resp1_en = body['enabled']
177
178 t_en2 = True
179 resp, body = self.client.update_tenant(t_id, enabled=t_en2)
Gordon Chungad873602013-02-18 19:26:27 -0500180 resp2_en = body['enabled']
Ken'ichi Ohmichiaa8974e2014-03-18 17:19:07 +0900181 self.assertEqual(200, resp.status)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700182 self.assertNotEqual(resp1_en, resp2_en)
183
184 resp, body = self.client.get_tenant(t_id)
185 resp3_en = body['enabled']
186
187 self.assertNotEqual(resp1_en, resp3_en)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800188 self.assertEqual('false', str(resp1_en).lower())
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700189 self.assertEqual(resp2_en, resp3_en)
190
191 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100192 self.data.tenants.remove(tenant)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800193
194
Attila Fazekas0d0c6162013-02-24 09:14:23 +0100195class TenantsTestXML(TenantsTestJSON):
196 _interface = 'xml'