diff --git a/vmware_nsx/plugins/nsx_v/drivers/distributed_router_driver.py b/vmware_nsx/plugins/nsx_v/drivers/distributed_router_driver.py index c2cebe6b3d..924f479102 100644 --- a/vmware_nsx/plugins/nsx_v/drivers/distributed_router_driver.py +++ b/vmware_nsx/plugins/nsx_v/drivers/distributed_router_driver.py @@ -20,7 +20,7 @@ from neutron.db import l3_db from neutron_lib import constants from neutron_lib import exceptions as n_exc -from vmware_nsx._i18n import _, _LE +from vmware_nsx._i18n import _LE, _LW from vmware_nsx.common import locking from vmware_nsx.db import nsxv_db from vmware_nsx.plugins.nsx_v.drivers import ( @@ -125,6 +125,12 @@ class RouterDistributedDriver(router_driver.RouterBaseDriver): def delete_router(self, context, router_id): self.edge_manager.delete_lrouter(context, router_id, dist=True) + # This should address cases where the binding remains due to breakage + if nsxv_db.get_vdr_dhcp_binding_by_vdr(context.session, router_id): + LOG.warning(_LW("DHCP bind wasn't cleaned for router %s. " + "Cleaning up entry"), router_id) + nsxv_db.delete_vdr_dhcp_binding(context.session, router_id) + def update_routes(self, context, router_id, newnexthop, metadata_gateway=None): with locking.LockManager.get_lock(self._get_edge_id(context, diff --git a/vmware_nsx/plugins/nsx_v/vshield/edge_utils.py b/vmware_nsx/plugins/nsx_v/vshield/edge_utils.py index a7603ec6f6..b54c11e316 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/edge_utils.py +++ b/vmware_nsx/plugins/nsx_v/vshield/edge_utils.py @@ -22,6 +22,7 @@ from sqlalchemy import exc as db_base_exc import time from oslo_config import cfg +from oslo_db import exception as db_exc from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import excutils @@ -1235,8 +1236,16 @@ class EdgeManager(object): dhcp_edge_id, [RP_FILTER_PROPERTY_OFF_TEMPLATE % ('all', '0')]) - nsxv_db.add_vdr_dhcp_binding(context.session, vdr_router_id, - dhcp_edge_id) + try: + nsxv_db.add_vdr_dhcp_binding(context.session, vdr_router_id, + dhcp_edge_id) + except db_exc.DBDuplicateEntry: + # Could have garbage binding in the DB - warn and overwrite + LOG.warning(_LW('Conflict found in VDR DHCP bindings - %s ' + 'was already bound'), dhcp_edge_id) + nsxv_db.delete_vdr_dhcp_binding(context.session, vdr_router_id) + nsxv_db.add_vdr_dhcp_binding(context.session, vdr_router_id, + dhcp_edge_id) address_groups = self.plugin._create_network_dhcp_address_group( context, network_id)