AdminUtils: Fix NSX-V dhcp-edge recreate

The admin utility:
nsxadmin -r dhcp-binding -o nsx-recreate --property edge-id=edge-18

did not delete all the router_bindings entries in case of multiple
networks on the same edge.
This caused error messaged, and DuplicateEntries error in the sql code.

Change-Id: I8c8486a77762bba9cf8c1b83c06ed938ec177418
This commit is contained in:
Adit Sarfaty 2017-04-26 15:20:41 +03:00
parent 8548f110ac
commit 747a4d28a5

View File

@ -130,12 +130,8 @@ def nsx_update_dhcp_edge_binding(resource, event, trigger, **kwargs):
def delete_old_dhcp_edge(context, old_edge_id, bindings):
LOG.info("Deleting the old DHCP edge: %s", old_edge_id)
# using one of the router-ids in the bindings for the deleting
dhcp_names = [binding['router_id'] for binding in bindings]
dhcp_name = dhcp_names[0]
with locking.LockManager.get_lock(old_edge_id):
# Delete from NSXv backend
# (using the first dhcp name as the "router name")
# Note - If we will not delete the router, but free it - it will be
# immediately used as the new one, So it is better to delete it.
try:
@ -148,7 +144,7 @@ def delete_old_dhcp_edge(context, old_edge_id, bindings):
try:
# Remove bindings from Neutron DB
nsxv_db.delete_nsxv_router_binding(context.session, dhcp_name)
nsxv_db.clean_edge_router_binding(context.session, old_edge_id)
nsxv_db.clean_edge_vnic_binding(context.session, old_edge_id)
except Exception as e:
LOG.warning("Failed to delete the old edge %(id)s from the "