From 99638abd8fd536081bcec19f3ff2e619bbcffc0f Mon Sep 17 00:00:00 2001 From: Shih-Hao Li Date: Tue, 23 Aug 2016 12:43:51 -0700 Subject: [PATCH] NSX|V3: Add codes to handle corner cases in native DHCP support 1. delete_network failed because native DHCP port was manually deleted 2. create_subnet was rolled back, but old entries still exist in backend Change-Id: I9e28438ff5a7eab9489a921d834eab8a65044aa4 --- vmware_nsx/plugins/nsx_v3/plugin.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index ff1b1e8bad..32a0849536 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -897,6 +897,12 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, # LogicalDhcpServer on the backend. Then create the corresponding # logical port for the Neutron port with DHCP attachment as the # LogicalDhcpServer UUID. + + # Delete obsolete settings if exist. This could happen when a + # previous failed transaction was rolled back. But the backend + # entries are still there. + self._disable_native_dhcp(context, network['id']) + port_data = { "name": "", "admin_state_up": True, @@ -964,9 +970,16 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, return if dhcp_service['port_id']: - self.delete_port(context, dhcp_service['port_id']) + try: + self.delete_port(context, dhcp_service['port_id']) + except Exception: + # This could happen when the port has been manually deleted. + LOG.error(_LE("Failed to delete DHCP port %(port)s for " + "network %(network)s"), + {'port': dhcp_service['port_id'], + 'network': network_id}) else: - LOG.error(_LE("Unable to find DHCP port for network %s"), + LOG.error(_LE("DHCP port is not configured for network %s"), network_id) try: