From 33b1fff622b1bd0c4716bf048e1621ca2984a853 Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Tue, 7 Jun 2016 15:22:23 +0300 Subject: [PATCH] Rename edge appliance before its deletion Current flow is: - update edge router binding to pending-delete - Delete in background task When we detach a last network from DHCP edge, and then reattach it immediately to a new DHCP edge, we have a case where deletion is still done in the background while we attempt to insert a new entry to nsxv_router_bindings for the new one. That causes a duplicate in nsxv_router_bindings as the new edge has the same name (dhcp-) as the old one. This change should address this issue. Change-Id: I9ea79b166b3c7cbccd2c1f52714bb7a3859f77da --- .../plugins/nsx_v/vshield/edge_utils.py | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v/vshield/edge_utils.py b/vmware_nsx/plugins/nsx_v/vshield/edge_utils.py index beb3282a20..a71c3b1257 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/edge_utils.py +++ b/vmware_nsx/plugins/nsx_v/vshield/edge_utils.py @@ -675,6 +675,22 @@ class EdgeManager(object): res_pool = nsxv_db.get_edge_resource_pool(context.session, edge_id) edge_pool_range = self.edge_pool_dicts[binding['edge_type']].get( binding['appliance_size']) + + nsxv_db.delete_nsxv_router_binding( + context.session, router_id) + backup_router_id = (vcns_const.BACKUP_ROUTER_PREFIX + + _uuid())[:vcns_const.EDGE_NAME_LEN] + nsxv_db.add_nsxv_router_binding( + context.session, + backup_router_id, + edge_id, + None, + plugin_const.PENDING_UPDATE, + appliance_size=binding['appliance_size'], + edge_type=binding['edge_type'], + resource_pool=res_pool) + + router_id = backup_router_id if (binding['status'] == plugin_const.ERROR or not self.check_edge_active_at_backend(edge_id) or not edge_pool_range): @@ -698,19 +714,6 @@ class EdgeManager(object): backup_num = len(backup_router_bindings) # collect the edge to pool if pool not full if backup_num < edge_pool_range['maximum_pooled_edges']: - nsxv_db.delete_nsxv_router_binding( - context.session, router_id) - backup_router_id = (vcns_const.BACKUP_ROUTER_PREFIX + - _uuid())[:vcns_const.EDGE_NAME_LEN] - nsxv_db.add_nsxv_router_binding( - context.session, - backup_router_id, - edge_id, - None, - plugin_const.PENDING_UPDATE, - appliance_size=binding['appliance_size'], - edge_type=binding['edge_type'], - resource_pool=res_pool) # change edge's name at backend task = self.nsxv_manager.update_edge( backup_router_id, edge_id, backup_router_id, None,