From 55320f9e7b6a34df0ff22dbb103235f4bb3d0c47 Mon Sep 17 00:00:00 2001 From: Kaiting Chen Date: Thu, 19 Dec 2019 08:28:19 -0800 Subject: [PATCH] Skip a network that disappears during enumeration There's a race condition in #find_network between the enumeration of the datacenter's network folder and the retrieval of each network's name. If *any* network disappears during this iteration then #create_vm will fail. This skips any network that disappears during the enumeration. --- src/vsphere_cpi/lib/cloud/vsphere/vcenter_client.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/vsphere_cpi/lib/cloud/vsphere/vcenter_client.rb b/src/vsphere_cpi/lib/cloud/vsphere/vcenter_client.rb index 998435d9d..cd5b9f098 100644 --- a/src/vsphere_cpi/lib/cloud/vsphere/vcenter_client.rb +++ b/src/vsphere_cpi/lib/cloud/vsphere/vcenter_client.rb @@ -215,7 +215,7 @@ def find_network(datacenter, network_name) if network_name.include?('/') container_name = File.dirname(network_name) network_name = File.basename(network_name) - network_container = find_by_inventory_path([ datacenter.name, 'network', container_name]) + network_container = find_by_inventory_path([datacenter.name, 'network', container_name]) if network_container.nil? network_container = find_child_by_name(datacenter.mob.network_folder, container_name.split('/')) end @@ -229,7 +229,14 @@ def find_network(datacenter, network_name) end target_network = nil - matching_networks = valid_networks.select { |n| n.name == network_name } + matching_networks = valid_networks.select do |network| + begin + network.name == network_name + rescue => e + logger.warn("Can't retrieve name of network #{network}: #{e}") + false + end + end if matching_networks.length == 1 target_network = matching_networks.first elsif matching_networks.length > 1