NSX|V3: ensure that devstack cleanup delets switches

Commit 3d24d19309 resulted in
networks not being deleted. This is due to the fact that some
ports on a network may not be stored in the DB. For example
a metadata port.

Change-Id: I192b5b85d99e08989bd68ebef73e592d398edbd4
This commit is contained in:
Gary Kotton 2017-06-27 00:01:31 -07:00
parent 805366ebe7
commit de196f9dc6
1 changed files with 22 additions and 9 deletions

View File

@ -229,15 +229,10 @@ class NSXClient(object):
if response.status_code != requests.codes.ok:
print("ERROR: Failed to update lport %s" % p['id'])
def cleanup_os_logical_ports(self):
"""
Delete all logical ports created by OpenStack
"""
os_lports = self.get_os_logical_ports()
print("Number of OS Logical Ports to be deleted: %s" % len(os_lports))
def _cleanup_logical_ports(self, lports):
# logical port vif detachment
self.update_logical_port_attachment(os_lports)
for p in os_lports:
self.update_logical_port_attachment(lports)
for p in lports:
endpoint = '/logical-ports/%s' % p['id']
response = self.delete(endpoint=endpoint)
if response.status_code == requests.codes.ok:
@ -246,6 +241,14 @@ class NSXClient(object):
print("ERROR: Failed to delete lport %s, response code %s" %
(p['id'], response.status_code))
def cleanup_os_logical_ports(self):
"""
Delete all logical ports created by OpenStack
"""
os_lports = self.get_os_logical_ports()
print("Number of OS Logical Ports to be deleted: %s" % len(os_lports))
self._cleanup_logical_ports(os_lports)
def get_os_resources(self, resources):
"""
Get all logical resources created by OpenStack
@ -279,7 +282,7 @@ class NSXClient(object):
Return all the logical ports that belong to this lswitch
"""
lports = self.get_logical_ports()
return [p for p in lports if p['logical_switch_id'] is ls_id]
return [p for p in lports if p['logical_switch_id'] == ls_id]
def cleanup_os_logical_switches(self):
"""
@ -289,6 +292,16 @@ class NSXClient(object):
print("Number of OS Logical Switches to be deleted: %s" %
len(lswitches))
for ls in lswitches:
# Check if there are still ports on switch and blow them away
# An example here is a metadata proxy port (this is not stored
# in the DB so we are unable to delete it when reading ports
# from the DB)
lports = self.get_lswitch_ports(ls['id'])
if lports:
print("Number of orphan OS Logical Ports to be "
"deleted: %s" % len(lports))
self._cleanup_logical_ports(lports)
endpoint = '/logical-switches/%s' % ls['id']
response = self.delete(endpoint=endpoint)
if response.status_code == requests.codes.ok: