blob: e36b5433b210387259b2e7c3e9e39850ce121b1c [file] [log] [blame]
Jay Pipesf38eaac2012-06-21 13:37:35 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipesf38eaac2012-06-21 13:37:35 -04004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
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
Attila Fazekas0d0c6162013-02-24 09:14:23 +010023class TenantsTestJSON(base.BaseIdentityAdminTest):
24 _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 = []
Attila Fazekas40ec1232013-01-08 11:45:32 +010030 for _ in 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()
Attila Fazekas40ec1232013-01-08 11:45:32 +010038 self.assertTrue(resp['status'].startswith('2'))
39 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'])
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070044 self.assertTrue(resp['status'].startswith('2'))
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 st1 = resp['status']
61 tenant_id = body['id']
62 desc1 = body['description']
63 self.assertTrue(st1.startswith('2'))
64 self.assertEqual(desc1, tenant_desc, 'Description should have '
Zhongyue Luo79d8d362012-09-25 13:49:27 +080065 'been sent in response for create')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070066 resp, body = self.client.get_tenant(tenant_id)
67 desc2 = body['description']
68 self.assertEqual(desc2, tenant_desc, 'Description does not appear'
Zhongyue Luo79d8d362012-09-25 13:49:27 +080069 'to be set')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070070 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +010071 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070072
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040073 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070074 def test_tenant_create_enabled(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050075 # Create a tenant that is enabled
huangtianhuab0993eb2013-09-30 18:07:15 +080076 tenant_name = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070077 resp, body = self.client.create_tenant(tenant_name, enabled=True)
Attila Fazekas40ec1232013-01-08 11:45:32 +010078 tenant = body
79 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070080 tenant_id = body['id']
81 st1 = resp['status']
82 en1 = body['enabled']
83 self.assertTrue(st1.startswith('2'))
84 self.assertTrue(en1, 'Enable should be True in response')
85 resp, body = self.client.get_tenant(tenant_id)
86 en2 = body['enabled']
87 self.assertTrue(en2, 'Enable should be True in lookup')
88 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +010089 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070090
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040091 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070092 def test_tenant_create_not_enabled(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050093 # Create a tenant that is not enabled
huangtianhuab0993eb2013-09-30 18:07:15 +080094 tenant_name = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070095 resp, body = self.client.create_tenant(tenant_name, enabled=False)
Attila Fazekas40ec1232013-01-08 11:45:32 +010096 tenant = body
97 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070098 tenant_id = body['id']
99 st1 = resp['status']
100 en1 = body['enabled']
101 self.assertTrue(st1.startswith('2'))
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800102 self.assertEqual('false', str(en1).lower(),
103 'Enable should be False in response')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700104 resp, body = self.client.get_tenant(tenant_id)
105 en2 = body['enabled']
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800106 self.assertEqual('false', str(en2).lower(),
107 'Enable should be False in lookup')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700108 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100109 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700110
Giampaolo Lauriaea294952013-05-15 08:52:04 -0400111 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700112 def test_tenant_update_name(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500113 # Update name attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800114 t_name1 = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700115 resp, body = self.client.create_tenant(t_name1)
huangtianhuab0993eb2013-09-30 18:07:15 +0800116 self.assertEqual(200, resp.status)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100117 tenant = body
118 self.data.tenants.append(tenant)
119
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700120 t_id = body['id']
121 resp1_name = body['name']
122
huangtianhuab0993eb2013-09-30 18:07:15 +0800123 t_name2 = data_utils.rand_name(name='tenant2-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700124 resp, body = self.client.update_tenant(t_id, name=t_name2)
125 st2 = resp['status']
126 resp2_name = body['name']
127 self.assertTrue(st2.startswith('2'))
128 self.assertNotEqual(resp1_name, resp2_name)
129
130 resp, body = self.client.get_tenant(t_id)
131 resp3_name = body['name']
132
133 self.assertNotEqual(resp1_name, resp3_name)
134 self.assertEqual(t_name1, resp1_name)
135 self.assertEqual(resp2_name, resp3_name)
136
137 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100138 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700139
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400140 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700141 def test_tenant_update_desc(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500142 # Update description attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800143 t_name = data_utils.rand_name(name='tenant-')
144 t_desc = data_utils.rand_name(name='desc-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700145 resp, body = self.client.create_tenant(t_name, description=t_desc)
huangtianhuab0993eb2013-09-30 18:07:15 +0800146 self.assertEqual(200, resp.status)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100147 tenant = body
148 self.data.tenants.append(tenant)
149
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700150 t_id = body['id']
151 resp1_desc = body['description']
152
huangtianhuab0993eb2013-09-30 18:07:15 +0800153 t_desc2 = data_utils.rand_name(name='desc2-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700154 resp, body = self.client.update_tenant(t_id, description=t_desc2)
155 st2 = resp['status']
Gordon Chungad873602013-02-18 19:26:27 -0500156 resp2_desc = body['description']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700157 self.assertTrue(st2.startswith('2'))
158 self.assertNotEqual(resp1_desc, resp2_desc)
159
160 resp, body = self.client.get_tenant(t_id)
161 resp3_desc = body['description']
162
163 self.assertNotEqual(resp1_desc, resp3_desc)
164 self.assertEqual(t_desc, resp1_desc)
165 self.assertEqual(resp2_desc, resp3_desc)
166
167 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100168 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700169
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400170 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700171 def test_tenant_update_enable(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500172 # Update the enabled attribute of a tenant
huangtianhuab0993eb2013-09-30 18:07:15 +0800173 t_name = data_utils.rand_name(name='tenant-')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700174 t_en = False
175 resp, body = self.client.create_tenant(t_name, enabled=t_en)
huangtianhuab0993eb2013-09-30 18:07:15 +0800176 self.assertEqual(200, resp.status)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100177 tenant = body
178 self.data.tenants.append(tenant)
179
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700180 t_id = body['id']
181 resp1_en = body['enabled']
182
183 t_en2 = True
184 resp, body = self.client.update_tenant(t_id, enabled=t_en2)
185 st2 = resp['status']
Gordon Chungad873602013-02-18 19:26:27 -0500186 resp2_en = body['enabled']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700187 self.assertTrue(st2.startswith('2'))
188 self.assertNotEqual(resp1_en, resp2_en)
189
190 resp, body = self.client.get_tenant(t_id)
191 resp3_en = body['enabled']
192
193 self.assertNotEqual(resp1_en, resp3_en)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800194 self.assertEqual('false', str(resp1_en).lower())
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700195 self.assertEqual(resp2_en, resp3_en)
196
197 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100198 self.data.tenants.remove(tenant)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800199
200
Attila Fazekas0d0c6162013-02-24 09:14:23 +0100201class TenantsTestXML(TenantsTestJSON):
202 _interface = 'xml'