From 66a1e3a85cad22a4968438441aff5514a5939b96 Mon Sep 17 00:00:00 2001 From: Julian Hjortshoj Date: Wed, 25 Aug 2021 17:04:02 -0700 Subject: [PATCH] Accommodate non-NSX-T Distributed Virtual Switches Previously the vSphere CPI NSX-T Policy API assumed _all_ Distributed Virtual Switches (DVSes) were NSX-T Segments, but that assummption was false; DVSes may be managed by vSphere and not NSX-T. We now check whether the network interface controller (NIC) is NSX-T-managed before attempting to tag the NIC's port with NSX-T metadata. fixes: ``` unable to create bosh vm:CPI 'set_vm_metadata' method responded with error: CmdError{"type":"Unknown","message":"Invalid Query","ok_to_retry":false} ``` [fixes #302] [#179334136](https://www.pivotaltracker.com/story/show/179334136) Signed-off-by: Brian Cunnie --- src/vsphere_cpi/spec/integration/nsxt_spec.rb | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/vsphere_cpi/spec/integration/nsxt_spec.rb b/src/vsphere_cpi/spec/integration/nsxt_spec.rb index e6a638f1d..d6c847110 100644 --- a/src/vsphere_cpi/spec/integration/nsxt_spec.rb +++ b/src/vsphere_cpi/spec/integration/nsxt_spec.rb @@ -538,6 +538,41 @@ def initialize(name: "BOSH-CPI-test-#{SecureRandom.uuid}", id: SecureRandom.uuid expect(server_pool_2.members).to be_nil end end + + context 'with non-nsxt distributed virtual switches' do + let(:nsxt_spec) { {} } + let(:dvpg_name) { ENV.fetch('BOSH_VSPHERE_CPI_FOLDER_PORTGROUP_ONE') } + let(:policy_network_spec) do + { + 'static-bridged' => { + 'ip' => "169.254.#{rand(1..254)}.#{rand(4..254)}", + 'netmask' => '255.255.254.0', + 'cloud_properties' => { 'name' => segment_1.name }, + 'default' => ['dns', 'gateway'], + 'dns' => ['169.254.1.2'], + 'gateway' => '169.254.1.3' + }, + 'static' => { + 'ip' => "169.254.#{rand(1..254)}.#{rand(4..254)}", + 'netmask' => '255.255.254.0', + 'cloud_properties' => { 'name' => dvpg_name }, + 'default' => ['dns', 'gateway'], + 'dns' => ['169.254.1.2'], + 'gateway' => '169.254.1.3' + } + } + end + it 'creates a VM without errors' do + simple_vm_lifecycle(cpi, '', vm_type, policy_network_spec) do |vm_id| + cpi.set_vm_metadata(vm_id, {'id' => 'foo'}) + + vm = @cpi.vm_provider.find(vm_id) + segment_names = vm.get_nsxt_segment_vif_list.map { |x| x[0] } + expect(segment_names.length).to eq(1) + expect(segment_names).to include(segment_1.name) + end + end + end end end