From 95f05a20979d63a77a2292cca2dd0e5954ebf5d1 Mon Sep 17 00:00:00 2001 From: asarfaty Date: Thu, 19 Dec 2019 14:31:26 +0200 Subject: [PATCH] NSX|V3: Fix devstack cleanup for tier0 ports In case using the cleantup with a newutron_db, tier0 logical ports were not deleted, becasue the tier0 routers could not be found in the neutron DB. Change-Id: I78e6641f2d94331a081bae218a99bbc2973f2540 --- devstack/tools/nsxv3_cleanup.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/devstack/tools/nsxv3_cleanup.py b/devstack/tools/nsxv3_cleanup.py index aeefef353f..6e56d0a85a 100755 --- a/devstack/tools/nsxv3_cleanup.py +++ b/devstack/tools/nsxv3_cleanup.py @@ -312,20 +312,32 @@ class NSXClient(object): Retrieve all the logical routers based on router type. If tier is None, it will return all logical routers. """ - lrouters = self.nsxlib.logical_router.list( + return self.nsxlib.logical_router.list( router_type=tier)['results'] + def get_tier1_logical_routers(self): + """ + Retrieve all tier1 logical routers, and return only neutron ones. + """ + lrouters = self.get_logical_routers(tier='TIER1') + if self.neutron_db: db_routers = self.neutron_db.get_logical_routers() lrouters = [lr for lr in lrouters if lr['id'] in db_routers] return lrouters + def get_tier0_logical_routers(self): + """ + Retrieve all tier0 logical routers. + """ + return self.get_logical_routers(tier='TIER0') + def get_os_logical_routers(self): """ Retrieve all logical routers created from Neutron NSXv3 plugin """ - lrouters = self.get_logical_routers() + lrouters = self.get_tier1_logical_routers() return self.get_os_resources(lrouters) def get_logical_router_ports(self, lrouter): @@ -382,7 +394,9 @@ class NSXClient(object): """ Delete all TIER0 logical router ports created from OpenStack """ - tier0_routers = self.get_logical_routers(tier='TIER0') + tier0_routers = self.get_tier0_logical_routers() + print("Number of TIER0 Logical Routers whos ports will be deleted: " + "%s" % len(tier0_routers)) for lr in tier0_routers: self.cleanup_logical_router_ports(lr)