mirror of
https://github.com/puppetlabs/vmpooler-provider-vsphere.git
synced 2026-01-25 19:08:41 -05:00
Merge pull request #44 from puppetlabs/fix-returning-ip
(RE-15710) Fix IP address that is returned and increase timeout
This commit is contained in:
commit
9971e84186
3 changed files with 35 additions and 3 deletions
|
|
@ -599,13 +599,15 @@ module Vmpooler
|
||||||
boottime = vm_object.runtime.bootTime if vm_object.runtime&.bootTime
|
boottime = vm_object.runtime.bootTime if vm_object.runtime&.bootTime
|
||||||
powerstate = vm_object.runtime.powerState if vm_object.runtime&.powerState
|
powerstate = vm_object.runtime.powerState if vm_object.runtime&.powerState
|
||||||
|
|
||||||
ip_maxloop = 60
|
ip_maxloop = 120
|
||||||
ip_loop_delay = 1
|
ip_loop_delay = 1
|
||||||
ip_loop_count = 1
|
ip_loop_count = 1
|
||||||
ip = nil
|
ip = nil
|
||||||
|
invalid_addresses = /(0|169)\.(0|254)\.\d+\.\d+/
|
||||||
while ip.nil?
|
while ip.nil?
|
||||||
sleep(ip_loop_delay)
|
sleep(ip_loop_delay)
|
||||||
ip = vm_object.guest_ip
|
ip = vm_object.guest_ip
|
||||||
|
ip = nil if !ip.nil? && ip.match?(invalid_addresses)
|
||||||
unless ip_maxloop == 0
|
unless ip_maxloop == 0
|
||||||
break if ip_loop_count >= ip_maxloop
|
break if ip_loop_count >= ip_maxloop
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -818,7 +818,7 @@ end
|
||||||
def mock_RbVmomi_VIM_VirtualMachine(options = {})
|
def mock_RbVmomi_VIM_VirtualMachine(options = {})
|
||||||
options[:snapshot_tree] = nil if options[:snapshot_tree].nil?
|
options[:snapshot_tree] = nil if options[:snapshot_tree].nil?
|
||||||
options[:name] = 'VM' + rand(65536).to_s if options[:name].nil?
|
options[:name] = 'VM' + rand(65536).to_s if options[:name].nil?
|
||||||
options[:ip] = '169.254.255.255' if options[:ip].nil?
|
options[:ip] = '192.168.0.2' if options[:ip].nil?
|
||||||
options[:path] = [] if options[:path].nil?
|
options[:path] = [] if options[:path].nil?
|
||||||
|
|
||||||
mock = MockVirtualMachine.new()
|
mock = MockVirtualMachine.new()
|
||||||
|
|
|
||||||
|
|
@ -580,11 +580,41 @@ EOT
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when VM exists but contains a self assigned ip' do
|
||||||
|
let(:vm_object) { mock_RbVmomi_VIM_VirtualMachine({
|
||||||
|
:name => vmname,
|
||||||
|
:ip => '169.254.255.255',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
it 'should return nil ip' do
|
||||||
|
allow(subject).to receive(:sleep)
|
||||||
|
result = subject.get_vm(poolname,vmname)
|
||||||
|
|
||||||
|
expect(result['ip']).to eq(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when VM exists but contains an invalid ip' do
|
||||||
|
let(:vm_object) { mock_RbVmomi_VIM_VirtualMachine({
|
||||||
|
:name => vmname,
|
||||||
|
:ip => '0.0.0.0',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
it 'should return nil for ip' do
|
||||||
|
allow(subject).to receive(:sleep)
|
||||||
|
result = subject.get_vm(poolname,vmname)
|
||||||
|
|
||||||
|
expect(result['ip']).to eq(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when VM exists and contains all information' do
|
context 'when VM exists and contains all information' do
|
||||||
let(:vm_hostname) { "#{vmname}.demo.local" }
|
let(:vm_hostname) { "#{vmname}.demo.local" }
|
||||||
let(:boot_time) { Time.now }
|
let(:boot_time) { Time.now }
|
||||||
let(:power_state) { 'MockPowerState' }
|
let(:power_state) { 'MockPowerState' }
|
||||||
let(:ip) { '169.254.255.255' }
|
let(:ip) { '192.168.0.2' }
|
||||||
|
|
||||||
let(:vm_object) { mock_RbVmomi_VIM_VirtualMachine({
|
let(:vm_object) { mock_RbVmomi_VIM_VirtualMachine({
|
||||||
:name => vmname,
|
:name => vmname,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue