blob: 8d3b402c59e498024d65adb73b24a999c1093a6a [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
Matthew Treinish5c660ab2014-05-18 21:14:36 -040020from tempest import test
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
Matthew Treinish5c660ab2014-05-18 21:14:36 -040026 @test.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')
David Kranze9d2f422014-07-02 13:57:41 -040032 _, tenant = self.client.create_tenant(tenant_name)
Attila Fazekas40ec1232013-01-08 11:45:32 +010033 self.data.tenants.append(tenant)
34 tenants.append(tenant)
35 tenant_ids = map(lambda x: x['id'], tenants)
David Kranze9d2f422014-07-02 13:57:41 -040036 _, body = self.client.list_tenants()
Matthew Treinishc795b9e2014-06-09 17:01:10 -040037 found = [t for t in body if t['id'] in tenant_ids]
Attila Fazekas40ec1232013-01-08 11:45:32 +010038 self.assertEqual(len(found), len(tenants), 'Tenants not created')
39
40 for tenant in tenants:
David Kranze9d2f422014-07-02 13:57:41 -040041 self.client.delete_tenant(tenant['id'])
Attila Fazekas40ec1232013-01-08 11:45:32 +010042 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070043
David Kranze9d2f422014-07-02 13:57:41 -040044 _, body = self.client.list_tenants()
Attila Fazekas40ec1232013-01-08 11:45:32 +010045 found = [tenant for tenant in body if tenant['id'] in tenant_ids]
46 self.assertFalse(any(found), 'Tenants failed to delete')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070047
Matthew Treinish5c660ab2014-05-18 21:14:36 -040048 @test.attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070049 def test_tenant_create_with_description(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050050 # Create tenant with a description
huangtianhuab0993eb2013-09-30 18:07:15 +080051 tenant_name = data_utils.rand_name(name='tenant-')
52 tenant_desc = data_utils.rand_name(name='desc-')
David Kranze9d2f422014-07-02 13:57:41 -040053 _, body = self.client.create_tenant(tenant_name,
54 description=tenant_desc)
Attila Fazekas40ec1232013-01-08 11:45:32 +010055 tenant = body
56 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070057 tenant_id = body['id']
58 desc1 = body['description']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070059 self.assertEqual(desc1, tenant_desc, 'Description should have '
Zhongyue Luo79d8d362012-09-25 13:49:27 +080060 'been sent in response for create')
David Kranze9d2f422014-07-02 13:57:41 -040061 _, body = self.client.get_tenant(tenant_id)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070062 desc2 = body['description']
63 self.assertEqual(desc2, tenant_desc, 'Description does not appear'
Zhongyue Luo79d8d362012-09-25 13:49:27 +080064 'to be set')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070065 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +010066 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070067
Matthew Treinish5c660ab2014-05-18 21:14:36 -040068 @test.attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070069 def test_tenant_create_enabled(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050070 # Create a tenant that is enabled
huangtianhuab0993eb2013-09-30 18:07:15 +080071 tenant_name = data_utils.rand_name(name='tenant-')
David Kranze9d2f422014-07-02 13:57:41 -040072 _, body = self.client.create_tenant(tenant_name, enabled=True)
Attila Fazekas40ec1232013-01-08 11:45:32 +010073 tenant = body
74 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070075 tenant_id = body['id']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070076 en1 = body['enabled']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070077 self.assertTrue(en1, 'Enable should be True in response')
David Kranze9d2f422014-07-02 13:57:41 -040078 _, body = self.client.get_tenant(tenant_id)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070079 en2 = body['enabled']
80 self.assertTrue(en2, 'Enable should be True in lookup')
81 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +010082 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070083
Matthew Treinish5c660ab2014-05-18 21:14:36 -040084 @test.attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070085 def test_tenant_create_not_enabled(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050086 # Create a tenant that is not enabled
huangtianhuab0993eb2013-09-30 18:07:15 +080087 tenant_name = data_utils.rand_name(name='tenant-')
David Kranze9d2f422014-07-02 13:57:41 -040088 _, body = self.client.create_tenant(tenant_name, enabled=False)
Attila Fazekas40ec1232013-01-08 11:45:32 +010089 tenant = body
90 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070091 tenant_id = body['id']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070092 en1 = body['enabled']
Vincent Hou6b8a7b72012-08-25 01:24:33 +080093 self.assertEqual('false', str(en1).lower(),
94 'Enable should be False in response')
David Kranze9d2f422014-07-02 13:57:41 -040095 _, body = self.client.get_tenant(tenant_id)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070096 en2 = body['enabled']
Vincent Hou6b8a7b72012-08-25 01:24:33 +080097 self.assertEqual('false', str(en2).lower(),
98 'Enable should be False in lookup')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070099 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100100 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700101
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400102 @test.attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700103 def test_tenant_update_name(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500104 # Update name attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800105 t_name1 = data_utils.rand_name(name='tenant-')
David Kranze9d2f422014-07-02 13:57:41 -0400106 _, body = self.client.create_tenant(t_name1)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100107 tenant = body
108 self.data.tenants.append(tenant)
109
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700110 t_id = body['id']
111 resp1_name = body['name']
112
huangtianhuab0993eb2013-09-30 18:07:15 +0800113 t_name2 = data_utils.rand_name(name='tenant2-')
David Kranze9d2f422014-07-02 13:57:41 -0400114 _, body = self.client.update_tenant(t_id, name=t_name2)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700115 resp2_name = body['name']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700116 self.assertNotEqual(resp1_name, resp2_name)
117
David Kranze9d2f422014-07-02 13:57:41 -0400118 _, body = self.client.get_tenant(t_id)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700119 resp3_name = body['name']
120
121 self.assertNotEqual(resp1_name, resp3_name)
122 self.assertEqual(t_name1, resp1_name)
123 self.assertEqual(resp2_name, resp3_name)
124
125 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100126 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700127
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400128 @test.attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700129 def test_tenant_update_desc(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500130 # Update description attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800131 t_name = data_utils.rand_name(name='tenant-')
132 t_desc = data_utils.rand_name(name='desc-')
David Kranze9d2f422014-07-02 13:57:41 -0400133 _, body = self.client.create_tenant(t_name, description=t_desc)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100134 tenant = body
135 self.data.tenants.append(tenant)
136
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700137 t_id = body['id']
138 resp1_desc = body['description']
139
huangtianhuab0993eb2013-09-30 18:07:15 +0800140 t_desc2 = data_utils.rand_name(name='desc2-')
David Kranze9d2f422014-07-02 13:57:41 -0400141 _, body = self.client.update_tenant(t_id, description=t_desc2)
Gordon Chungad873602013-02-18 19:26:27 -0500142 resp2_desc = body['description']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700143 self.assertNotEqual(resp1_desc, resp2_desc)
144
David Kranze9d2f422014-07-02 13:57:41 -0400145 _, body = self.client.get_tenant(t_id)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700146 resp3_desc = body['description']
147
148 self.assertNotEqual(resp1_desc, resp3_desc)
149 self.assertEqual(t_desc, resp1_desc)
150 self.assertEqual(resp2_desc, resp3_desc)
151
152 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100153 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700154
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400155 @test.attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700156 def test_tenant_update_enable(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500157 # Update the enabled attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800158 t_name = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700159 t_en = False
David Kranze9d2f422014-07-02 13:57:41 -0400160 _, body = self.client.create_tenant(t_name, enabled=t_en)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100161 tenant = body
162 self.data.tenants.append(tenant)
163
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700164 t_id = body['id']
165 resp1_en = body['enabled']
166
167 t_en2 = True
David Kranze9d2f422014-07-02 13:57:41 -0400168 _, body = self.client.update_tenant(t_id, enabled=t_en2)
Gordon Chungad873602013-02-18 19:26:27 -0500169 resp2_en = body['enabled']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700170 self.assertNotEqual(resp1_en, resp2_en)
171
David Kranze9d2f422014-07-02 13:57:41 -0400172 _, body = self.client.get_tenant(t_id)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700173 resp3_en = body['enabled']
174
175 self.assertNotEqual(resp1_en, resp3_en)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800176 self.assertEqual('false', str(resp1_en).lower())
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700177 self.assertEqual(resp2_en, resp3_en)
178
179 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100180 self.data.tenants.remove(tenant)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800181
182
Attila Fazekas0d0c6162013-02-24 09:14:23 +0100183class TenantsTestXML(TenantsTestJSON):
184 _interface = 'xml'