From 77d75885532fcf72c5610278fd4b8cab842a1f91 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Thu, 30 Jul 2015 03:26:40 -0700 Subject: [PATCH] Prevent failures on router delete If a logical router has been removed from the backend, and the DB is an inconsistent state where no NSX mapping is stored for the neutron logical router, the backend will fail when attempting deletion of the router, causing the neutron operation to return a 500. This patch ensures the neutron operation completes successfully, thus reconciling Neutron's DB with the NSX backend. Change-Id: Ieb86faa9a71317fe82da4ea2f473164d01a36910 --- .../neutron/plugins/vmware/plugins/base.py | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/vmware_nsx/neutron/plugins/vmware/plugins/base.py b/vmware_nsx/neutron/plugins/vmware/plugins/base.py index 1bebd05ff7..d188d8df55 100644 --- a/vmware_nsx/neutron/plugins/vmware/plugins/base.py +++ b/vmware_nsx/neutron/plugins/vmware/plugins/base.py @@ -1595,16 +1595,25 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin, context.session, self.cluster, router_id) # It is safe to remove the router from the database, so remove it # from the backend - try: - self._delete_lrouter(context, router_id, nsx_router_id) - except n_exc.NotFound: - # This is not a fatal error, but needs to be logged - LOG.warning(_LW("Logical router '%s' not found " + if nsx_router_id: + try: + self._delete_lrouter(context, router_id, nsx_router_id) + except n_exc.NotFound: + # This is not a fatal error, but needs to be logged + LOG.warning(_LW("Logical router '%s' not found " + "on NSX Platform"), router_id) + except api_exc.NsxApiException: + raise nsx_exc.NsxPluginException( + err_msg=(_("Unable to delete logical router '%s' " + "on NSX Platform") % nsx_router_id)) + else: + # If no mapping is found it is likely that the logical router does + # not exist anymore in the backend. This is not a fatal condition, + # but will result in an exception is "None" is passed to + # _delete_lrouter + LOG.warning(_LW("No mapping found for logical router '%s' " "on NSX Platform"), router_id) - except api_exc.NsxApiException: - raise nsx_exc.NsxPluginException( - err_msg=(_("Unable to delete logical router '%s' " - "on NSX Platform") % nsx_router_id)) + # Remove the NSX mapping first in order to ensure a mapping to # a non-existent NSX router is not left in the DB in case of # failure while removing the router from the neutron DB