From 0c5a40d8b6146cdd616e0c30eef2d28d3ce5d3f4 Mon Sep 17 00:00:00 2001 From: Shih-Hao Li Date: Wed, 9 Nov 2016 17:34:18 -0800 Subject: [PATCH] NSXv3: Add error handling for SQL timeout case After the plugin added a DHCP static binding for a new neutron port in NSX backend, if it failed to store the binding info in neutron DB due to SQL timeout, neutron will delete this port. In this case, the backend entry is still there. So the plugin need to catch the timeout exception and clean the backend entry. Change-Id: I4ec93792bce67739dc73aa8a309d4291a54a8b64 --- vmware_nsx/plugins/nsx_v3/plugin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index 3c93f4e393..b45f05830b 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -68,6 +68,7 @@ from oslo_log import log from oslo_utils import excutils from oslo_utils import importutils from oslo_utils import uuidutils +from sqlalchemy import exc as sql_exc from vmware_nsx._i18n import _, _LE, _LI, _LW from vmware_nsx.api_replay import utils as api_replay_utils @@ -982,7 +983,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, nsx_db.add_neutron_nsx_service_binding( context.session, network['id'], neutron_port['id'], nsxlib_consts.SERVICE_DHCP, dhcp_server['id']) - except db_exc.DBError: + except (db_exc.DBError, sql_exc.TimeoutError): with excutils.save_and_reraise_exception(): LOG.error(_LE("Failed to create mapping for DHCP port %s," "deleting port and logical DHCP server"), @@ -1586,7 +1587,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, context.session, port['id'], fixed_ip['subnet_id'], fixed_ip['ip_address'], dhcp_service['nsx_service_id'], binding['id']) - except db_exc.DBError: + except (db_exc.DBError, sql_exc.TimeoutError): LOG.error(_LE("Failed to add mapping of DHCP binding " "%(binding)s for port %(port)s, deleting" "DHCP binding on server"),