Skip to content

Commit

Permalink
Correctly return nil if no valid adapters are present.
Browse files Browse the repository at this point in the history
This should resolve #231
  • Loading branch information
Jkovarik committed Mar 7, 2017
1 parent a3678fa commit 4e387fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/vSphere/action/get_ssh_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def filter_guest_nic(vm, machine)
interfaces = vm.guest.net.select { |g| g.deviceConfigId > 0 }
ip_addresses = interfaces.map { |i| i.ipConfig.ipAddress.select { |a| a.state == 'preferred' } }.flatten

return nil if ip_addresses.empty?
fail Errors::VSphereError.new, :'multiple_interface_with_real_nic_ip_set' if ip_addresses.size > 1
ip_addresses.first.ipAddress
end
Expand Down
9 changes: 9 additions & 0 deletions spec/get_ssh_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@
expect(@env[:machine_ssh_info][:host]).to eq IP_ADDRESS
end

context 'when the VM networking is uninitialized' do
before do
allow(@vm.guest).to receive(:net) {[]}
end
it 'should set the ssh info to nil if no valid adapters are present' do
call
expect(@env[:machine_ssh_info]).to eq nil
end
end
end
end
end

0 comments on commit 4e387fe

Please sign in to comment.