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
This commit is contained in:
Shih-Hao Li 2016-11-09 17:34:18 -08:00
parent 921ff894a3
commit 0c5a40d8b6

View File

@ -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"),