blob: 5f6c8b87b26b0b9f107dabe990c7a13d16b6cd44 [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
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050018
Matthew Treinishb86cda92013-07-29 11:22:23 -040019from tempest import clients
Jamie Lennox15350172015-08-17 10:54:25 +100020from tempest.common import cred_client
Marc Kodererd2690fe2014-07-16 14:17:47 +020021from tempest.common import cred_provider
Andrea Frittoli (andreaf)8def7ca2015-05-13 14:24:19 +010022from tempest.common.utils import data_utils
Matthew Treinishb86cda92013-07-29 11:22:23 -040023from tempest import config
24from tempest import exceptions
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050025from tempest.lib import exceptions as lib_exc
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
Yaroslav Lobankov47a93ab2016-02-07 16:32:49 -060060 (self.identity_admin_client,
61 self.tenants_admin_client,
Daniel Mellado82c83a52015-12-09 15:16:49 +000062 self.users_admin_client,
Daniel Mellado7aea5342016-02-09 09:10:12 +000063 self.roles_admin_client,
Daniel Mellado91a26b62016-02-11 11:13:04 +000064 self.domains_admin_client,
Daniel Melladob04da902015-11-20 17:43:12 +010065 self.network_admin_client,
John Warren3961acd2015-10-02 14:38:53 -040066 self.networks_admin_client,
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +000067 self.routers_admin_client,
John Warren49c0fe52015-10-22 12:35:54 -040068 self.subnets_admin_client,
John Warrenf9606e92015-12-10 12:12:42 -050069 self.ports_admin_client,
70 self.security_groups_admin_client) = self._get_admin_clients()
John Warren3961acd2015-10-02 14:38:53 -040071 # Domain where isolated credentials are provisioned (v3 only).
Andrea Frittolic3280152015-02-26 12:42:34 +000072 # Use that of the admin account is None is configured.
73 self.creds_domain_name = None
74 if self.identity_version == 'v3':
75 self.creds_domain_name = (
David Kranz87fc7e92015-07-28 14:05:20 -040076 self.default_admin_creds.project_domain_name or
Andrea Frittoli (andreaf)1eb04962015-10-09 14:48:06 +010077 self.credentials_domain)
Jamie Lennox15350172015-08-17 10:54:25 +100078 self.creds_client = cred_client.get_creds_client(
Daniel Melladob04da902015-11-20 17:43:12 +010079 self.identity_admin_client,
80 self.tenants_admin_client,
Daniel Mellado82c83a52015-12-09 15:16:49 +000081 self.users_admin_client,
Daniel Mellado7aea5342016-02-09 09:10:12 +000082 self.roles_admin_client,
Daniel Mellado91a26b62016-02-11 11:13:04 +000083 self.domains_admin_client,
Daniel Melladob04da902015-11-20 17:43:12 +010084 self.creds_domain_name)
Matthew Treinishb86cda92013-07-29 11:22:23 -040085
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050086 def _get_admin_clients(self):
Ken'ichi Ohmichicb67d2d2015-11-19 08:23:22 +000087 """Returns a tuple with instances of the following admin clients
88
89 (in this order):
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050090 identity
91 network
Matthew Treinishb86cda92013-07-29 11:22:23 -040092 """
Andrea Frittolic3280152015-02-26 12:42:34 +000093 os = clients.Manager(self.default_admin_creds)
94 if self.identity_version == 'v2':
Daniel Mellado7aea5342016-02-09 09:10:12 +000095 return (os.identity_client, os.tenants_client, os.users_client,
Daniel Mellado91a26b62016-02-11 11:13:04 +000096 os.roles_client, None, os.network_client,
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +000097 os.networks_client, os.routers_client, os.subnets_client,
98 os.ports_client, os.security_groups_client)
Andrea Frittolic3280152015-02-26 12:42:34 +000099 else:
Daniel Mellado7aea5342016-02-09 09:10:12 +0000100 return (os.identity_v3_client, os.projects_client,
Arx Cruz24bcb882016-02-10 15:20:16 +0100101 os.users_v3_client, os.roles_v3_client, os.domains_client,
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +0000102 os.network_client, os.networks_client, os.routers_client,
103 os.subnets_client, os.ports_client,
104 os.security_groups_client)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400105
Matthew Treinish976e8df2014-12-19 14:21:54 -0500106 def _create_creds(self, suffix="", admin=False, roles=None):
Sean Dague6969b902014-01-28 06:48:37 -0500107 """Create random credentials under the following schema.
108
109 If the name contains a '.' is the full class path of something, and
110 we don't really care. If it isn't, it's probably a meaningful name,
111 so use it.
112
113 For logging purposes, -user and -tenant are long and redundant,
114 don't use them. The user# will be sufficient to figure it out.
115 """
116 if '.' in self.name:
117 root = ""
118 else:
119 root = self.name
120
Andrea Frittolic3280152015-02-26 12:42:34 +0000121 project_name = data_utils.rand_name(root) + suffix
122 project_desc = project_name + "-desc"
123 project = self.creds_client.create_project(
124 name=project_name, description=project_desc)
Sean Dague6969b902014-01-28 06:48:37 -0500125
126 username = data_utils.rand_name(root) + suffix
LingxianKong9c713d22015-06-09 15:19:55 +0800127 user_password = data_utils.rand_password()
Sean Dague6969b902014-01-28 06:48:37 -0500128 email = data_utils.rand_name(root) + suffix + "@example.com"
Andrea Frittolic3280152015-02-26 12:42:34 +0000129 user = self.creds_client.create_user(
LingxianKong9c713d22015-06-09 15:19:55 +0800130 username, user_password, project, email)
John Warren56317e02015-08-12 20:48:32 +0000131 if 'user' in user:
132 user = user['user']
Matthew Treinish32f98a42015-07-14 19:58:46 -0400133 role_assigned = False
Matthew Treinishb86cda92013-07-29 11:22:23 -0400134 if admin:
Andrea Frittolic3280152015-02-26 12:42:34 +0000135 self.creds_client.assign_user_role(user, project,
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +0100136 self.admin_role)
Matthew Treinish32f98a42015-07-14 19:58:46 -0400137 role_assigned = True
Matthew Treinish976e8df2014-12-19 14:21:54 -0500138 # Add roles specified in config file
139 for conf_role in CONF.auth.tempest_roles:
Andrea Frittolic3280152015-02-26 12:42:34 +0000140 self.creds_client.assign_user_role(user, project, conf_role)
Matthew Treinish32f98a42015-07-14 19:58:46 -0400141 role_assigned = True
Matthew Treinish976e8df2014-12-19 14:21:54 -0500142 # Add roles requested by caller
143 if roles:
144 for role in roles:
Andrea Frittolic3280152015-02-26 12:42:34 +0000145 self.creds_client.assign_user_role(user, project, role)
Matthew Treinish32f98a42015-07-14 19:58:46 -0400146 role_assigned = True
147 # NOTE(mtreinish) For a user to have access to a project with v3 auth
148 # it must beassigned a role on the project. So we need to ensure that
149 # our newly created user has a role on the newly created project.
150 if self.identity_version == 'v3' and not role_assigned:
151 self.creds_client.create_user_role('Member')
152 self.creds_client.assign_user_role(user, project, 'Member')
153
LingxianKong9c713d22015-06-09 15:19:55 +0800154 creds = self.creds_client.get_credentials(user, project, user_password)
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400155 return cred_provider.TestResources(creds)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500156
157 def _create_network_resources(self, tenant_id):
158 network = None
159 subnet = None
160 router = None
Matthew Treinish9f756a02014-01-15 10:26:07 -0500161 # Make sure settings
162 if self.network_resources:
163 if self.network_resources['router']:
164 if (not self.network_resources['subnet'] or
165 not self.network_resources['network']):
166 raise exceptions.InvalidConfiguration(
167 'A router requires a subnet and network')
168 elif self.network_resources['subnet']:
169 if not self.network_resources['network']:
170 raise exceptions.InvalidConfiguration(
171 'A subnet requires a network')
172 elif self.network_resources['dhcp']:
173 raise exceptions.InvalidConfiguration('DHCP requires a subnet')
174
Masayuki Igawa259c1132013-10-31 17:48:44 +0900175 data_utils.rand_name_root = data_utils.rand_name(self.name)
Matthew Treinish9f756a02014-01-15 10:26:07 -0500176 if not self.network_resources or self.network_resources['network']:
177 network_name = data_utils.rand_name_root + "-network"
178 network = self._create_network(network_name, tenant_id)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500179 try:
Matthew Treinish9f756a02014-01-15 10:26:07 -0500180 if not self.network_resources or self.network_resources['subnet']:
181 subnet_name = data_utils.rand_name_root + "-subnet"
182 subnet = self._create_subnet(subnet_name, tenant_id,
183 network['id'])
184 if not self.network_resources or self.network_resources['router']:
185 router_name = data_utils.rand_name_root + "-router"
186 router = self._create_router(router_name, tenant_id)
187 self._add_router_interface(router['id'], subnet['id'])
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500188 except Exception:
Andrea Frittoli (andreaf)d9a18b02016-02-29 15:27:34 +0000189 try:
190 if router:
191 self._clear_isolated_router(router['id'], router['name'])
192 if subnet:
193 self._clear_isolated_subnet(subnet['id'], subnet['name'])
194 if network:
195 self._clear_isolated_network(network['id'],
196 network['name'])
197 except Exception as cleanup_exception:
198 msg = "There was an exception trying to setup network " \
199 "resources for tenant %s, and this error happened " \
200 "trying to clean them up: %s"
201 LOG.warning(msg % (tenant_id, cleanup_exception))
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500202 raise
203 return network, subnet, router
204
205 def _create_network(self, name, tenant_id):
John Warren94d8faf2015-09-15 12:22:24 -0400206 resp_body = self.networks_admin_client.create_network(
Andrea Frittoliae9aca02014-09-25 11:43:11 +0100207 name=name, tenant_id=tenant_id)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500208 return resp_body['network']
209
210 def _create_subnet(self, subnet_name, tenant_id, network_id):
Sean Dague86bd8422013-12-20 09:56:44 -0500211 base_cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
212 mask_bits = CONF.network.tenant_network_mask_bits
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500213 for subnet_cidr in base_cidr.subnet(mask_bits):
214 try:
Andrea Frittoliae9aca02014-09-25 11:43:11 +0100215 if self.network_resources:
John Warren3961acd2015-10-02 14:38:53 -0400216 resp_body = self.subnets_admin_client.\
Andrea Frittoliae9aca02014-09-25 11:43:11 +0100217 create_subnet(
218 network_id=network_id, cidr=str(subnet_cidr),
219 name=subnet_name,
220 tenant_id=tenant_id,
221 enable_dhcp=self.network_resources['dhcp'],
222 ip_version=4)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500223 else:
John Warren3961acd2015-10-02 14:38:53 -0400224 resp_body = self.subnets_admin_client.\
Andrea Frittoliae9aca02014-09-25 11:43:11 +0100225 create_subnet(network_id=network_id,
226 cidr=str(subnet_cidr),
227 name=subnet_name,
228 tenant_id=tenant_id,
229 ip_version=4)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500230 break
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900231 except lib_exc.BadRequest as e:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500232 if 'overlaps with another subnet' not in str(e):
233 raise
234 else:
David Kranzd4210412014-11-21 08:37:45 -0500235 message = 'Available CIDR for subnet creation could not be found'
236 raise Exception(message)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500237 return resp_body['subnet']
238
239 def _create_router(self, router_name, tenant_id):
240 external_net_id = dict(
Sean Dague86bd8422013-12-20 09:56:44 -0500241 network_id=CONF.network.public_network_id)
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +0000242 resp_body = self.routers_admin_client.create_router(
Ken'ichi Ohmichi6665c972016-02-24 13:09:09 -0800243 name=router_name,
Andrea Frittoliae9aca02014-09-25 11:43:11 +0100244 external_gateway_info=external_net_id,
245 tenant_id=tenant_id)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500246 return resp_body['router']
247
248 def _add_router_interface(self, router_id, subnet_id):
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +0000249 self.routers_admin_client.add_router_interface(router_id,
piyush11078694aca952015-12-17 12:54:44 +0530250 subnet_id=subnet_id)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500251
Andrea Frittoli9612e812014-03-13 10:57:26 +0000252 def get_credentials(self, credential_type):
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700253 if self._creds.get(str(credential_type)):
254 credentials = self._creds[str(credential_type)]
Matthew Treinishb86cda92013-07-29 11:22:23 -0400255 else:
Matthew Treinish976e8df2014-12-19 14:21:54 -0500256 if credential_type in ['primary', 'alt', 'admin']:
257 is_admin = (credential_type == 'admin')
258 credentials = self._create_creds(admin=is_admin)
259 else:
260 credentials = self._create_creds(roles=credential_type)
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700261 self._creds[str(credential_type)] = credentials
Andrea Frittolifc315902014-03-20 09:21:44 +0000262 # Maintained until tests are ported
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700263 LOG.info("Acquired dynamic creds:\n credentials: %s"
Andrea Frittolifc315902014-03-20 09:21:44 +0000264 % credentials)
Adam Gandelman85395e72014-07-29 18:34:33 -0700265 if (CONF.service_available.neutron and
Matthew Treinish2219d382015-04-24 10:33:04 -0400266 not CONF.baremetal.driver_enabled and
267 CONF.auth.create_isolated_networks):
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500268 network, subnet, router = self._create_network_resources(
Andrea Frittolifc315902014-03-20 09:21:44 +0000269 credentials.tenant_id)
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400270 credentials.set_resources(network=network, subnet=subnet,
271 router=router)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500272 LOG.info("Created isolated network resources for : \n"
Andrea Frittolifc315902014-03-20 09:21:44 +0000273 + " credentials: %s" % credentials)
Andrea Frittoli9612e812014-03-13 10:57:26 +0000274 return credentials
Matthew Treinishb86cda92013-07-29 11:22:23 -0400275
Andrea Frittoli9612e812014-03-13 10:57:26 +0000276 def get_primary_creds(self):
277 return self.get_credentials('primary')
Matthew Treinishb86cda92013-07-29 11:22:23 -0400278
Andrea Frittoli9612e812014-03-13 10:57:26 +0000279 def get_admin_creds(self):
280 return self.get_credentials('admin')
Andrea Frittolifc315902014-03-20 09:21:44 +0000281
Andrea Frittoli9612e812014-03-13 10:57:26 +0000282 def get_alt_creds(self):
283 return self.get_credentials('alt')
Matthew Treinishb86cda92013-07-29 11:22:23 -0400284
Matthew Treinish976e8df2014-12-19 14:21:54 -0500285 def get_creds_by_roles(self, roles, force_new=False):
286 roles = list(set(roles))
287 # The roles list as a str will become the index as the dict key for
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700288 # the created credentials set in the dynamic_creds dict.
289 exist_creds = self._creds.get(str(roles))
Matthew Treinish976e8df2014-12-19 14:21:54 -0500290 # If force_new flag is True 2 cred sets with the same roles are needed
291 # handle this by creating a separate index for old one to store it
292 # separately for cleanup
293 if exist_creds and force_new:
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700294 new_index = str(roles) + '-' + str(len(self._creds))
295 self._creds[new_index] = exist_creds
296 del self._creds[str(roles)]
Matthew Treinish976e8df2014-12-19 14:21:54 -0500297 return self.get_credentials(roles)
298
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500299 def _clear_isolated_router(self, router_id, router_name):
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +0000300 client = self.routers_admin_client
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500301 try:
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +0000302 client.delete_router(router_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900303 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000304 LOG.warning('router with name: %s not found for delete' %
305 router_name)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500306
307 def _clear_isolated_subnet(self, subnet_id, subnet_name):
John Warren3961acd2015-10-02 14:38:53 -0400308 client = self.subnets_admin_client
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500309 try:
John Warren3961acd2015-10-02 14:38:53 -0400310 client.delete_subnet(subnet_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900311 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000312 LOG.warning('subnet with name: %s not found for delete' %
313 subnet_name)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500314
315 def _clear_isolated_network(self, network_id, network_name):
John Warren94d8faf2015-09-15 12:22:24 -0400316 net_client = self.networks_admin_client
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500317 try:
318 net_client.delete_network(network_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900319 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000320 LOG.warning('network with name: %s not found for delete' %
321 network_name)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500322
Ala Rezmerita846eb7c2014-03-10 09:06:03 +0100323 def _cleanup_default_secgroup(self, tenant):
John Warrenf9606e92015-12-10 12:12:42 -0500324 nsg_client = self.security_groups_admin_client
325 resp_body = nsg_client.list_security_groups(tenant_id=tenant,
David Kranz34e88122014-12-11 15:24:05 -0500326 name="default")
Ala Rezmerita846eb7c2014-03-10 09:06:03 +0100327 secgroups_to_delete = resp_body['security_groups']
328 for secgroup in secgroups_to_delete:
329 try:
John Warrenf9606e92015-12-10 12:12:42 -0500330 nsg_client.delete_security_group(secgroup['id'])
Masayuki Igawabfa07602015-01-20 18:47:17 +0900331 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000332 LOG.warning('Security group %s, id %s not found for clean-up' %
333 (secgroup['name'], secgroup['id']))
Ala Rezmerita846eb7c2014-03-10 09:06:03 +0100334
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500335 def _clear_isolated_net_resources(self):
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +0000336 client = self.routers_admin_client
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700337 for cred in self._creds:
338 creds = self._creds.get(cred)
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400339 if (not creds or not any([creds.router, creds.network,
340 creds.subnet])):
341 continue
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800342 LOG.debug("Clearing network: %(network)s, "
Matthew Treinishfe094ea2014-12-09 01:19:27 +0000343 "subnet: %(subnet)s, router: %(router)s",
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400344 {'network': creds.network, 'subnet': creds.subnet,
345 'router': creds.router})
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800346 if (not self.network_resources or
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400347 (self.network_resources.get('router') and creds.subnet)):
Matthew Treinish9f756a02014-01-15 10:26:07 -0500348 try:
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +0000349 client.remove_router_interface(
piyush11078694aca952015-12-17 12:54:44 +0530350 creds.router['id'],
351 subnet_id=creds.subnet['id'])
Masayuki Igawabfa07602015-01-20 18:47:17 +0900352 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000353 LOG.warning('router with name: %s not found for delete' %
354 creds.router['name'])
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400355 self._clear_isolated_router(creds.router['id'],
356 creds.router['name'])
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800357 if (not self.network_resources or
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800358 self.network_resources.get('subnet')):
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400359 self._clear_isolated_subnet(creds.subnet['id'],
360 creds.subnet['name'])
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800361 if (not self.network_resources or
362 self.network_resources.get('network')):
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400363 self._clear_isolated_network(creds.network['id'],
364 creds.network['name'])
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500365
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700366 def clear_creds(self):
367 if not self._creds:
Matthew Treinishb86cda92013-07-29 11:22:23 -0400368 return
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500369 self._clear_isolated_net_resources()
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700370 for creds in six.itervalues(self._creds):
Matthew Treinishb86cda92013-07-29 11:22:23 -0400371 try:
Andrea Frittolic3280152015-02-26 12:42:34 +0000372 self.creds_client.delete_user(creds.user_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900373 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000374 LOG.warning("user with name: %s not found for delete" %
375 creds.username)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400376 try:
Andrea Frittolic3280152015-02-26 12:42:34 +0000377 if CONF.service_available.neutron:
378 self._cleanup_default_secgroup(creds.tenant_id)
379 self.creds_client.delete_project(creds.tenant_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900380 except lib_exc.NotFound:
zhangguoqing6c096642016-01-04 06:17:21 +0000381 LOG.warning("tenant with name: %s not found for delete" %
382 creds.tenant_name)
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700383 self._creds = {}
Andrea Frittoli8283b4e2014-07-17 13:28:58 +0100384
385 def is_multi_user(self):
386 return True
Yair Fried76488d72014-10-21 10:13:19 +0300387
388 def is_multi_tenant(self):
389 return True
Matthew Treinish4a596932015-03-06 20:37:01 -0500390
391 def is_role_available(self, role):
392 return True