From 0accfb2c6d75aeb6c1091cff62b79632138af00a Mon Sep 17 00:00:00 2001 From: Angel Luis Moya Gonzalez Date: Tue, 8 Oct 2019 10:40:24 +0200 Subject: [PATCH] F #3440: Fix bug creating NSX networks (#3821) * F #3440: Fix bug creating NSX networks Fix bug when creating NSX network without transport zone. Added more checks and exceptions to manage them. * F #3440: Added backtrace to error message --- share/hooks/vcenter/create_vcenter_net.rb | 20 ++++++++++---- .../remotes/lib/nsx_driver/opaque_network.rb | 27 ++++++++++--------- .../remotes/lib/nsx_driver/virtual_wire.rb | 27 ++++++++++--------- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/share/hooks/vcenter/create_vcenter_net.rb b/share/hooks/vcenter/create_vcenter_net.rb index dc2ca8e25d..f5115272c0 100755 --- a/share/hooks/vcenter/create_vcenter_net.rb +++ b/share/hooks/vcenter/create_vcenter_net.rb @@ -158,8 +158,13 @@ begin UNICAST_MODE\ false\ " - logical_switch = NSXDriver::VirtualWire - .new(nsx_client, nil, tz_id, virtual_wire_spec) + begin + logical_switch = NSXDriver::VirtualWire + .new(nsx_client, nil, tz_id, virtual_wire_spec) + rescue StandardError => e + STDERR.puts "ERROR: #{e.message} #{e.backtrace}" + exit(-1) + end # Get reference will have in vcenter and vni vnet_ref = logical_switch.ls_vcenter_ref ls_vni = logical_switch.ls_vni @@ -180,9 +185,14 @@ begin "description": "#{ls_description}" } ) - logical_switch = NSXDriver::OpaqueNetwork - .new(nsx_client, nil, nil, opaque_network_spec) - # Get NSX_VNI + begin + logical_switch = NSXDriver::OpaqueNetwork + .new(nsx_client, nil, tz_id, opaque_network_spec) + rescue StandardError => e + STDERR.puts "ERROR: #{e.message} #{e.backtrace}" + exit(-1) + end + # Get reference will have in vcenter and vni vnet_ref = dc.nsx_network(logical_switch.ls_id, pg_type) ls_vni = logical_switch.ls_vni ls_name = logical_switch.ls_name diff --git a/src/vmm_mad/remotes/lib/nsx_driver/opaque_network.rb b/src/vmm_mad/remotes/lib/nsx_driver/opaque_network.rb index 0f642a7fa3..cf071ef28d 100644 --- a/src/vmm_mad/remotes/lib/nsx_driver/opaque_network.rb +++ b/src/vmm_mad/remotes/lib/nsx_driver/opaque_network.rb @@ -24,7 +24,7 @@ module NSXDriver SECTION_LS = '/logical-switches/' # CONSTRUCTOR - def initialize(nsx_client, ls_id = nil, _tz_id = nil, ls_data = nil) + def initialize(nsx_client, ls_id = nil, tz_id = nil, ls_data = nil) super(nsx_client) # Construct base URLs @base_url = "#{@nsx_client.nsxmgr}/api/v1" @@ -32,18 +32,19 @@ module NSXDriver if ls_id initialize_with_id(ls_id) else - if tz_id - if ls_data - @ls_id = new_logical_switch(ls_data) - # Construct URL of the created logical switch - @url_ls = @base_url + SECTION_LS + @ls_id - @ls_vni = ls_vni - @ls_name = ls_name - @tz_id = ls_tz - @admin_display = 'UP' - end - raise 'Missing logical switch data' unless ls_data - end + raise 'Missing transport zone id' unless tz_id + + raise 'Missing logical switch data' unless ls_data + + @ls_id = new_logical_switch(ls_data) + raise 'Opaque Network not created in NSX' unless @ls_id + + # Construct URL of the created logical switch + @url_ls = @base_url + SECTION_LS + @ls_id + @ls_vni = ls_vni + @ls_name = ls_name + @tz_id = ls_tz + @admin_display = 'UP' end end diff --git a/src/vmm_mad/remotes/lib/nsx_driver/virtual_wire.rb b/src/vmm_mad/remotes/lib/nsx_driver/virtual_wire.rb index 150c57668a..387d9741b2 100644 --- a/src/vmm_mad/remotes/lib/nsx_driver/virtual_wire.rb +++ b/src/vmm_mad/remotes/lib/nsx_driver/virtual_wire.rb @@ -38,19 +38,20 @@ module NSXDriver if ls_id initialize_with_id(ls_id) else - if tz_id - if ls_data - @ls_id = new_logical_switch(ls_data, tz_id) - # Construct URL of the created logical switch - @url_ls = @base_url + SECTION_LS + @ls_id - @ls_vni = ls_vni - @ls_name = ls_name - @tz_id = ls_tz - @tenant_id = 'virtual wire tenant' - @guest_vlan_allowed = false - end - raise 'Missing logical switch data' unless ls? - end + raise 'Missing transport zone id' unless tz_id + + raise 'Missing logical switch data' unless ls_data + + @ls_id = new_logical_switch(ls_data, tz_id) + raise 'Virtual Wire not created in NSX' unless @ls_id + + # Construct URL of the created logical switch + @url_ls = @base_url + SECTION_LS + @ls_id + @ls_vni = ls_vni + @ls_name = ls_name + @tz_id = ls_tz + @tenant_id = 'virtual wire tenant' + @guest_vlan_allowed = false end end