blob: 46fa7a9dfdbb1f103603e9680186c4bd3592c185 [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
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.identity import base
huangtianhuab0993eb2013-09-30 18:07:15 +080017from tempest.common.utils import data_utils
Chris Yeoh01cb2792013-02-09 22:25:37 +103018from tempest.test import attr
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070019
20
Attila Fazekas0d0c6162013-02-24 09:14:23 +010021class TenantsTestJSON(base.BaseIdentityAdminTest):
22 _interface = 'json'
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070023
Giampaolo Lauriaea294952013-05-15 08:52:04 -040024 @attr(type='gate')
Attila Fazekas40ec1232013-01-08 11:45:32 +010025 def test_tenant_list_delete(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050026 # Create several tenants and delete them
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070027 tenants = []
Attila Fazekas40ec1232013-01-08 11:45:32 +010028 for _ in xrange(3):
huangtianhuab0993eb2013-09-30 18:07:15 +080029 tenant_name = data_utils.rand_name(name='tenant-new')
30 resp, tenant = self.client.create_tenant(tenant_name)
31 self.assertEqual(200, resp.status)
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)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070035 resp, body = self.client.list_tenants()
Attila Fazekas40ec1232013-01-08 11:45:32 +010036 self.assertTrue(resp['status'].startswith('2'))
37 found = [tenant for tenant in body if tenant['id'] in tenant_ids]
38 self.assertEqual(len(found), len(tenants), 'Tenants not created')
39
40 for tenant in tenants:
41 resp, body = self.client.delete_tenant(tenant['id'])
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070042 self.assertTrue(resp['status'].startswith('2'))
Attila Fazekas40ec1232013-01-08 11:45:32 +010043 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070044
45 resp, body = self.client.list_tenants()
Attila Fazekas40ec1232013-01-08 11:45:32 +010046 found = [tenant for tenant in body if tenant['id'] in tenant_ids]
47 self.assertFalse(any(found), 'Tenants failed to delete')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070048
Giampaolo Lauriaea294952013-05-15 08:52:04 -040049 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070050 def test_tenant_create_with_description(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050051 # Create tenant with a description
huangtianhuab0993eb2013-09-30 18:07:15 +080052 tenant_name = data_utils.rand_name(name='tenant-')
53 tenant_desc = data_utils.rand_name(name='desc-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070054 resp, body = self.client.create_tenant(tenant_name,
55 description=tenant_desc)
Attila Fazekas40ec1232013-01-08 11:45:32 +010056 tenant = body
57 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070058 st1 = resp['status']
59 tenant_id = body['id']
60 desc1 = body['description']
61 self.assertTrue(st1.startswith('2'))
62 self.assertEqual(desc1, tenant_desc, 'Description should have '
Zhongyue Luo79d8d362012-09-25 13:49:27 +080063 'been sent in response for create')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070064 resp, body = self.client.get_tenant(tenant_id)
65 desc2 = body['description']
66 self.assertEqual(desc2, tenant_desc, 'Description does not appear'
Zhongyue Luo79d8d362012-09-25 13:49:27 +080067 'to be set')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070068 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +010069 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070070
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040071 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070072 def test_tenant_create_enabled(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050073 # Create a tenant that is enabled
huangtianhuab0993eb2013-09-30 18:07:15 +080074 tenant_name = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070075 resp, body = self.client.create_tenant(tenant_name, enabled=True)
Attila Fazekas40ec1232013-01-08 11:45:32 +010076 tenant = body
77 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070078 tenant_id = body['id']
79 st1 = resp['status']
80 en1 = body['enabled']
81 self.assertTrue(st1.startswith('2'))
82 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']
97 st1 = resp['status']
98 en1 = body['enabled']
99 self.assertTrue(st1.startswith('2'))
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800100 self.assertEqual('false', str(en1).lower(),
101 'Enable should be False in response')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700102 resp, body = self.client.get_tenant(tenant_id)
103 en2 = body['enabled']
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800104 self.assertEqual('false', str(en2).lower(),
105 'Enable should be False in lookup')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700106 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100107 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700108
Giampaolo Lauriaea294952013-05-15 08:52:04 -0400109 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700110 def test_tenant_update_name(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500111 # Update name attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800112 t_name1 = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700113 resp, body = self.client.create_tenant(t_name1)
huangtianhuab0993eb2013-09-30 18:07:15 +0800114 self.assertEqual(200, resp.status)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100115 tenant = body
116 self.data.tenants.append(tenant)
117
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700118 t_id = body['id']
119 resp1_name = body['name']
120
huangtianhuab0993eb2013-09-30 18:07:15 +0800121 t_name2 = data_utils.rand_name(name='tenant2-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700122 resp, body = self.client.update_tenant(t_id, name=t_name2)
123 st2 = resp['status']
124 resp2_name = body['name']
125 self.assertTrue(st2.startswith('2'))
126 self.assertNotEqual(resp1_name, resp2_name)
127
128 resp, body = self.client.get_tenant(t_id)
129 resp3_name = body['name']
130
131 self.assertNotEqual(resp1_name, resp3_name)
132 self.assertEqual(t_name1, resp1_name)
133 self.assertEqual(resp2_name, resp3_name)
134
135 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100136 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700137
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400138 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700139 def test_tenant_update_desc(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500140 # Update description attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800141 t_name = data_utils.rand_name(name='tenant-')
142 t_desc = data_utils.rand_name(name='desc-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700143 resp, body = self.client.create_tenant(t_name, description=t_desc)
huangtianhuab0993eb2013-09-30 18:07:15 +0800144 self.assertEqual(200, resp.status)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100145 tenant = body
146 self.data.tenants.append(tenant)
147
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700148 t_id = body['id']
149 resp1_desc = body['description']
150
huangtianhuab0993eb2013-09-30 18:07:15 +0800151 t_desc2 = data_utils.rand_name(name='desc2-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700152 resp, body = self.client.update_tenant(t_id, description=t_desc2)
153 st2 = resp['status']
Gordon Chungad873602013-02-18 19:26:27 -0500154 resp2_desc = body['description']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700155 self.assertTrue(st2.startswith('2'))
156 self.assertNotEqual(resp1_desc, resp2_desc)
157
158 resp, body = self.client.get_tenant(t_id)
159 resp3_desc = body['description']
160
161 self.assertNotEqual(resp1_desc, resp3_desc)
162 self.assertEqual(t_desc, resp1_desc)
163 self.assertEqual(resp2_desc, resp3_desc)
164
165 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100166 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700167
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400168 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700169 def test_tenant_update_enable(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500170 # Update the enabled attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800171 t_name = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700172 t_en = False
173 resp, body = self.client.create_tenant(t_name, enabled=t_en)
huangtianhuab0993eb2013-09-30 18:07:15 +0800174 self.assertEqual(200, resp.status)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100175 tenant = body
176 self.data.tenants.append(tenant)
177
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700178 t_id = body['id']
179 resp1_en = body['enabled']
180
181 t_en2 = True
182 resp, body = self.client.update_tenant(t_id, enabled=t_en2)
183 st2 = resp['status']
Gordon Chungad873602013-02-18 19:26:27 -0500184 resp2_en = body['enabled']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700185 self.assertTrue(st2.startswith('2'))
186 self.assertNotEqual(resp1_en, resp2_en)
187
188 resp, body = self.client.get_tenant(t_id)
189 resp3_en = body['enabled']
190
191 self.assertNotEqual(resp1_en, resp3_en)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800192 self.assertEqual('false', str(resp1_en).lower())
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700193 self.assertEqual(resp2_en, resp3_en)
194
195 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100196 self.data.tenants.remove(tenant)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800197
198
Attila Fazekas0d0c6162013-02-24 09:14:23 +0100199class TenantsTestXML(TenantsTestJSON):
200 _interface = 'xml'