blob: 7a1e3a5582ea4d70f88f4b08fd45c95023eced18 [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log as logging
Jay Pipesf38eaac2012-06-21 13:37:35 -040017
Fei Long Wangd39431f2015-05-14 11:30:48 +120018from tempest.common.utils import data_utils
Matthew Treinishdb2c5972014-01-31 22:18:59 +000019from tempest import config
Jordan Pittier9e227c52016-02-09 14:35:18 +010020from tempest.lib.common.utils import test_utils
Attila Fazekasdc216422013-01-29 15:12:14 +010021import tempest.test
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070022
Matthew Treinishdb2c5972014-01-31 22:18:59 +000023CONF = config.CONF
Masayuki Igawa630a3fa2014-03-12 19:51:45 +090024LOG = logging.getLogger(__name__)
Matthew Treinishdb2c5972014-01-31 22:18:59 +000025
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070026
Chris Hoge4f6117a2015-03-20 12:39:33 -050027class BaseIdentityTest(tempest.test.BaseTestCase):
Jay Pipesf38eaac2012-06-21 13:37:35 -040028
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070029 @classmethod
Matthew Treinishdb2c5972014-01-31 22:18:59 +000030 def disable_user(cls, user_name):
31 user = cls.get_user_by_name(user_name)
ghanshyam9c257a72016-06-21 10:15:10 +090032 cls.users_client.update_user_enabled(user['id'], enabled=False)
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070033
Matthew Treinishdb2c5972014-01-31 22:18:59 +000034 @classmethod
35 def disable_tenant(cls, tenant_name):
36 tenant = cls.get_tenant_by_name(tenant_name)
Daniel Melladob04da902015-11-20 17:43:12 +010037 cls.tenants_client.update_tenant(tenant['id'], enabled=False)
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070038
Matthew Treinishdb2c5972014-01-31 22:18:59 +000039 @classmethod
Tom Cocozzello5544c172016-02-23 17:50:28 -060040 def get_user_by_name(cls, name, domain_id=None):
41 if domain_id:
42 params = {'domain_id': domain_id}
43 users = cls.users_client.list_users(params)['users']
44 else:
45 users = cls.users_client.list_users()['users']
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070046 user = [u for u in users if u['name'] == name]
47 if len(user) > 0:
48 return user[0]
49
Matthew Treinishdb2c5972014-01-31 22:18:59 +000050 @classmethod
51 def get_tenant_by_name(cls, name):
52 try:
Daniel Melladob04da902015-11-20 17:43:12 +010053 tenants = cls.tenants_client.list_tenants()['tenants']
Matthew Treinishdb2c5972014-01-31 22:18:59 +000054 except AttributeError:
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060055 tenants = cls.projects_client.list_projects()['projects']
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070056 tenant = [t for t in tenants if t['name'] == name]
57 if len(tenant) > 0:
58 return tenant[0]
59
Matthew Treinishdb2c5972014-01-31 22:18:59 +000060 @classmethod
61 def get_role_by_name(cls, name):
Daniel Mellado6b16b922015-12-07 12:43:08 +000062 roles = cls.roles_client.list_roles()['roles']
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070063 role = [r for r in roles if r['name'] == name]
64 if len(role) > 0:
65 return role[0]
66
67
Chris Hoge4f6117a2015-03-20 12:39:33 -050068class BaseIdentityV2Test(BaseIdentityTest):
69
Andrea Frittolib21de6c2015-02-06 20:12:38 +000070 credentials = ['primary']
71
Andrea Frittoli (andreaf)41601412015-05-12 16:39:03 +010072 # identity v2 tests should obtain tokens and create accounts via v2
73 # regardless of the configured CONF.identity.auth_version
74 identity_version = 'v2'
Rohan Kanadeb645e172015-02-05 17:38:59 +053075
76 @classmethod
77 def setup_clients(cls):
Chris Hoge4f6117a2015-03-20 12:39:33 -050078 super(BaseIdentityV2Test, cls).setup_clients()
Jane Zadorozhnabfc72372015-06-16 17:32:59 +030079 cls.non_admin_client = cls.os.identity_public_client
Chris Hoge4f6117a2015-03-20 12:39:33 -050080 cls.non_admin_token_client = cls.os.token_client
Daniel Melladob04da902015-11-20 17:43:12 +010081 cls.non_admin_tenants_client = cls.os.tenants_public_client
Daniel Mellado82c83a52015-12-09 15:16:49 +000082 cls.non_admin_users_client = cls.os.users_public_client
Chris Hoge4f6117a2015-03-20 12:39:33 -050083
Chris Hoge4f6117a2015-03-20 12:39:33 -050084
85class BaseIdentityV2AdminTest(BaseIdentityV2Test):
86
Andrea Frittoli (andreaf)41601412015-05-12 16:39:03 +010087 credentials = ['primary', 'admin']
Chris Hoge4f6117a2015-03-20 12:39:33 -050088
89 @classmethod
90 def setup_clients(cls):
Rohan Kanadeb645e172015-02-05 17:38:59 +053091 super(BaseIdentityV2AdminTest, cls).setup_clients()
Matthew Treinishdb2c5972014-01-31 22:18:59 +000092 cls.client = cls.os_adm.identity_client
Jane Zadorozhnabfc72372015-06-16 17:32:59 +030093 cls.non_admin_client = cls.os.identity_client
Matthew Treinishdb2c5972014-01-31 22:18:59 +000094 cls.token_client = cls.os_adm.token_client
Daniel Melladob04da902015-11-20 17:43:12 +010095 cls.tenants_client = cls.os_adm.tenants_client
96 cls.non_admin_tenants_client = cls.os.tenants_client
Daniel Mellado6b16b922015-12-07 12:43:08 +000097 cls.roles_client = cls.os_adm.roles_client
98 cls.non_admin_roles_client = cls.os.roles_client
Daniel Mellado82c83a52015-12-09 15:16:49 +000099 cls.users_client = cls.os_adm.users_client
100 cls.non_admin_users_client = cls.os.users_client
Yaroslav Lobankovf6906e12016-02-26 19:44:53 -0600101 cls.services_client = cls.os_adm.identity_services_client
102 cls.endpoints_client = cls.os_adm.endpoints_client
Rohan Kanadeb645e172015-02-05 17:38:59 +0530103
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000104 @classmethod
Rohan Kanadeb645e172015-02-05 17:38:59 +0530105 def resource_setup(cls):
106 super(BaseIdentityV2AdminTest, cls).resource_setup()
Arx Cruz24bcb882016-02-10 15:20:16 +0100107 cls.data = DataGeneratorV2(cls.tenants_client, cls.users_client,
108 cls.roles_client)
Rohan Kanadeb645e172015-02-05 17:38:59 +0530109
110 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +0100111 def resource_cleanup(cls):
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000112 cls.data.teardown_all()
Andrea Frittoli7688e742014-09-15 12:38:22 +0100113 super(BaseIdentityV2AdminTest, cls).resource_cleanup()
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000114
115
Chris Hoge4f6117a2015-03-20 12:39:33 -0500116class BaseIdentityV3Test(BaseIdentityTest):
117
Andrea Frittolib21de6c2015-02-06 20:12:38 +0000118 credentials = ['primary']
119
Andrea Frittoli (andreaf)41601412015-05-12 16:39:03 +0100120 # identity v3 tests should obtain tokens and create accounts via v3
121 # regardless of the configured CONF.identity.auth_version
122 identity_version = 'v3'
Rohan Kanadeb645e172015-02-05 17:38:59 +0530123
124 @classmethod
125 def setup_clients(cls):
Chris Hoge4f6117a2015-03-20 12:39:33 -0500126 super(BaseIdentityV3Test, cls).setup_clients()
127 cls.non_admin_client = cls.os.identity_v3_client
Daniel Mellado7aea5342016-02-09 09:10:12 +0000128 cls.non_admin_users_client = cls.os.users_v3_client
Chris Hoge4f6117a2015-03-20 12:39:33 -0500129 cls.non_admin_token = cls.os.token_v3_client
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -0600130 cls.non_admin_projects_client = cls.os.projects_client
Chris Hoge4f6117a2015-03-20 12:39:33 -0500131
Chris Hoge4f6117a2015-03-20 12:39:33 -0500132
133class BaseIdentityV3AdminTest(BaseIdentityV3Test):
134
Andrea Frittoli (andreaf)41601412015-05-12 16:39:03 +0100135 credentials = ['primary', 'admin']
Chris Hoge4f6117a2015-03-20 12:39:33 -0500136
137 @classmethod
138 def setup_clients(cls):
Rohan Kanadeb645e172015-02-05 17:38:59 +0530139 super(BaseIdentityV3AdminTest, cls).setup_clients()
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000140 cls.client = cls.os_adm.identity_v3_client
Daniel Mellado91a26b62016-02-11 11:13:04 +0000141 cls.domains_client = cls.os_adm.domains_client
Daniel Mellado7aea5342016-02-09 09:10:12 +0000142 cls.users_client = cls.os_adm.users_v3_client
Daniel Mellado76405392016-02-11 12:47:12 +0000143 cls.trusts_client = cls.os_adm.trusts_client
Arx Cruz24bcb882016-02-10 15:20:16 +0100144 cls.roles_client = cls.os_adm.roles_v3_client
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000145 cls.token = cls.os_adm.token_v3_client
Yaroslav Lobankovf6906e12016-02-26 19:44:53 -0600146 cls.endpoints_client = cls.os_adm.endpoints_v3_client
Yaroslav Lobankov757d1a22015-12-18 11:43:02 +0300147 cls.regions_client = cls.os_adm.regions_client
Yaroslav Lobankovf6906e12016-02-26 19:44:53 -0600148 cls.services_client = cls.os_adm.identity_services_v3_client
Yaroslav Lobankoved4d15c2015-12-18 11:30:10 +0300149 cls.policies_client = cls.os_adm.policies_client
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000150 cls.creds_client = cls.os_adm.credentials_client
Yaroslav Lobankov997a1452015-11-19 17:11:37 +0300151 cls.groups_client = cls.os_adm.groups_client
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -0600152 cls.projects_client = cls.os_adm.projects_client
Andrea Frittoli (andreaf)100d18d2016-05-05 23:34:52 +0100153 if CONF.identity.admin_domain_scope:
154 # NOTE(andreaf) When keystone policy requires it, the identity
155 # admin clients for these tests shall use 'domain' scoped tokens.
156 # As the client manager is already created by the base class,
157 # we set the scope for the inner auth provider.
158 cls.os_adm.auth_provider.scope = 'domain'
Yaroslav Lobankov997a1452015-11-19 17:11:37 +0300159
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300160 @classmethod
161 def resource_setup(cls):
162 super(BaseIdentityV3AdminTest, cls).resource_setup()
Arx Cruz24bcb882016-02-10 15:20:16 +0100163 cls.data = DataGeneratorV3(cls.projects_client, cls.users_client,
164 cls.roles_client, cls.domains_client)
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000165
166 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +0100167 def resource_cleanup(cls):
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000168 cls.data.teardown_all()
Andrea Frittoli7688e742014-09-15 12:38:22 +0100169 super(BaseIdentityV3AdminTest, cls).resource_cleanup()
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000170
David Kranzd8ccb792014-12-29 11:32:05 -0500171 @classmethod
Tom Cocozzello5544c172016-02-23 17:50:28 -0600172 def disable_user(cls, user_name, domain_id=None):
173 user = cls.get_user_by_name(user_name, domain_id)
Daniel Mellado7aea5342016-02-09 09:10:12 +0000174 cls.users_client.update_user(user['id'], user_name, enabled=False)
BinBin Congc6e8ef52015-11-20 02:08:46 -0500175
Martin Pavlasek4c3f2ab2014-04-15 17:15:15 +0200176 def delete_domain(self, domain_id):
177 # NOTE(mpavlase) It is necessary to disable the domain before deleting
178 # otherwise it raises Forbidden exception
Daniel Mellado91a26b62016-02-11 11:13:04 +0000179 self.domains_client.update_domain(domain_id, enabled=False)
180 self.domains_client.delete_domain(domain_id)
Martin Pavlasek4c3f2ab2014-04-15 17:15:15 +0200181
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000182
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300183class BaseDataGenerator(object):
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700184
Arx Cruz24bcb882016-02-10 15:20:16 +0100185 def __init__(self, projects_client, users_client, roles_client,
186 domains_client=None):
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -0600187 self.projects_client = projects_client
Daniel Mellado7aea5342016-02-09 09:10:12 +0000188 self.users_client = users_client
Arx Cruz24bcb882016-02-10 15:20:16 +0100189 self.roles_client = roles_client
Daniel Mellado91a26b62016-02-11 11:13:04 +0000190 self.domains_client = domains_client
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700191
Yaroslav Lobankov95aa3f72016-01-28 15:39:49 -0600192 self.user_password = None
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300193 self.user = None
194 self.tenant = None
195 self.project = None
196 self.role = None
197 self.domain = None
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700198
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300199 self.users = []
200 self.tenants = []
201 self.projects = []
202 self.roles = []
203 self.domains = []
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700204
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300205 def _create_test_user(self, **kwargs):
Yaroslav Lobankov95aa3f72016-01-28 15:39:49 -0600206 self.user_password = data_utils.rand_password()
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300207 self.user = self.users_client.create_user(
ghanshyame1c6c1c2016-06-15 14:50:41 +0900208 password=self.user_password,
209 **kwargs)['user']
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300210 self.users.append(self.user)
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700211
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300212 def setup_test_role(self):
213 """Set up a test role."""
Yaroslav Lobankov95aa3f72016-01-28 15:39:49 -0600214 self.role = self.roles_client.create_role(
215 name=data_utils.rand_name('test_role'))['role']
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300216 self.roles.append(self.role)
Nayna Patele6331362013-08-12 06:59:48 +0000217
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300218 def teardown_all(self):
219 for user in self.users:
Matthew Treinish03f09f92016-06-23 15:32:33 -0400220 test_utils.call_and_ignore_notfound_exc(
221 self.users_client.delete_user, user)
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300222 for tenant in self.tenants:
Matthew Treinish03f09f92016-06-23 15:32:33 -0400223 test_utils.call_and_ignore_notfound_exc(
224 self.projects_client.delete_tenant, tenant)
Brant Knudsone77b6892016-06-23 13:07:47 -0500225 for project in reversed(self.projects):
Matthew Treinish03f09f92016-06-23 15:32:33 -0400226 test_utils.call_and_ignore_notfound_exc(
227 self.projects_client.delete_project, project)
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300228 for role in self.roles:
Matthew Treinish03f09f92016-06-23 15:32:33 -0400229 test_utils.call_and_ignore_notfound_exc(
230 self.roles_client.delete_role, role)
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300231 for domain in self.domains:
Matthew Treinish03f09f92016-06-23 15:32:33 -0400232 test_utils.call_and_ignore_notfound_exc(
233 self.domains_client.update_domain, domain, enabled=False)
234 test_utils.call_and_ignore_notfound_exc(
235 self.domains_client.delete_domain, domain)
Nayna Patele6331362013-08-12 06:59:48 +0000236
nayna-patel2db83b32014-05-15 11:41:03 +0000237
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300238class DataGeneratorV2(BaseDataGenerator):
Masayuki Igawa630a3fa2014-03-12 19:51:45 +0900239
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300240 def setup_test_user(self):
241 """Set up a test user."""
242 self.setup_test_tenant()
ghanshyame1c6c1c2016-06-15 14:50:41 +0900243 username = data_utils.rand_name('test_user')
244 email = username + '@testmail.tm'
245 self._create_test_user(name=username, email=email,
246 tenantId=self.tenant['id'])
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300247
248 def setup_test_tenant(self):
249 """Set up a test tenant."""
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300250 self.tenant = self.projects_client.create_tenant(
Yaroslav Lobankov95aa3f72016-01-28 15:39:49 -0600251 name=data_utils.rand_name('test_tenant'),
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300252 description=data_utils.rand_name('desc'))['tenant']
253 self.tenants.append(self.tenant)
254
255
256class DataGeneratorV3(BaseDataGenerator):
257
258 def setup_test_user(self):
259 """Set up a test user."""
260 self.setup_test_project()
ghanshyame1c6c1c2016-06-15 14:50:41 +0900261 username = data_utils.rand_name('test_user')
262 email = username + '@testmail.tm'
263 self._create_test_user(user_name=username, email=email,
264 project_id=self.project['id'])
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300265
266 def setup_test_project(self):
267 """Set up a test project."""
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300268 self.project = self.projects_client.create_project(
Yaroslav Lobankov95aa3f72016-01-28 15:39:49 -0600269 name=data_utils.rand_name('test_project'),
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300270 description=data_utils.rand_name('desc'))['project']
271 self.projects.append(self.project)
272
273 def setup_test_domain(self):
274 """Set up a test domain."""
Daniel Mellado91a26b62016-02-11 11:13:04 +0000275 self.domain = self.domains_client.create_domain(
Yaroslav Lobankov2c2f0362016-01-13 18:07:22 +0300276 name=data_utils.rand_name('test_domain'),
277 description=data_utils.rand_name('desc'))['domain']
278 self.domains.append(self.domain)