From 09bfb99bb2f32bf497cd61c5b30c512528477f25 Mon Sep 17 00:00:00 2001 From: asarfaty Date: Mon, 15 Jun 2020 16:31:24 +0200 Subject: [PATCH] Catch nsgroup deletion exceptions and log Commit I475a5c984aed7b6cae26951e64971ec463a43c5e changed the error handling of this api, so the plugin will need to handle the errors Change-Id: I1ba3d0a64793674c97c62f6ff26fa00e34a7c4fe (cherry picked from commit 4a0b872d7756a2099bf253fc5ab660c4fdeb55ce) --- vmware_nsx/plugins/nsx_v3/plugin.py | 18 +++++++++++++++--- .../plugins/nsxv3/resources/securitygroups.py | 8 +++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index 54480fb1fa..4f2974d922 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -329,7 +329,12 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base, if section_id: self.nsxlib.firewall_section.delete(section_id) if ns_group_id: - self.nsxlib.ns_group.delete(ns_group_id) + try: + self.nsxlib.ns_group.delete(ns_group_id) + except Exception: + LOG.debug("While cleaning up duplicate sections NSGroup %s " + "was not found", ns_group_id) + # Ensure global variables are updated self._ensure_default_rules() @@ -3044,7 +3049,10 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base, context = context.elevated() super(NsxV3Plugin, self).delete_security_group( context, secgroup_db['id']) - self.nsxlib.ns_group.delete(ns_group['id']) + try: + self.nsxlib.ns_group.delete(ns_group['id']) + except Exception: + pass self.nsxlib.firewall_section.delete(firewall_section['id']) if ex.__class__ is nsx_lib_exc.ResourceNotFound: @@ -3106,7 +3114,11 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base, context.session, id) super(NsxV3Plugin, self).delete_security_group(context, id) self.nsxlib.firewall_section.delete(section_id) - self.nsxlib.ns_group.delete(nsgroup_id) + try: + self.nsxlib.ns_group.delete(nsgroup_id) + except Exception: + LOG.debug("While deleting SG %s NSGroup %s was not found", + id, nsgroup_id) def create_security_group_rule(self, context, security_group_rule): bulk_rule = {'security_group_rules': [security_group_rule]} diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/securitygroups.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/securitygroups.py index c33bf8ca33..0d0fa33bad 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/securitygroups.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/securitygroups.py @@ -220,7 +220,13 @@ def fix_security_groups(resource, event, trigger, **kwargs): nsxlib.firewall_section.delete(sg['section-id']) except Exception: pass - nsxlib.ns_group.delete(sg['nsx-securitygroup-id']) + + try: + nsxlib.ns_group.delete(sg['nsx-securitygroup-id']) + except Exception: + LOG.debug("NSGroup %s does not exists for delete request.", + sg['nsx-securitygroup-id']) + neutron_sg.delete_security_group_section_mapping(sg_id) neutron_sg.delete_security_group_backend_mapping(sg_id) nsgroup, fw_section = (