ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 2 | # 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 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 16 | from tempest import config |
Ken'ichi Ohmichi | 7bd2575 | 2017-03-10 10:45:39 -0800 | [diff] [blame] | 17 | from tempest.lib.common.utils import data_utils |
Samantha Blanco | df33c78 | 2017-03-06 14:29:52 -0500 | [diff] [blame] | 18 | from tempest.lib.common.utils import test_utils |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 19 | import tempest.test |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 20 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 21 | CONF = config.CONF |
| 22 | |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 23 | |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 24 | class BaseIdentityTest(tempest.test.BaseTestCase): |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 25 | |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 26 | @classmethod |
Jordan Pittier | f7da5e5 | 2016-09-06 18:00:52 +0200 | [diff] [blame] | 27 | def setup_credentials(cls): |
| 28 | # Create no network resources for these test. |
| 29 | cls.set_network_resources() |
| 30 | super(BaseIdentityTest, cls).setup_credentials() |
| 31 | |
| 32 | @classmethod |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 33 | def disable_user(cls, user_name): |
| 34 | user = cls.get_user_by_name(user_name) |
ghanshyam | 9c257a7 | 2016-06-21 10:15:10 +0900 | [diff] [blame] | 35 | cls.users_client.update_user_enabled(user['id'], enabled=False) |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 36 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 37 | @classmethod |
| 38 | def disable_tenant(cls, tenant_name): |
| 39 | tenant = cls.get_tenant_by_name(tenant_name) |
Daniel Mellado | b04da90 | 2015-11-20 17:43:12 +0100 | [diff] [blame] | 40 | cls.tenants_client.update_tenant(tenant['id'], enabled=False) |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 41 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 42 | @classmethod |
Tom Cocozzello | 5544c17 | 2016-02-23 17:50:28 -0600 | [diff] [blame] | 43 | def get_user_by_name(cls, name, domain_id=None): |
| 44 | if domain_id: |
| 45 | params = {'domain_id': domain_id} |
ghanshyam | 7f817db | 2016-08-01 18:37:13 +0900 | [diff] [blame] | 46 | users = cls.users_client.list_users(**params)['users'] |
Tom Cocozzello | 5544c17 | 2016-02-23 17:50:28 -0600 | [diff] [blame] | 47 | else: |
| 48 | users = cls.users_client.list_users()['users'] |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 49 | user = [u for u in users if u['name'] == name] |
Masayuki Igawa | 0c0f014 | 2017-04-10 17:22:02 +0900 | [diff] [blame] | 50 | if user: |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 51 | return user[0] |
| 52 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 53 | @classmethod |
| 54 | def get_tenant_by_name(cls, name): |
| 55 | try: |
Daniel Mellado | b04da90 | 2015-11-20 17:43:12 +0100 | [diff] [blame] | 56 | tenants = cls.tenants_client.list_tenants()['tenants'] |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 57 | except AttributeError: |
Yaroslav Lobankov | 47a93ab | 2016-02-07 16:32:49 -0600 | [diff] [blame] | 58 | tenants = cls.projects_client.list_projects()['projects'] |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 59 | tenant = [t for t in tenants if t['name'] == name] |
Masayuki Igawa | 0c0f014 | 2017-04-10 17:22:02 +0900 | [diff] [blame] | 60 | if tenant: |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 61 | return tenant[0] |
| 62 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 63 | @classmethod |
| 64 | def get_role_by_name(cls, name): |
Daniel Mellado | 6b16b92 | 2015-12-07 12:43:08 +0000 | [diff] [blame] | 65 | roles = cls.roles_client.list_roles()['roles'] |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 66 | role = [r for r in roles if r['name'] == name] |
Masayuki Igawa | 0c0f014 | 2017-04-10 17:22:02 +0900 | [diff] [blame] | 67 | if role: |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 68 | return role[0] |
| 69 | |
zhufl | 75d51a9 | 2017-04-11 16:02:39 +0800 | [diff] [blame] | 70 | def create_test_user(self, **kwargs): |
Nicolas Helgeson | dffb867 | 2017-01-26 14:43:06 -0800 | [diff] [blame] | 71 | if kwargs.get('password', None) is None: |
zhufl | 75d51a9 | 2017-04-11 16:02:39 +0800 | [diff] [blame] | 72 | kwargs['password'] = data_utils.rand_password() |
| 73 | if 'name' not in kwargs: |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 74 | kwargs['name'] = data_utils.rand_name( |
| 75 | name='test_user', prefix=CONF.resource_name_prefix) |
zhufl | 75d51a9 | 2017-04-11 16:02:39 +0800 | [diff] [blame] | 76 | if 'email' not in kwargs: |
| 77 | kwargs['email'] = kwargs['name'] + '@testmail.tm' |
| 78 | |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 79 | user = self.users_client.create_user(**kwargs)['user'] |
| 80 | # Delete the user at the end of the test |
Samantha Blanco | df33c78 | 2017-03-06 14:29:52 -0500 | [diff] [blame] | 81 | self.addCleanup( |
| 82 | test_utils.call_and_ignore_notfound_exc, |
| 83 | self.users_client.delete_user, user['id']) |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 84 | return user |
| 85 | |
zhufl | 66b616a | 2017-04-11 15:00:32 +0800 | [diff] [blame] | 86 | def setup_test_role(self, name=None, domain_id=None): |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 87 | """Set up a test role.""" |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 88 | params = {'name': name or data_utils.rand_name( |
| 89 | name='test_role', prefix=CONF.resource_name_prefix)} |
Rodrigo Duarte | 34a6512 | 2017-01-27 11:28:26 -0300 | [diff] [blame] | 90 | if domain_id: |
| 91 | params['domain_id'] = domain_id |
| 92 | |
| 93 | role = self.roles_client.create_role(**params)['role'] |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 94 | # Delete the role at the end of the test |
Samantha Blanco | df33c78 | 2017-03-06 14:29:52 -0500 | [diff] [blame] | 95 | self.addCleanup( |
| 96 | test_utils.call_and_ignore_notfound_exc, |
| 97 | self.roles_client.delete_role, role['id']) |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 98 | return role |
| 99 | |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 100 | |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 101 | class BaseIdentityV2Test(BaseIdentityTest): |
| 102 | |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 103 | credentials = ['primary'] |
| 104 | |
Andrea Frittoli (andreaf) | 4160141 | 2015-05-12 16:39:03 +0100 | [diff] [blame] | 105 | # identity v2 tests should obtain tokens and create accounts via v2 |
| 106 | # regardless of the configured CONF.identity.auth_version |
| 107 | identity_version = 'v2' |
Rohan Kanade | b645e17 | 2015-02-05 17:38:59 +0530 | [diff] [blame] | 108 | |
| 109 | @classmethod |
| 110 | def setup_clients(cls): |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 111 | super(BaseIdentityV2Test, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 112 | cls.non_admin_client = cls.os_primary.identity_public_client |
| 113 | cls.non_admin_token_client = cls.os_primary.token_client |
| 114 | cls.non_admin_tenants_client = cls.os_primary.tenants_public_client |
| 115 | cls.non_admin_users_client = cls.os_primary.users_public_client |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 116 | |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 117 | |
| 118 | class BaseIdentityV2AdminTest(BaseIdentityV2Test): |
| 119 | |
Andrea Frittoli (andreaf) | 4160141 | 2015-05-12 16:39:03 +0100 | [diff] [blame] | 120 | credentials = ['primary', 'admin'] |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 121 | |
Andrea Frittoli | 00882b6 | 2016-12-19 23:22:44 +0000 | [diff] [blame] | 122 | # NOTE(andreaf) Identity tests work with credentials, so it is safer |
| 123 | # for them to always use disposable credentials. Forcing dynamic creds |
| 124 | # on regular identity tests would be however to restrictive, since it |
| 125 | # would prevent any identity test from being executed against clouds where |
| 126 | # admin credentials are not available. |
| 127 | # Since All admin tests require admin credentials to be |
| 128 | # executed, so this will not impact the ability to execute tests. |
| 129 | force_tenant_isolation = True |
| 130 | |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 131 | @classmethod |
Andrea Frittoli | 1413ba9 | 2017-04-21 14:33:23 +0100 | [diff] [blame] | 132 | def skip_checks(cls): |
| 133 | super(BaseIdentityV2AdminTest, cls).skip_checks() |
| 134 | if not CONF.identity_feature_enabled.api_v2_admin: |
| 135 | raise cls.skipException('Identity v2 admin not available') |
| 136 | |
| 137 | @classmethod |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 138 | def setup_clients(cls): |
Rohan Kanade | b645e17 | 2015-02-05 17:38:59 +0530 | [diff] [blame] | 139 | super(BaseIdentityV2AdminTest, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 140 | cls.client = cls.os_admin.identity_client |
| 141 | cls.non_admin_client = cls.os_primary.identity_client |
| 142 | cls.token_client = cls.os_admin.token_client |
| 143 | cls.tenants_client = cls.os_admin.tenants_client |
| 144 | cls.non_admin_tenants_client = cls.os_primary.tenants_client |
| 145 | cls.roles_client = cls.os_admin.roles_client |
| 146 | cls.non_admin_roles_client = cls.os_primary.roles_client |
| 147 | cls.users_client = cls.os_admin.users_client |
| 148 | cls.non_admin_users_client = cls.os_primary.users_client |
| 149 | cls.services_client = cls.os_admin.identity_services_client |
| 150 | cls.endpoints_client = cls.os_admin.endpoints_client |
Rohan Kanade | b645e17 | 2015-02-05 17:38:59 +0530 | [diff] [blame] | 151 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 152 | @classmethod |
Rohan Kanade | b645e17 | 2015-02-05 17:38:59 +0530 | [diff] [blame] | 153 | def resource_setup(cls): |
| 154 | super(BaseIdentityV2AdminTest, cls).resource_setup() |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 155 | cls.projects_client = cls.tenants_client |
Rohan Kanade | b645e17 | 2015-02-05 17:38:59 +0530 | [diff] [blame] | 156 | |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 157 | def setup_test_user(self, password=None): |
| 158 | """Set up a test user.""" |
| 159 | tenant = self.setup_test_tenant() |
zhufl | 75d51a9 | 2017-04-11 16:02:39 +0800 | [diff] [blame] | 160 | user = self.create_test_user(tenantId=tenant['id'], password=password) |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 161 | return user |
| 162 | |
zhufl | 963d2c3 | 2017-04-20 15:44:58 +0800 | [diff] [blame] | 163 | def setup_test_tenant(self, **kwargs): |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 164 | """Set up a test tenant.""" |
zhufl | 963d2c3 | 2017-04-20 15:44:58 +0800 | [diff] [blame] | 165 | if 'name' not in kwargs: |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 166 | kwargs['name'] = data_utils.rand_name( |
| 167 | name='test_tenant', |
| 168 | prefix=CONF.resource_name_prefix) |
zhufl | 963d2c3 | 2017-04-20 15:44:58 +0800 | [diff] [blame] | 169 | if 'description' not in kwargs: |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 170 | kwargs['description'] = data_utils.rand_name( |
| 171 | name='desc', prefix=CONF.resource_name_prefix) |
zhufl | 963d2c3 | 2017-04-20 15:44:58 +0800 | [diff] [blame] | 172 | tenant = self.projects_client.create_tenant(**kwargs)['tenant'] |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 173 | # Delete the tenant at the end of the test |
Samantha Blanco | df33c78 | 2017-03-06 14:29:52 -0500 | [diff] [blame] | 174 | self.addCleanup( |
| 175 | test_utils.call_and_ignore_notfound_exc, |
| 176 | self.tenants_client.delete_tenant, tenant['id']) |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 177 | return tenant |
| 178 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 179 | |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 180 | class BaseIdentityV3Test(BaseIdentityTest): |
| 181 | |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 182 | credentials = ['primary'] |
| 183 | |
Andrea Frittoli (andreaf) | 4160141 | 2015-05-12 16:39:03 +0100 | [diff] [blame] | 184 | # identity v3 tests should obtain tokens and create accounts via v3 |
| 185 | # regardless of the configured CONF.identity.auth_version |
| 186 | identity_version = 'v3' |
Rohan Kanade | b645e17 | 2015-02-05 17:38:59 +0530 | [diff] [blame] | 187 | |
| 188 | @classmethod |
| 189 | def setup_clients(cls): |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 190 | super(BaseIdentityV3Test, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 191 | cls.non_admin_client = cls.os_primary.identity_v3_client |
| 192 | cls.non_admin_users_client = cls.os_primary.users_v3_client |
| 193 | cls.non_admin_token = cls.os_primary.token_v3_client |
| 194 | cls.non_admin_projects_client = cls.os_primary.projects_client |
Megan Guiney | d029516 | 2017-05-23 23:57:53 -0700 | [diff] [blame] | 195 | cls.non_admin_catalog_client = cls.os_primary.catalog_client |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 196 | cls.non_admin_versions_client =\ |
| 197 | cls.os_primary.identity_versions_v3_client |
Colleen Murphy | 0e52d4e | 2018-02-17 21:29:40 +0100 | [diff] [blame] | 198 | cls.non_admin_app_creds_client = \ |
| 199 | cls.os_primary.application_credentials_client |
Colleen Murphy | d2cbd3a | 2019-12-17 16:31:14 -0800 | [diff] [blame] | 200 | cls.non_admin_access_rules_client = cls.os_primary.access_rules_client |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 201 | |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 202 | |
| 203 | class BaseIdentityV3AdminTest(BaseIdentityV3Test): |
| 204 | |
Andrea Frittoli (andreaf) | 4160141 | 2015-05-12 16:39:03 +0100 | [diff] [blame] | 205 | credentials = ['primary', 'admin'] |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 206 | |
Andrea Frittoli | 00882b6 | 2016-12-19 23:22:44 +0000 | [diff] [blame] | 207 | # NOTE(andreaf) Identity tests work with credentials, so it is safer |
| 208 | # for them to always use disposable credentials. Forcing dynamic creds |
| 209 | # on regular identity tests would be however to restrictive, since it |
| 210 | # would prevent any identity test from being executed against clouds where |
| 211 | # admin credentials are not available. |
| 212 | # Since All admin tests require admin credentials to be |
| 213 | # executed, so this will not impact the ability to execute tests. |
| 214 | force_tenant_isolation = True |
| 215 | |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 216 | @classmethod |
| 217 | def setup_clients(cls): |
Rohan Kanade | b645e17 | 2015-02-05 17:38:59 +0530 | [diff] [blame] | 218 | super(BaseIdentityV3AdminTest, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 219 | cls.client = cls.os_admin.identity_v3_client |
| 220 | cls.domains_client = cls.os_admin.domains_client |
| 221 | cls.users_client = cls.os_admin.users_v3_client |
| 222 | cls.trusts_client = cls.os_admin.trusts_client |
| 223 | cls.roles_client = cls.os_admin.roles_v3_client |
| 224 | cls.inherited_roles_client = cls.os_admin.inherited_roles_client |
| 225 | cls.token = cls.os_admin.token_v3_client |
| 226 | cls.endpoints_client = cls.os_admin.endpoints_v3_client |
| 227 | cls.regions_client = cls.os_admin.regions_client |
| 228 | cls.services_client = cls.os_admin.identity_services_v3_client |
| 229 | cls.policies_client = cls.os_admin.policies_client |
| 230 | cls.creds_client = cls.os_admin.credentials_client |
| 231 | cls.groups_client = cls.os_admin.groups_client |
| 232 | cls.projects_client = cls.os_admin.projects_client |
Rodrigo Duarte | 12f8d4a | 2016-07-08 11:53:53 -0300 | [diff] [blame] | 233 | cls.role_assignments = cls.os_admin.role_assignments_client |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 234 | cls.oauth_consumers_client = cls.os_admin.oauth_consumers_client |
Hemanth Nakkina | d9594f5 | 2017-04-19 11:14:40 +0530 | [diff] [blame] | 235 | cls.oauth_token_client = cls.os_admin.oauth_token_client |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 236 | cls.domain_config_client = cls.os_admin.domain_config_client |
| 237 | cls.endpoint_filter_client = cls.os_admin.endpoint_filter_client |
Chi Lo | d0ed8b0 | 2017-04-22 05:35:53 -0500 | [diff] [blame] | 238 | cls.endpoint_groups_client = cls.os_admin.endpoint_groups_client |
Felipe Monteiro | a3b2d8e | 2018-03-15 04:47:52 +0000 | [diff] [blame] | 239 | cls.project_tags_client = cls.os_admin.project_tags_client |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 240 | |
Andrea Frittoli (andreaf) | 100d18d | 2016-05-05 23:34:52 +0100 | [diff] [blame] | 241 | if CONF.identity.admin_domain_scope: |
| 242 | # NOTE(andreaf) When keystone policy requires it, the identity |
| 243 | # admin clients for these tests shall use 'domain' scoped tokens. |
| 244 | # As the client manager is already created by the base class, |
| 245 | # we set the scope for the inner auth provider. |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 246 | cls.os_admin.auth_provider.scope = 'domain' |
Yaroslav Lobankov | 997a145 | 2015-11-19 17:11:37 +0300 | [diff] [blame] | 247 | |
Yaroslav Lobankov | 2c2f036 | 2016-01-13 18:07:22 +0300 | [diff] [blame] | 248 | @classmethod |
Tom Cocozzello | 5544c17 | 2016-02-23 17:50:28 -0600 | [diff] [blame] | 249 | def disable_user(cls, user_name, domain_id=None): |
| 250 | user = cls.get_user_by_name(user_name, domain_id) |
ghanshyam | 7f817db | 2016-08-01 18:37:13 +0900 | [diff] [blame] | 251 | cls.users_client.update_user(user['id'], name=user_name, enabled=False) |
BinBin Cong | c6e8ef5 | 2015-11-20 02:08:46 -0500 | [diff] [blame] | 252 | |
Castulo J. Martinez | 19b81b2 | 2016-07-15 08:58:25 -0700 | [diff] [blame] | 253 | @classmethod |
zhufl | 2b33c1a | 2017-04-24 17:33:48 +0800 | [diff] [blame] | 254 | def create_domain(cls, **kwargs): |
Castulo J. Martinez | 19b81b2 | 2016-07-15 08:58:25 -0700 | [diff] [blame] | 255 | """Create a domain.""" |
zhufl | 2b33c1a | 2017-04-24 17:33:48 +0800 | [diff] [blame] | 256 | if 'name' not in kwargs: |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 257 | kwargs['name'] = data_utils.rand_name( |
| 258 | name='test_domain', prefix=CONF.resource_name_prefix) |
zhufl | 2b33c1a | 2017-04-24 17:33:48 +0800 | [diff] [blame] | 259 | if 'description' not in kwargs: |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 260 | kwargs['description'] = data_utils.rand_name( |
| 261 | name='desc', prefix=CONF.resource_name_prefix) |
zhufl | 2b33c1a | 2017-04-24 17:33:48 +0800 | [diff] [blame] | 262 | domain = cls.domains_client.create_domain(**kwargs)['domain'] |
zhufl | eed21d7 | 2017-11-07 13:03:31 +0800 | [diff] [blame] | 263 | cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc, |
| 264 | cls.delete_domain, domain['id']) |
Castulo J. Martinez | 19b81b2 | 2016-07-15 08:58:25 -0700 | [diff] [blame] | 265 | return domain |
| 266 | |
zhufl | eed21d7 | 2017-11-07 13:03:31 +0800 | [diff] [blame] | 267 | @classmethod |
| 268 | def delete_domain(cls, domain_id): |
Martin Pavlasek | 4c3f2ab | 2014-04-15 17:15:15 +0200 | [diff] [blame] | 269 | # NOTE(mpavlase) It is necessary to disable the domain before deleting |
| 270 | # otherwise it raises Forbidden exception |
zhufl | eed21d7 | 2017-11-07 13:03:31 +0800 | [diff] [blame] | 271 | cls.domains_client.update_domain(domain_id, enabled=False) |
| 272 | cls.domains_client.delete_domain(domain_id) |
Martin Pavlasek | 4c3f2ab | 2014-04-15 17:15:15 +0200 | [diff] [blame] | 273 | |
Castulo J. Martinez | 19b81b2 | 2016-07-15 08:58:25 -0700 | [diff] [blame] | 274 | def setup_test_user(self, password=None): |
| 275 | """Set up a test user.""" |
| 276 | project = self.setup_test_project() |
zhufl | 75d51a9 | 2017-04-11 16:02:39 +0800 | [diff] [blame] | 277 | user = self.create_test_user(project_id=project['id'], |
| 278 | password=password) |
Castulo J. Martinez | 19b81b2 | 2016-07-15 08:58:25 -0700 | [diff] [blame] | 279 | return user |
| 280 | |
zhufl | f2f4705 | 2017-04-20 15:08:02 +0800 | [diff] [blame] | 281 | def setup_test_project(self, **kwargs): |
Castulo J. Martinez | 19b81b2 | 2016-07-15 08:58:25 -0700 | [diff] [blame] | 282 | """Set up a test project.""" |
zhufl | f2f4705 | 2017-04-20 15:08:02 +0800 | [diff] [blame] | 283 | if 'name' not in kwargs: |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 284 | kwargs['name'] = data_utils.rand_name( |
| 285 | name='test_project', prefix=CONF.resource_name_prefix) |
zhufl | f2f4705 | 2017-04-20 15:08:02 +0800 | [diff] [blame] | 286 | if 'description' not in kwargs: |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 287 | kwargs['description'] = data_utils.rand_name( |
| 288 | name='test_description', prefix=CONF.resource_name_prefix) |
zhufl | f2f4705 | 2017-04-20 15:08:02 +0800 | [diff] [blame] | 289 | project = self.projects_client.create_project(**kwargs)['project'] |
Castulo J. Martinez | 19b81b2 | 2016-07-15 08:58:25 -0700 | [diff] [blame] | 290 | # Delete the project at the end of the test |
Samantha Blanco | df33c78 | 2017-03-06 14:29:52 -0500 | [diff] [blame] | 291 | self.addCleanup( |
| 292 | test_utils.call_and_ignore_notfound_exc, |
| 293 | self.projects_client.delete_project, project['id']) |
Castulo J. Martinez | 19b81b2 | 2016-07-15 08:58:25 -0700 | [diff] [blame] | 294 | return project |
| 295 | |
| 296 | def setup_test_domain(self): |
| 297 | """Set up a test domain.""" |
| 298 | domain = self.create_domain() |
| 299 | # Delete the domain at the end of the test |
Samantha Blanco | df33c78 | 2017-03-06 14:29:52 -0500 | [diff] [blame] | 300 | self.addCleanup( |
| 301 | test_utils.call_and_ignore_notfound_exc, |
| 302 | self.delete_domain, domain['id']) |
Castulo J. Martinez | 19b81b2 | 2016-07-15 08:58:25 -0700 | [diff] [blame] | 303 | return domain |
Colleen Murphy | 0e52d4e | 2018-02-17 21:29:40 +0100 | [diff] [blame] | 304 | |
Felipe Monteiro | d441507 | 2018-07-03 14:09:02 -0400 | [diff] [blame] | 305 | def setup_test_group(self, **kwargs): |
| 306 | """Set up a test group.""" |
| 307 | if 'name' not in kwargs: |
| 308 | kwargs['name'] = data_utils.rand_name( |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 309 | self.__class__.__name__ + '_test_project', |
| 310 | prefix=CONF.resource_name_prefix) |
Felipe Monteiro | d441507 | 2018-07-03 14:09:02 -0400 | [diff] [blame] | 311 | if 'description' not in kwargs: |
| 312 | kwargs['description'] = data_utils.rand_name( |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 313 | self.__class__.__name__ + '_test_description', |
| 314 | prefix=CONF.resource_name_prefix) |
Felipe Monteiro | d441507 | 2018-07-03 14:09:02 -0400 | [diff] [blame] | 315 | group = self.groups_client.create_group(**kwargs)['group'] |
| 316 | self.addCleanup( |
| 317 | test_utils.call_and_ignore_notfound_exc, |
| 318 | self.groups_client.delete_group, group['id']) |
| 319 | return group |
| 320 | |
Colleen Murphy | 0e52d4e | 2018-02-17 21:29:40 +0100 | [diff] [blame] | 321 | |
| 322 | class BaseApplicationCredentialsV3Test(BaseIdentityV3Test): |
| 323 | |
| 324 | @classmethod |
Colleen Murphy | 0e52d4e | 2018-02-17 21:29:40 +0100 | [diff] [blame] | 325 | def resource_setup(cls): |
| 326 | super(BaseApplicationCredentialsV3Test, cls).resource_setup() |
| 327 | cls.user_id = cls.os_primary.credentials.user_id |
| 328 | cls.project_id = cls.os_primary.credentials.project_id |
| 329 | |
| 330 | def create_application_credential(self, name=None, **kwargs): |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 331 | name = name or data_utils.rand_name( |
| 332 | name='application_credential', prefix=CONF.resource_name_prefix) |
Colleen Murphy | 0e52d4e | 2018-02-17 21:29:40 +0100 | [diff] [blame] | 333 | application_credential = ( |
| 334 | self.non_admin_app_creds_client.create_application_credential( |
| 335 | self.user_id, name=name, **kwargs))['application_credential'] |
| 336 | self.addCleanup( |
| 337 | self.non_admin_app_creds_client.delete_application_credential, |
| 338 | self.user_id, |
| 339 | application_credential['id']) |
| 340 | return application_credential |