blob: 8d3a24d6a34f1a642e9dc1b8dc8b898a2b57aba9 [file] [log] [blame]
Matthew Treinishb86cda92013-07-29 11:22:23 -04001# Copyright 2013 IBM Corp.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050015import netaddr
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log as logging
Andrea Frittolic3280152015-02-26 12:42:34 +000017import six
Masayuki Igawabfa07602015-01-20 18:47:17 +090018from tempest_lib import exceptions as lib_exc
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050019
Matthew Treinishb86cda92013-07-29 11:22:23 -040020from tempest import clients
Jamie Lennox15350172015-08-17 10:54:25 +100021from tempest.common import cred_client
Marc Kodererd2690fe2014-07-16 14:17:47 +020022from tempest.common import cred_provider
Andrea Frittoli (andreaf)8def7ca2015-05-13 14:24:19 +010023from tempest.common.utils import data_utils
Matthew Treinishb86cda92013-07-29 11:22:23 -040024from tempest import config
25from tempest import exceptions
Matthew Treinishb86cda92013-07-29 11:22:23 -040026
Sean Dague86bd8422013-12-20 09:56:44 -050027CONF = config.CONF
Matthew Treinishb86cda92013-07-29 11:22:23 -040028LOG = logging.getLogger(__name__)
29
30
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -070031class DynamicCredentialProvider(cred_provider.CredentialProvider):
Matthew Treinishb86cda92013-07-29 11:22:23 -040032
Andrea Frittoli (andreaf)1eb04962015-10-09 14:48:06 +010033 def __init__(self, identity_version, name=None, network_resources=None,
Andrea Frittoli (andreaf)290b3e12015-10-08 10:25:02 +010034 credentials_domain=None, admin_role=None, admin_creds=None):
35 """Creates credentials dynamically for tests
36
37 A credential provider that, based on an initial set of
38 admin credentials, creates new credentials on the fly for
39 tests to use and then discard.
40
41 :param str identity_version: identity API version to use `v2` or `v3`
42 :param str admin_role: name of the admin role added to admin users
43 :param str name: names of dynamic resources include this parameter
44 when specified
45 :param str credentials_domain: name of the domain where the users
46 are created. If not defined, the project
47 domain from admin_credentials is used
48 :param dict network_resources: network resources to be created for
49 the created credentials
50 :param Credentials admin_creds: initial admin credentials
51 """
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -070052 super(DynamicCredentialProvider, self).__init__(
Andrea Frittoli (andreaf)290b3e12015-10-08 10:25:02 +010053 identity_version=identity_version, admin_role=admin_role,
54 name=name, credentials_domain=credentials_domain,
55 network_resources=network_resources)
56 self.network_resources = network_resources
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -070057 self._creds = {}
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050058 self.ports = []
Andrea Frittoli (andreaf)290b3e12015-10-08 10:25:02 +010059 self.default_admin_creds = admin_creds
Daniel Melladob04da902015-11-20 17:43:12 +010060 (self.identity_admin_client, self.tenants_admin_client,
Daniel Mellado6b16b922015-12-07 12:43:08 +000061 self.roles_admin_client,
Daniel Mellado82c83a52015-12-09 15:16:49 +000062 self.users_admin_client,
Daniel Melladob04da902015-11-20 17:43:12 +010063 self.network_admin_client,
John Warren3961acd2015-10-02 14:38:53 -040064 self.networks_admin_client,
John Warren49c0fe52015-10-22 12:35:54 -040065 self.subnets_admin_client,
John Warrenf9606e92015-12-10 12:12:42 -050066 self.ports_admin_client,
67 self.security_groups_admin_client) = self._get_admin_clients()
John Warren3961acd2015-10-02 14:38:53 -040068 # Domain where isolated credentials are provisioned (v3 only).
Andrea Frittolic3280152015-02-26 12:42:34 +000069 # Use that of the admin account is None is configured.
70 self.creds_domain_name = None
71 if self.identity_version == 'v3':
72 self.creds_domain_name = (
David Kranz87fc7e92015-07-28 14:05:20 -040073 self.default_admin_creds.project_domain_name or
Andrea Frittoli (andreaf)1eb04962015-10-09 14:48:06 +010074 self.credentials_domain)
Jamie Lennox15350172015-08-17 10:54:25 +100075 self.creds_client = cred_client.get_creds_client(
Daniel Melladob04da902015-11-20 17:43:12 +010076 self.identity_admin_client,
77 self.tenants_admin_client,
Daniel Mellado6b16b922015-12-07 12:43:08 +000078 self.roles_admin_client,
Daniel Mellado82c83a52015-12-09 15:16:49 +000079 self.users_admin_client,
Daniel Melladob04da902015-11-20 17:43:12 +010080 self.creds_domain_name)
Matthew Treinishb86cda92013-07-29 11:22:23 -040081
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050082 def _get_admin_clients(self):
Ken'ichi Ohmichicb67d2d2015-11-19 08:23:22 +000083 """Returns a tuple with instances of the following admin clients
84
85 (in this order):
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050086 identity
87 network
Matthew Treinishb86cda92013-07-29 11:22:23 -040088 """
Andrea Frittolic3280152015-02-26 12:42:34 +000089 os = clients.Manager(self.default_admin_creds)
90 if self.identity_version == 'v2':
Daniel Mellado6b16b922015-12-07 12:43:08 +000091 return (os.identity_client, os.tenants_client, os.roles_client,
Daniel Mellado82c83a52015-12-09 15:16:49 +000092 os.users_client, os.network_client, os.networks_client,
93 os.subnets_client, os.ports_client,
94 os.security_groups_client)
Andrea Frittolic3280152015-02-26 12:42:34 +000095 else:
Daniel Mellado82c83a52015-12-09 15:16:49 +000096 return (os.identity_v3_client, None, None, None, os.network_client,
John Warrenf9606e92015-12-10 12:12:42 -050097 os.networks_client, os.subnets_client, os.ports_client,
98 os.security_groups_client)
Matthew Treinishb86cda92013-07-29 11:22:23 -040099
Matthew Treinish976e8df2014-12-19 14:21:54 -0500100 def _create_creds(self, suffix="", admin=False, roles=None):
Sean Dague6969b902014-01-28 06:48:37 -0500101 """Create random credentials under the following schema.
102
103 If the name contains a '.' is the full class path of something, and
104 we don't really care. If it isn't, it's probably a meaningful name,
105 so use it.
106
107 For logging purposes, -user and -tenant are long and redundant,
108 don't use them. The user# will be sufficient to figure it out.
109 """
110 if '.' in self.name:
111 root = ""
112 else:
113 root = self.name
114
Andrea Frittolic3280152015-02-26 12:42:34 +0000115 project_name = data_utils.rand_name(root) + suffix
116 project_desc = project_name + "-desc"
117 project = self.creds_client.create_project(
118 name=project_name, description=project_desc)
Sean Dague6969b902014-01-28 06:48:37 -0500119
120 username = data_utils.rand_name(root) + suffix
LingxianKong9c713d22015-06-09 15:19:55 +0800121 user_password = data_utils.rand_password()
Sean Dague6969b902014-01-28 06:48:37 -0500122 email = data_utils.rand_name(root) + suffix + "@example.com"
Andrea Frittolic3280152015-02-26 12:42:34 +0000123 user = self.creds_client.create_user(
LingxianKong9c713d22015-06-09 15:19:55 +0800124 username, user_password, project, email)
John Warren56317e02015-08-12 20:48:32 +0000125 if 'user' in user:
126 user = user['user']
Matthew Treinish32f98a42015-07-14 19:58:46 -0400127 role_assigned = False
Matthew Treinishb86cda92013-07-29 11:22:23 -0400128 if admin:
Andrea Frittolic3280152015-02-26 12:42:34 +0000129 self.creds_client.assign_user_role(user, project,
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +0100130 self.admin_role)
Matthew Treinish32f98a42015-07-14 19:58:46 -0400131 role_assigned = True
Matthew Treinish976e8df2014-12-19 14:21:54 -0500132 # Add roles specified in config file
133 for conf_role in CONF.auth.tempest_roles:
Andrea Frittolic3280152015-02-26 12:42:34 +0000134 self.creds_client.assign_user_role(user, project, conf_role)
Matthew Treinish32f98a42015-07-14 19:58:46 -0400135 role_assigned = True
Matthew Treinish976e8df2014-12-19 14:21:54 -0500136 # Add roles requested by caller
137 if roles:
138 for role in roles:
Andrea Frittolic3280152015-02-26 12:42:34 +0000139 self.creds_client.assign_user_role(user, project, role)
Matthew Treinish32f98a42015-07-14 19:58:46 -0400140 role_assigned = True
141 # NOTE(mtreinish) For a user to have access to a project with v3 auth
142 # it must beassigned a role on the project. So we need to ensure that
143 # our newly created user has a role on the newly created project.
144 if self.identity_version == 'v3' and not role_assigned:
145 self.creds_client.create_user_role('Member')
146 self.creds_client.assign_user_role(user, project, 'Member')
147
LingxianKong9c713d22015-06-09 15:19:55 +0800148 creds = self.creds_client.get_credentials(user, project, user_password)
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400149 return cred_provider.TestResources(creds)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500150
151 def _create_network_resources(self, tenant_id):
152 network = None
153 subnet = None
154 router = None
Matthew Treinish9f756a02014-01-15 10:26:07 -0500155 # Make sure settings
156 if self.network_resources:
157 if self.network_resources['router']:
158 if (not self.network_resources['subnet'] or
159 not self.network_resources['network']):
160 raise exceptions.InvalidConfiguration(
161 'A router requires a subnet and network')
162 elif self.network_resources['subnet']:
163 if not self.network_resources['network']:
164 raise exceptions.InvalidConfiguration(
165 'A subnet requires a network')
166 elif self.network_resources['dhcp']:
167 raise exceptions.InvalidConfiguration('DHCP requires a subnet')
168
Masayuki Igawa259c1132013-10-31 17:48:44 +0900169 data_utils.rand_name_root = data_utils.rand_name(self.name)
Matthew Treinish9f756a02014-01-15 10:26:07 -0500170 if not self.network_resources or self.network_resources['network']:
171 network_name = data_utils.rand_name_root + "-network"
172 network = self._create_network(network_name, tenant_id)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500173 try:
Matthew Treinish9f756a02014-01-15 10:26:07 -0500174 if not self.network_resources or self.network_resources['subnet']:
175 subnet_name = data_utils.rand_name_root + "-subnet"
176 subnet = self._create_subnet(subnet_name, tenant_id,
177 network['id'])
178 if not self.network_resources or self.network_resources['router']:
179 router_name = data_utils.rand_name_root + "-router"
180 router = self._create_router(router_name, tenant_id)
181 self._add_router_interface(router['id'], subnet['id'])
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500182 except Exception:
183 if router:
184 self._clear_isolated_router(router['id'], router['name'])
185 if subnet:
186 self._clear_isolated_subnet(subnet['id'], subnet['name'])
187 if network:
188 self._clear_isolated_network(network['id'], network['name'])
189 raise
190 return network, subnet, router
191
192 def _create_network(self, name, tenant_id):
John Warren94d8faf2015-09-15 12:22:24 -0400193 resp_body = self.networks_admin_client.create_network(
Andrea Frittoliae9aca02014-09-25 11:43:11 +0100194 name=name, tenant_id=tenant_id)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500195 return resp_body['network']
196
197 def _create_subnet(self, subnet_name, tenant_id, network_id):
Sean Dague86bd8422013-12-20 09:56:44 -0500198 base_cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
199 mask_bits = CONF.network.tenant_network_mask_bits
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500200 for subnet_cidr in base_cidr.subnet(mask_bits):
201 try:
Andrea Frittoliae9aca02014-09-25 11:43:11 +0100202 if self.network_resources:
John Warren3961acd2015-10-02 14:38:53 -0400203 resp_body = self.subnets_admin_client.\
Andrea Frittoliae9aca02014-09-25 11:43:11 +0100204 create_subnet(
205 network_id=network_id, cidr=str(subnet_cidr),
206 name=subnet_name,
207 tenant_id=tenant_id,
208 enable_dhcp=self.network_resources['dhcp'],
209 ip_version=4)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500210 else:
John Warren3961acd2015-10-02 14:38:53 -0400211 resp_body = self.subnets_admin_client.\
Andrea Frittoliae9aca02014-09-25 11:43:11 +0100212 create_subnet(network_id=network_id,
213 cidr=str(subnet_cidr),
214 name=subnet_name,
215 tenant_id=tenant_id,
216 ip_version=4)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500217 break
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900218 except lib_exc.BadRequest as e:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500219 if 'overlaps with another subnet' not in str(e):
220 raise
221 else:
David Kranzd4210412014-11-21 08:37:45 -0500222 message = 'Available CIDR for subnet creation could not be found'
223 raise Exception(message)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500224 return resp_body['subnet']
225
226 def _create_router(self, router_name, tenant_id):
227 external_net_id = dict(
Sean Dague86bd8422013-12-20 09:56:44 -0500228 network_id=CONF.network.public_network_id)
David Kranz34e88122014-12-11 15:24:05 -0500229 resp_body = self.network_admin_client.create_router(
Andrea Frittoliae9aca02014-09-25 11:43:11 +0100230 router_name,
231 external_gateway_info=external_net_id,
232 tenant_id=tenant_id)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500233 return resp_body['router']
234
235 def _add_router_interface(self, router_id, subnet_id):
piyush11078694aca952015-12-17 12:54:44 +0530236 self.network_admin_client.add_router_interface(router_id,
237 subnet_id=subnet_id)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500238
Andrea Frittoli9612e812014-03-13 10:57:26 +0000239 def get_credentials(self, credential_type):
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700240 if self._creds.get(str(credential_type)):
241 credentials = self._creds[str(credential_type)]
Matthew Treinishb86cda92013-07-29 11:22:23 -0400242 else:
Matthew Treinish976e8df2014-12-19 14:21:54 -0500243 if credential_type in ['primary', 'alt', 'admin']:
244 is_admin = (credential_type == 'admin')
245 credentials = self._create_creds(admin=is_admin)
246 else:
247 credentials = self._create_creds(roles=credential_type)
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700248 self._creds[str(credential_type)] = credentials
Andrea Frittolifc315902014-03-20 09:21:44 +0000249 # Maintained until tests are ported
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700250 LOG.info("Acquired dynamic creds:\n credentials: %s"
Andrea Frittolifc315902014-03-20 09:21:44 +0000251 % credentials)
Adam Gandelman85395e72014-07-29 18:34:33 -0700252 if (CONF.service_available.neutron and
Matthew Treinish2219d382015-04-24 10:33:04 -0400253 not CONF.baremetal.driver_enabled and
254 CONF.auth.create_isolated_networks):
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500255 network, subnet, router = self._create_network_resources(
Andrea Frittolifc315902014-03-20 09:21:44 +0000256 credentials.tenant_id)
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400257 credentials.set_resources(network=network, subnet=subnet,
258 router=router)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500259 LOG.info("Created isolated network resources for : \n"
Andrea Frittolifc315902014-03-20 09:21:44 +0000260 + " credentials: %s" % credentials)
Andrea Frittoli9612e812014-03-13 10:57:26 +0000261 return credentials
Matthew Treinishb86cda92013-07-29 11:22:23 -0400262
Andrea Frittoli9612e812014-03-13 10:57:26 +0000263 def get_primary_creds(self):
264 return self.get_credentials('primary')
Matthew Treinishb86cda92013-07-29 11:22:23 -0400265
Andrea Frittoli9612e812014-03-13 10:57:26 +0000266 def get_admin_creds(self):
267 return self.get_credentials('admin')
Andrea Frittolifc315902014-03-20 09:21:44 +0000268
Andrea Frittoli9612e812014-03-13 10:57:26 +0000269 def get_alt_creds(self):
270 return self.get_credentials('alt')
Matthew Treinishb86cda92013-07-29 11:22:23 -0400271
Matthew Treinish976e8df2014-12-19 14:21:54 -0500272 def get_creds_by_roles(self, roles, force_new=False):
273 roles = list(set(roles))
274 # The roles list as a str will become the index as the dict key for
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700275 # the created credentials set in the dynamic_creds dict.
276 exist_creds = self._creds.get(str(roles))
Matthew Treinish976e8df2014-12-19 14:21:54 -0500277 # If force_new flag is True 2 cred sets with the same roles are needed
278 # handle this by creating a separate index for old one to store it
279 # separately for cleanup
280 if exist_creds and force_new:
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700281 new_index = str(roles) + '-' + str(len(self._creds))
282 self._creds[new_index] = exist_creds
283 del self._creds[str(roles)]
Matthew Treinish976e8df2014-12-19 14:21:54 -0500284 return self.get_credentials(roles)
285
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500286 def _clear_isolated_router(self, router_id, router_name):
287 net_client = self.network_admin_client
288 try:
289 net_client.delete_router(router_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900290 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000291 LOG.warning('router with name: %s not found for delete' %
292 router_name)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500293
294 def _clear_isolated_subnet(self, subnet_id, subnet_name):
John Warren3961acd2015-10-02 14:38:53 -0400295 client = self.subnets_admin_client
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500296 try:
John Warren3961acd2015-10-02 14:38:53 -0400297 client.delete_subnet(subnet_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900298 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000299 LOG.warning('subnet with name: %s not found for delete' %
300 subnet_name)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500301
302 def _clear_isolated_network(self, network_id, network_name):
John Warren94d8faf2015-09-15 12:22:24 -0400303 net_client = self.networks_admin_client
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500304 try:
305 net_client.delete_network(network_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900306 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000307 LOG.warning('network with name: %s not found for delete' %
308 network_name)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500309
Ala Rezmerita846eb7c2014-03-10 09:06:03 +0100310 def _cleanup_default_secgroup(self, tenant):
John Warrenf9606e92015-12-10 12:12:42 -0500311 nsg_client = self.security_groups_admin_client
312 resp_body = nsg_client.list_security_groups(tenant_id=tenant,
David Kranz34e88122014-12-11 15:24:05 -0500313 name="default")
Ala Rezmerita846eb7c2014-03-10 09:06:03 +0100314 secgroups_to_delete = resp_body['security_groups']
315 for secgroup in secgroups_to_delete:
316 try:
John Warrenf9606e92015-12-10 12:12:42 -0500317 nsg_client.delete_security_group(secgroup['id'])
Masayuki Igawabfa07602015-01-20 18:47:17 +0900318 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000319 LOG.warning('Security group %s, id %s not found for clean-up' %
320 (secgroup['name'], secgroup['id']))
Ala Rezmerita846eb7c2014-03-10 09:06:03 +0100321
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500322 def _clear_isolated_net_resources(self):
323 net_client = self.network_admin_client
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700324 for cred in self._creds:
325 creds = self._creds.get(cred)
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400326 if (not creds or not any([creds.router, creds.network,
327 creds.subnet])):
328 continue
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800329 LOG.debug("Clearing network: %(network)s, "
Matthew Treinishfe094ea2014-12-09 01:19:27 +0000330 "subnet: %(subnet)s, router: %(router)s",
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400331 {'network': creds.network, 'subnet': creds.subnet,
332 'router': creds.router})
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800333 if (not self.network_resources or
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400334 (self.network_resources.get('router') and creds.subnet)):
Matthew Treinish9f756a02014-01-15 10:26:07 -0500335 try:
piyush11078694aca952015-12-17 12:54:44 +0530336 net_client.remove_router_interface(
337 creds.router['id'],
338 subnet_id=creds.subnet['id'])
Masayuki Igawabfa07602015-01-20 18:47:17 +0900339 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000340 LOG.warning('router with name: %s not found for delete' %
341 creds.router['name'])
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400342 self._clear_isolated_router(creds.router['id'],
343 creds.router['name'])
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800344 if (not self.network_resources or
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800345 self.network_resources.get('subnet')):
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400346 self._clear_isolated_subnet(creds.subnet['id'],
347 creds.subnet['name'])
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800348 if (not self.network_resources or
349 self.network_resources.get('network')):
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400350 self._clear_isolated_network(creds.network['id'],
351 creds.network['name'])
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500352
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700353 def clear_creds(self):
354 if not self._creds:
Matthew Treinishb86cda92013-07-29 11:22:23 -0400355 return
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500356 self._clear_isolated_net_resources()
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700357 for creds in six.itervalues(self._creds):
Matthew Treinishb86cda92013-07-29 11:22:23 -0400358 try:
Andrea Frittolic3280152015-02-26 12:42:34 +0000359 self.creds_client.delete_user(creds.user_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900360 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000361 LOG.warning("user with name: %s not found for delete" %
362 creds.username)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400363 try:
Andrea Frittolic3280152015-02-26 12:42:34 +0000364 if CONF.service_available.neutron:
365 self._cleanup_default_secgroup(creds.tenant_id)
366 self.creds_client.delete_project(creds.tenant_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900367 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000368 LOG.warning("tenant with name: %s not found for delete" %
369 creds.tenant_name)
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700370 self._creds = {}
Andrea Frittoli8283b4e2014-07-17 13:28:58 +0100371
372 def is_multi_user(self):
373 return True
Yair Fried76488d72014-10-21 10:13:19 +0300374
375 def is_multi_tenant(self):
376 return True
Matthew Treinish4a596932015-03-06 20:37:01 -0500377
378 def is_role_available(self, role):
379 return True