blob: cfae3a16204065283f5ad4cf65fd5231a24dd8cd [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):
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070024
Matthew Treinish5c660ab2014-05-18 21:14:36 -040025 @test.attr(type='gate')
Attila Fazekas40ec1232013-01-08 11:45:32 +010026 def test_tenant_list_delete(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050027 # Create several tenants and delete them
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070028 tenants = []
llg821243b20502014-02-22 10:32:49 +080029 for _ in moves.xrange(3):
huangtianhuab0993eb2013-09-30 18:07:15 +080030 tenant_name = data_utils.rand_name(name='tenant-new')
David Kranzb7afa922014-12-30 10:56:26 -050031 tenant = self.client.create_tenant(tenant_name)
Attila Fazekas40ec1232013-01-08 11:45:32 +010032 self.data.tenants.append(tenant)
33 tenants.append(tenant)
34 tenant_ids = map(lambda x: x['id'], tenants)
David Kranzb7afa922014-12-30 10:56:26 -050035 body = self.client.list_tenants()
Matthew Treinishc795b9e2014-06-09 17:01:10 -040036 found = [t for t in body if t['id'] in tenant_ids]
Attila Fazekas40ec1232013-01-08 11:45:32 +010037 self.assertEqual(len(found), len(tenants), 'Tenants not created')
38
39 for tenant in tenants:
David Kranze9d2f422014-07-02 13:57:41 -040040 self.client.delete_tenant(tenant['id'])
Attila Fazekas40ec1232013-01-08 11:45:32 +010041 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070042
David Kranzb7afa922014-12-30 10:56:26 -050043 body = self.client.list_tenants()
Attila Fazekas40ec1232013-01-08 11:45:32 +010044 found = [tenant for tenant in body if tenant['id'] in tenant_ids]
45 self.assertFalse(any(found), 'Tenants failed to delete')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070046
Matthew Treinish5c660ab2014-05-18 21:14:36 -040047 @test.attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070048 def test_tenant_create_with_description(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050049 # Create tenant with a description
huangtianhuab0993eb2013-09-30 18:07:15 +080050 tenant_name = data_utils.rand_name(name='tenant-')
51 tenant_desc = data_utils.rand_name(name='desc-')
David Kranzb7afa922014-12-30 10:56:26 -050052 body = self.client.create_tenant(tenant_name,
53 description=tenant_desc)
Attila Fazekas40ec1232013-01-08 11:45:32 +010054 tenant = body
55 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070056 tenant_id = body['id']
57 desc1 = body['description']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070058 self.assertEqual(desc1, tenant_desc, 'Description should have '
Zhongyue Luo79d8d362012-09-25 13:49:27 +080059 'been sent in response for create')
David Kranzb7afa922014-12-30 10:56:26 -050060 body = self.client.get_tenant(tenant_id)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070061 desc2 = body['description']
62 self.assertEqual(desc2, tenant_desc, 'Description does not appear'
Zhongyue Luo79d8d362012-09-25 13:49:27 +080063 'to be set')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070064 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +010065 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070066
Matthew Treinish5c660ab2014-05-18 21:14:36 -040067 @test.attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070068 def test_tenant_create_enabled(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050069 # Create a tenant that is enabled
huangtianhuab0993eb2013-09-30 18:07:15 +080070 tenant_name = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -050071 body = self.client.create_tenant(tenant_name, enabled=True)
Attila Fazekas40ec1232013-01-08 11:45:32 +010072 tenant = body
73 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070074 tenant_id = body['id']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070075 en1 = body['enabled']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070076 self.assertTrue(en1, 'Enable should be True in response')
David Kranzb7afa922014-12-30 10:56:26 -050077 body = self.client.get_tenant(tenant_id)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070078 en2 = body['enabled']
79 self.assertTrue(en2, 'Enable should be True in lookup')
80 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +010081 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070082
Matthew Treinish5c660ab2014-05-18 21:14:36 -040083 @test.attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070084 def test_tenant_create_not_enabled(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050085 # Create a tenant that is not enabled
huangtianhuab0993eb2013-09-30 18:07:15 +080086 tenant_name = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -050087 body = self.client.create_tenant(tenant_name, enabled=False)
Attila Fazekas40ec1232013-01-08 11:45:32 +010088 tenant = body
89 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070090 tenant_id = body['id']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070091 en1 = body['enabled']
Vincent Hou6b8a7b72012-08-25 01:24:33 +080092 self.assertEqual('false', str(en1).lower(),
93 'Enable should be False in response')
David Kranzb7afa922014-12-30 10:56:26 -050094 body = self.client.get_tenant(tenant_id)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070095 en2 = body['enabled']
Vincent Hou6b8a7b72012-08-25 01:24:33 +080096 self.assertEqual('false', str(en2).lower(),
97 'Enable should be False in lookup')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070098 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +010099 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700100
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400101 @test.attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700102 def test_tenant_update_name(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500103 # Update name attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800104 t_name1 = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -0500105 body = self.client.create_tenant(t_name1)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100106 tenant = body
107 self.data.tenants.append(tenant)
108
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700109 t_id = body['id']
110 resp1_name = body['name']
111
huangtianhuab0993eb2013-09-30 18:07:15 +0800112 t_name2 = data_utils.rand_name(name='tenant2-')
David Kranzb7afa922014-12-30 10:56:26 -0500113 body = self.client.update_tenant(t_id, name=t_name2)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700114 resp2_name = body['name']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700115 self.assertNotEqual(resp1_name, resp2_name)
116
David Kranzb7afa922014-12-30 10:56:26 -0500117 body = self.client.get_tenant(t_id)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700118 resp3_name = body['name']
119
120 self.assertNotEqual(resp1_name, resp3_name)
121 self.assertEqual(t_name1, resp1_name)
122 self.assertEqual(resp2_name, resp3_name)
123
124 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100125 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700126
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400127 @test.attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700128 def test_tenant_update_desc(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500129 # Update description attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800130 t_name = data_utils.rand_name(name='tenant-')
131 t_desc = data_utils.rand_name(name='desc-')
David Kranzb7afa922014-12-30 10:56:26 -0500132 body = self.client.create_tenant(t_name, description=t_desc)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100133 tenant = body
134 self.data.tenants.append(tenant)
135
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700136 t_id = body['id']
137 resp1_desc = body['description']
138
huangtianhuab0993eb2013-09-30 18:07:15 +0800139 t_desc2 = data_utils.rand_name(name='desc2-')
David Kranzb7afa922014-12-30 10:56:26 -0500140 body = self.client.update_tenant(t_id, description=t_desc2)
Gordon Chungad873602013-02-18 19:26:27 -0500141 resp2_desc = body['description']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700142 self.assertNotEqual(resp1_desc, resp2_desc)
143
David Kranzb7afa922014-12-30 10:56:26 -0500144 body = self.client.get_tenant(t_id)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700145 resp3_desc = body['description']
146
147 self.assertNotEqual(resp1_desc, resp3_desc)
148 self.assertEqual(t_desc, resp1_desc)
149 self.assertEqual(resp2_desc, resp3_desc)
150
151 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100152 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700153
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400154 @test.attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700155 def test_tenant_update_enable(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500156 # Update the enabled attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800157 t_name = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700158 t_en = False
David Kranzb7afa922014-12-30 10:56:26 -0500159 body = self.client.create_tenant(t_name, enabled=t_en)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100160 tenant = body
161 self.data.tenants.append(tenant)
162
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700163 t_id = body['id']
164 resp1_en = body['enabled']
165
166 t_en2 = True
David Kranzb7afa922014-12-30 10:56:26 -0500167 body = self.client.update_tenant(t_id, enabled=t_en2)
Gordon Chungad873602013-02-18 19:26:27 -0500168 resp2_en = body['enabled']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700169 self.assertNotEqual(resp1_en, resp2_en)
170
David Kranzb7afa922014-12-30 10:56:26 -0500171 body = self.client.get_tenant(t_id)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700172 resp3_en = body['enabled']
173
174 self.assertNotEqual(resp1_en, resp3_en)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800175 self.assertEqual('false', str(resp1_en).lower())
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700176 self.assertEqual(resp2_en, resp3_en)
177
178 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100179 self.data.tenants.remove(tenant)