blob: c54a8e8d8b63e34d43c8e343525200e1cbd85cc9 [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
16
17import keystoneclient.v2_0.client as keystoneclient
18import neutronclient.v2_0.client as neutronclient
Matthew Treinishb86cda92013-07-29 11:22:23 -040019
20from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090021from tempest.common.utils import data_utils
Matthew Treinishb86cda92013-07-29 11:22:23 -040022from tempest import config
23from tempest import exceptions
24from tempest.openstack.common import log as logging
25
Sean Dague86bd8422013-12-20 09:56:44 -050026CONF = config.CONF
Matthew Treinishb86cda92013-07-29 11:22:23 -040027LOG = logging.getLogger(__name__)
28
29
30class IsolatedCreds(object):
31
32 def __init__(self, name, tempest_client=True, interface='json',
Matthew Treinish9f756a02014-01-15 10:26:07 -050033 password='pass', network_resources=None):
34 self.network_resources = network_resources
Matthew Treinishb86cda92013-07-29 11:22:23 -040035 self.isolated_creds = {}
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050036 self.isolated_net_resources = {}
37 self.ports = []
Matthew Treinishb86cda92013-07-29 11:22:23 -040038 self.name = name
Matthew Treinishb86cda92013-07-29 11:22:23 -040039 self.tempest_client = tempest_client
40 self.interface = interface
41 self.password = password
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050042 self.identity_admin_client, self.network_admin_client = (
43 self._get_admin_clients())
Matthew Treinishb86cda92013-07-29 11:22:23 -040044
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050045 def _get_official_admin_clients(self):
Sean Dague86bd8422013-12-20 09:56:44 -050046 username = CONF.identity.admin_username
47 password = CONF.identity.admin_password
48 tenant_name = CONF.identity.admin_tenant_name
49 auth_url = CONF.identity.uri
50 dscv = CONF.identity.disable_ssl_certificate_validation
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050051 identity_client = keystoneclient.Client(username=username,
52 password=password,
53 tenant_name=tenant_name,
54 auth_url=auth_url,
55 insecure=dscv)
56 network_client = neutronclient.Client(username=username,
57 password=password,
58 tenant_name=tenant_name,
59 auth_url=auth_url,
60 insecure=dscv)
61 return identity_client, network_client
Matthew Treinishb86cda92013-07-29 11:22:23 -040062
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050063 def _get_admin_clients(self):
Matthew Treinishb86cda92013-07-29 11:22:23 -040064 """
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050065 Returns a tuple with instances of the following admin clients (in this
66 order):
67 identity
68 network
Matthew Treinishb86cda92013-07-29 11:22:23 -040069 """
70 if self.tempest_client:
71 os = clients.AdminManager(interface=self.interface)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050072 admin_clients = (os.identity_client,
73 os.network_client,)
Matthew Treinishb86cda92013-07-29 11:22:23 -040074 else:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050075 admin_clients = self._get_official_admin_clients()
76 return admin_clients
Matthew Treinishb86cda92013-07-29 11:22:23 -040077
78 def _create_tenant(self, name, description):
79 if self.tempest_client:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050080 resp, tenant = self.identity_admin_client.create_tenant(
Matthew Treinishb86cda92013-07-29 11:22:23 -040081 name=name, description=description)
82 else:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050083 tenant = self.identity_admin_client.tenants.create(
84 name,
85 description=description)
Matthew Treinishb86cda92013-07-29 11:22:23 -040086 return tenant
87
88 def _get_tenant_by_name(self, name):
89 if self.tempest_client:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050090 resp, tenant = self.identity_admin_client.get_tenant_by_name(name)
Matthew Treinishb86cda92013-07-29 11:22:23 -040091 else:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -050092 tenants = self.identity_admin_client.tenants.list()
Matthew Treinishb86cda92013-07-29 11:22:23 -040093 for ten in tenants:
94 if ten['name'] == name:
95 tenant = ten
DennyZhang1eb40462013-09-26 14:18:30 -050096 break
97 else:
98 raise exceptions.NotFound('No such tenant')
Matthew Treinishb86cda92013-07-29 11:22:23 -040099 return tenant
100
101 def _create_user(self, username, password, tenant, email):
102 if self.tempest_client:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500103 resp, user = self.identity_admin_client.create_user(username,
104 password,
105 tenant['id'],
106 email)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400107 else:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500108 user = self.identity_admin_client.users.create(username, password,
109 email,
110 tenant_id=tenant.id)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400111 return user
112
113 def _get_user(self, tenant, username):
114 if self.tempest_client:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500115 resp, user = self.identity_admin_client.get_user_by_username(
116 tenant['id'],
117 username)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400118 else:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500119 user = self.identity_admin_client.users.get(username)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400120 return user
121
122 def _list_roles(self):
123 if self.tempest_client:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500124 resp, roles = self.identity_admin_client.list_roles()
Matthew Treinishb86cda92013-07-29 11:22:23 -0400125 else:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500126 roles = self.identity_admin_client.roles.list()
Matthew Treinishb86cda92013-07-29 11:22:23 -0400127 return roles
128
129 def _assign_user_role(self, tenant, user, role):
130 if self.tempest_client:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500131 self.identity_admin_client.assign_user_role(tenant, user, role)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400132 else:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500133 self.identity_admin_client.roles.add_user_role(user,
134 role, tenant=tenant)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400135
136 def _delete_user(self, user):
137 if self.tempest_client:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500138 self.identity_admin_client.delete_user(user)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400139 else:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500140 self.identity_admin_client.users.delete(user)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400141
142 def _delete_tenant(self, tenant):
143 if self.tempest_client:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500144 self.identity_admin_client.delete_tenant(tenant)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400145 else:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500146 self.identity_admin_client.tenants.delete(tenant)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400147
Sean Dague6969b902014-01-28 06:48:37 -0500148 def _create_creds(self, suffix="", admin=False):
149 """Create random credentials under the following schema.
150
151 If the name contains a '.' is the full class path of something, and
152 we don't really care. If it isn't, it's probably a meaningful name,
153 so use it.
154
155 For logging purposes, -user and -tenant are long and redundant,
156 don't use them. The user# will be sufficient to figure it out.
157 """
158 if '.' in self.name:
159 root = ""
160 else:
161 root = self.name
162
163 tenant_name = data_utils.rand_name(root) + suffix
Matthew Treinishb86cda92013-07-29 11:22:23 -0400164 tenant_desc = tenant_name + "-desc"
Matthew Treinishb86cda92013-07-29 11:22:23 -0400165 tenant = self._create_tenant(name=tenant_name,
166 description=tenant_desc)
Sean Dague6969b902014-01-28 06:48:37 -0500167
168 username = data_utils.rand_name(root) + suffix
169 email = data_utils.rand_name(root) + suffix + "@example.com"
Matthew Treinishb86cda92013-07-29 11:22:23 -0400170 user = self._create_user(username, self.password,
171 tenant, email)
172 if admin:
173 role = None
174 try:
175 roles = self._list_roles()
Sean Dague86bd8422013-12-20 09:56:44 -0500176 admin_role = CONF.identity.admin_role
Matthew Treinishb86cda92013-07-29 11:22:23 -0400177 if self.tempest_client:
Russell Sim7f894a52013-09-13 10:35:21 +1000178 role = next(r for r in roles if r['name'] == admin_role)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400179 else:
Russell Sim7f894a52013-09-13 10:35:21 +1000180 role = next(r for r in roles if r.name == admin_role)
Matthew Treinishb86cda92013-07-29 11:22:23 -0400181 except StopIteration:
182 msg = "No admin role found"
183 raise exceptions.NotFound(msg)
184 if self.tempest_client:
185 self._assign_user_role(tenant['id'], user['id'], role['id'])
186 else:
187 self._assign_user_role(tenant.id, user.id, role.id)
188 return user, tenant
189
190 def _get_cred_names(self, user, tenant):
191 if self.tempest_client:
192 username = user.get('name')
193 tenant_name = tenant.get('name')
194 else:
195 username = user.name
196 tenant_name = tenant.name
197 return username, tenant_name
198
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500199 def _get_tenant_id(self, tenant):
200 if self.tempest_client:
201 return tenant.get('id')
202 else:
203 return tenant.id
204
205 def _create_network_resources(self, tenant_id):
206 network = None
207 subnet = None
208 router = None
Matthew Treinish9f756a02014-01-15 10:26:07 -0500209 # Make sure settings
210 if self.network_resources:
211 if self.network_resources['router']:
212 if (not self.network_resources['subnet'] or
213 not self.network_resources['network']):
214 raise exceptions.InvalidConfiguration(
215 'A router requires a subnet and network')
216 elif self.network_resources['subnet']:
217 if not self.network_resources['network']:
218 raise exceptions.InvalidConfiguration(
219 'A subnet requires a network')
220 elif self.network_resources['dhcp']:
221 raise exceptions.InvalidConfiguration('DHCP requires a subnet')
222
Masayuki Igawa259c1132013-10-31 17:48:44 +0900223 data_utils.rand_name_root = data_utils.rand_name(self.name)
Matthew Treinish9f756a02014-01-15 10:26:07 -0500224 if not self.network_resources or self.network_resources['network']:
225 network_name = data_utils.rand_name_root + "-network"
226 network = self._create_network(network_name, tenant_id)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500227 try:
Matthew Treinish9f756a02014-01-15 10:26:07 -0500228 if not self.network_resources or self.network_resources['subnet']:
229 subnet_name = data_utils.rand_name_root + "-subnet"
230 subnet = self._create_subnet(subnet_name, tenant_id,
231 network['id'])
232 if not self.network_resources or self.network_resources['router']:
233 router_name = data_utils.rand_name_root + "-router"
234 router = self._create_router(router_name, tenant_id)
235 self._add_router_interface(router['id'], subnet['id'])
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500236 except Exception:
237 if router:
238 self._clear_isolated_router(router['id'], router['name'])
239 if subnet:
240 self._clear_isolated_subnet(subnet['id'], subnet['name'])
241 if network:
242 self._clear_isolated_network(network['id'], network['name'])
243 raise
244 return network, subnet, router
245
246 def _create_network(self, name, tenant_id):
247 if self.tempest_client:
248 resp, resp_body = self.network_admin_client.create_network(
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400249 name=name, tenant_id=tenant_id)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500250 else:
251 body = {'network': {'tenant_id': tenant_id, 'name': name}}
252 resp_body = self.network_admin_client.create_network(body)
253 return resp_body['network']
254
255 def _create_subnet(self, subnet_name, tenant_id, network_id):
256 if not self.tempest_client:
257 body = {'subnet': {'name': subnet_name, 'tenant_id': tenant_id,
258 'network_id': network_id, 'ip_version': 4}}
Matthew Treinish9f756a02014-01-15 10:26:07 -0500259 if self.network_resources:
260 body['enable_dhcp'] = self.network_resources['dhcp']
Sean Dague86bd8422013-12-20 09:56:44 -0500261 base_cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
262 mask_bits = CONF.network.tenant_network_mask_bits
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500263 for subnet_cidr in base_cidr.subnet(mask_bits):
264 try:
265 if self.tempest_client:
Matthew Treinish9f756a02014-01-15 10:26:07 -0500266 if self.network_resources:
267 resp, resp_body = self.network_admin_client.\
268 create_subnet(
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400269 network_id=network_id, cidr=str(subnet_cidr),
Matthew Treinish9f756a02014-01-15 10:26:07 -0500270 name=subnet_name,
271 tenant_id=tenant_id,
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400272 enable_dhcp=self.network_resources['dhcp'],
273 ip_version=4)
Matthew Treinish9f756a02014-01-15 10:26:07 -0500274 else:
275 resp, resp_body = self.network_admin_client.\
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400276 create_subnet(network_id=network_id,
277 cidr=str(subnet_cidr),
Matthew Treinish9f756a02014-01-15 10:26:07 -0500278 name=subnet_name,
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400279 tenant_id=tenant_id,
280 ip_version=4)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500281 else:
282 body['subnet']['cidr'] = str(subnet_cidr)
283 resp_body = self.network_admin_client.create_subnet(body)
284 break
285 except exceptions.BadRequest as e:
286 if 'overlaps with another subnet' not in str(e):
287 raise
288 else:
289 e = exceptions.BuildErrorException()
290 e.message = 'Available CIDR for subnet creation could not be found'
291 raise e
292 return resp_body['subnet']
293
294 def _create_router(self, router_name, tenant_id):
295 external_net_id = dict(
Sean Dague86bd8422013-12-20 09:56:44 -0500296 network_id=CONF.network.public_network_id)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500297 if self.tempest_client:
298 resp, resp_body = self.network_admin_client.create_router(
299 router_name,
300 external_gateway_info=external_net_id,
301 tenant_id=tenant_id)
302 else:
303 body = {'router': {'name': router_name, 'tenant_id': tenant_id,
304 'external_gateway_info': external_net_id,
305 'admin_state_up': True}}
306 resp_body = self.network_admin_client.create_router(body)
307 return resp_body['router']
308
309 def _add_router_interface(self, router_id, subnet_id):
310 if self.tempest_client:
311 self.network_admin_client.add_router_interface_with_subnet_id(
312 router_id, subnet_id)
313 else:
314 body = {'subnet_id': subnet_id}
315 self.network_admin_client.add_interface_router(router_id, body)
316
Matthew Treinishb86cda92013-07-29 11:22:23 -0400317 def get_primary_tenant(self):
318 return self.isolated_creds.get('primary')[1]
319
320 def get_primary_user(self):
321 return self.isolated_creds.get('primary')[0]
322
323 def get_alt_tenant(self):
324 return self.isolated_creds.get('alt')[1]
325
326 def get_alt_user(self):
327 return self.isolated_creds.get('alt')[0]
328
329 def get_admin_tenant(self):
330 return self.isolated_creds.get('admin')[1]
331
332 def get_admin_user(self):
333 return self.isolated_creds.get('admin')[0]
334
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500335 def get_primary_network(self):
336 return self.isolated_net_resources.get('primary')[0]
337
338 def get_primary_subnet(self):
339 return self.isolated_net_resources.get('primary')[1]
340
341 def get_primary_router(self):
342 return self.isolated_net_resources.get('primary')[2]
343
344 def get_admin_network(self):
345 return self.isolated_net_resources.get('admin')[0]
346
347 def get_admin_subnet(self):
348 return self.isolated_net_resources.get('admin')[1]
349
350 def get_admin_router(self):
351 return self.isolated_net_resources.get('admin')[2]
352
353 def get_alt_network(self):
354 return self.isolated_net_resources.get('alt')[0]
355
356 def get_alt_subnet(self):
357 return self.isolated_net_resources.get('alt')[1]
358
359 def get_alt_router(self):
360 return self.isolated_net_resources.get('alt')[2]
361
Matthew Treinishb86cda92013-07-29 11:22:23 -0400362 def get_primary_creds(self):
363 if self.isolated_creds.get('primary'):
364 user, tenant = self.isolated_creds['primary']
365 username, tenant_name = self._get_cred_names(user, tenant)
366 else:
367 user, tenant = self._create_creds()
368 username, tenant_name = self._get_cred_names(user, tenant)
369 self.isolated_creds['primary'] = (user, tenant)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500370 LOG.info("Acquired isolated creds:\n user: %s, tenant: %s"
Matthew Treinishb86cda92013-07-29 11:22:23 -0400371 % (username, tenant_name))
Sean Dague86bd8422013-12-20 09:56:44 -0500372 if CONF.service_available.neutron:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500373 network, subnet, router = self._create_network_resources(
374 self._get_tenant_id(tenant))
375 self.isolated_net_resources['primary'] = (
376 network, subnet, router,)
377 LOG.info("Created isolated network resources for : \n"
378 + " user: %s, tenant: %s" % (username, tenant_name))
Matthew Treinishb86cda92013-07-29 11:22:23 -0400379 return username, tenant_name, self.password
380
381 def get_admin_creds(self):
382 if self.isolated_creds.get('admin'):
383 user, tenant = self.isolated_creds['admin']
384 username, tenant_name = self._get_cred_names(user, tenant)
385 else:
386 user, tenant = self._create_creds(admin=True)
387 username, tenant_name = self._get_cred_names(user, tenant)
388 self.isolated_creds['admin'] = (user, tenant)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500389 LOG.info("Acquired admin isolated creds:\n user: %s, tenant: %s"
Matthew Treinishb86cda92013-07-29 11:22:23 -0400390 % (username, tenant_name))
Sean Dague86bd8422013-12-20 09:56:44 -0500391 if CONF.service_available.neutron:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500392 network, subnet, router = self._create_network_resources(
393 self._get_tenant_id(tenant))
394 self.isolated_net_resources['admin'] = (
395 network, subnet, router,)
396 LOG.info("Created isolated network resources for : \n"
397 + " user: %s, tenant: %s" % (username, tenant_name))
398 return username, tenant_name, self.password
Matthew Treinishb86cda92013-07-29 11:22:23 -0400399
400 def get_alt_creds(self):
401 if self.isolated_creds.get('alt'):
402 user, tenant = self.isolated_creds['alt']
403 username, tenant_name = self._get_cred_names(user, tenant)
404 else:
405 user, tenant = self._create_creds()
406 username, tenant_name = self._get_cred_names(user, tenant)
407 self.isolated_creds['alt'] = (user, tenant)
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500408 LOG.info("Acquired alt isolated creds:\n user: %s, tenant: %s"
Matthew Treinishb86cda92013-07-29 11:22:23 -0400409 % (username, tenant_name))
Sean Dague86bd8422013-12-20 09:56:44 -0500410 if CONF.service_available.neutron:
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500411 network, subnet, router = self._create_network_resources(
412 self._get_tenant_id(tenant))
413 self.isolated_net_resources['alt'] = (
414 network, subnet, router,)
415 LOG.info("Created isolated network resources for : \n"
416 + " user: %s, tenant: %s" % (username, tenant_name))
Matthew Treinishb86cda92013-07-29 11:22:23 -0400417 return username, tenant_name, self.password
418
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500419 def _clear_isolated_router(self, router_id, router_name):
420 net_client = self.network_admin_client
421 try:
422 net_client.delete_router(router_id)
423 except exceptions.NotFound:
424 LOG.warn('router with name: %s not found for delete' %
425 router_name)
426 pass
427
428 def _clear_isolated_subnet(self, subnet_id, subnet_name):
429 net_client = self.network_admin_client
430 try:
431 net_client.delete_subnet(subnet_id)
432 except exceptions.NotFound:
433 LOG.warn('subnet with name: %s not found for delete' %
434 subnet_name)
435 pass
436
437 def _clear_isolated_network(self, network_id, network_name):
438 net_client = self.network_admin_client
439 try:
440 net_client.delete_network(network_id)
441 except exceptions.NotFound:
442 LOG.warn('network with name: %s not found for delete' %
443 network_name)
444 pass
445
446 def _cleanup_ports(self, network_id):
447 # TODO(mlavalle) This method will be removed once patch
448 # https://review.openstack.org/#/c/46563/ merges in Neutron
449 if not self.ports:
450 if self.tempest_client:
451 resp, resp_body = self.network_admin_client.list_ports()
452 else:
453 resp_body = self.network_admin_client.list_ports()
454 self.ports = resp_body['ports']
455 ports_to_delete = [
armando-migliaccio96a86ae2013-11-21 17:26:16 -0800456 port
457 for port in self.ports
458 if (port['network_id'] == network_id and
shihanzhangc3d73c82014-02-18 10:27:02 +0800459 port['device_owner'] != 'network:router_interface' and
460 port['device_owner'] != 'network:dhcp')
armando-migliaccio96a86ae2013-11-21 17:26:16 -0800461 ]
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500462 for port in ports_to_delete:
463 try:
464 LOG.info('Cleaning up port id %s, name %s' %
465 (port['id'], port['name']))
466 self.network_admin_client.delete_port(port['id'])
467 except exceptions.NotFound:
468 LOG.warn('Port id: %s, name %s not found for clean-up' %
469 (port['id'], port['name']))
470
471 def _clear_isolated_net_resources(self):
472 net_client = self.network_admin_client
473 for cred in self.isolated_net_resources:
474 network, subnet, router = self.isolated_net_resources.get(cred)
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800475 LOG.debug("Clearing network: %(network)s, "
476 "subnet: %(subnet)s, router: %(router)s",
477 {'network': network, 'subnet': subnet, 'router': router})
478 if (not self.network_resources or
479 self.network_resources.get('router')):
Matthew Treinish9f756a02014-01-15 10:26:07 -0500480 try:
481 if self.tempest_client:
482 net_client.remove_router_interface_with_subnet_id(
483 router['id'], subnet['id'])
484 else:
485 body = {'subnet_id': subnet['id']}
486 net_client.remove_interface_router(router['id'], body)
487 except exceptions.NotFound:
488 LOG.warn('router with name: %s not found for delete' %
489 router['name'])
490 pass
491 self._clear_isolated_router(router['id'], router['name'])
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800492 if (not self.network_resources or
493 self.network_resources.get('network')):
Matthew Treinish9f756a02014-01-15 10:26:07 -0500494 # TODO(mlavalle) This method call will be removed once patch
495 # https://review.openstack.org/#/c/46563/ merges in Neutron
496 self._cleanup_ports(network['id'])
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800497 if (not self.network_resources or
498 self.network_resources.get('subnet')):
Matthew Treinish9f756a02014-01-15 10:26:07 -0500499 self._clear_isolated_subnet(subnet['id'], subnet['name'])
Salvatore Orlandocf996c62014-01-30 09:15:18 -0800500 if (not self.network_resources or
501 self.network_resources.get('network')):
Matthew Treinish9f756a02014-01-15 10:26:07 -0500502 self._clear_isolated_network(network['id'], network['name'])
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500503
Matthew Treinishb86cda92013-07-29 11:22:23 -0400504 def clear_isolated_creds(self):
505 if not self.isolated_creds:
506 return
Miguel Lavalleb8fabc52013-08-23 11:19:57 -0500507 self._clear_isolated_net_resources()
Matthew Treinishb86cda92013-07-29 11:22:23 -0400508 for cred in self.isolated_creds:
509 user, tenant = self.isolated_creds.get(cred)
510 try:
511 if self.tempest_client:
512 self._delete_user(user['id'])
513 else:
514 self._delete_user(user.id)
515 except exceptions.NotFound:
516 if self.tempest_client:
517 name = user['name']
518 else:
519 name = user.name
520 LOG.warn("user with name: %s not found for delete" % name)
521 pass
522 try:
523 if self.tempest_client:
524 self._delete_tenant(tenant['id'])
525 else:
526 self._delete_tenant(tenant.id)
527 except exceptions.NotFound:
528 if self.tempest_client:
529 name = tenant['name']
530 else:
531 name = tenant.name
532 LOG.warn("tenant with name: %s not found for delete" % name)
533 pass