Remove debug statements. Return when get_vm returns nil

This commit is contained in:
kirby@puppetlabs.com 2018-09-12 12:28:12 -07:00
parent cd73f53561
commit 830acd705d
3 changed files with 24 additions and 37 deletions

View file

@ -149,34 +149,25 @@ module Vmpooler
# Periodically check that the VM is available # Periodically check that the VM is available
mutex = vm_mutex(vm) mutex = vm_mutex(vm)
return if mutex.locked? return if mutex.locked?
begin mutex.synchronize do
mutex.synchronize do check_stamp = $redis.hget('vmpooler__vm__' + vm, 'check')
stage = 'stamp check' return if check_stamp && (((Time.now - Time.parse(check_stamp)) / 60) <= $config[:config]['vm_checktime'])
check_stamp = $redis.hget('vmpooler__vm__' + vm, 'check')
return if check_stamp && (((Time.now - Time.parse(check_stamp)) / 60) <= $config[:config]['vm_checktime'])
$redis.hset('vmpooler__vm__' + vm, 'check', Time.now) $redis.hset('vmpooler__vm__' + vm, 'check', Time.now)
# Check if the hosts TTL has expired # Check if the hosts TTL has expired
stage = 'ttl' if ttl > 0
if ttl > 0 # host['boottime'] may be nil if host is not powered on
# host['boottime'] may be nil if host is not powered on if ((Time.now - host['boottime']) / 60).to_s[/^\d+\.\d{1}/].to_f > ttl
if ((Time.now - host['boottime']) / 60).to_s[/^\d+\.\d{1}/].to_f > ttl $redis.smove('vmpooler__ready__' + pool['name'], 'vmpooler__completed__' + pool['name'], vm)
$redis.smove('vmpooler__ready__' + pool['name'], 'vmpooler__completed__' + pool['name'], vm)
$logger.log('d', "[!] [#{pool['name']}] '#{vm}' reached end of TTL after #{ttl} minutes, removed from 'ready' queue") $logger.log('d', "[!] [#{pool['name']}] '#{vm}' reached end of TTL after #{ttl} minutes, removed from 'ready' queue")
return return
end
end end
stage = 'hostname mismatch'
return if has_mismatched_hostname?(vm, pool, provider)
stage = 'still ready'
vm_still_ready?(pool['name'], vm, provider)
end end
rescue => err
$logger.log('s', "Failed at stage #{stage} for #{vm}") return if has_mismatched_hostname?(vm, pool, provider)
raise
vm_still_ready?(pool['name'], vm, provider)
end end
end end
@ -197,6 +188,7 @@ module Vmpooler
# Check if the hostname has magically changed from underneath Pooler # Check if the hostname has magically changed from underneath Pooler
vm_hash = provider.get_vm(pool['name'], vm) vm_hash = provider.get_vm(pool['name'], vm)
return unless vm_hash.is_a? Hash
hostname = vm_hash['hostname'] hostname = vm_hash['hostname']
return if hostname.nil? return if hostname.nil?
@ -875,7 +867,7 @@ module Vmpooler
end end
end end
def check_ready_pool_vms(pool_name, provider, pool_check_response, inventory, pool_ttl) def check_ready_pool_vms(pool_name, provider, pool_check_response, inventory, pool_ttl = 0)
$redis.smembers("vmpooler__ready__#{pool_name}").each do |vm| $redis.smembers("vmpooler__ready__#{pool_name}").each do |vm|
if inventory[vm] if inventory[vm]
begin begin

View file

@ -2974,9 +2974,7 @@ EOT
# mock response from create_inventory # mock response from create_inventory
{vm => 1} {vm => 1}
} }
let(:big_lifetime) { let(:big_lifetime) { 2000 }
2000
}
before(:each) do before(:each) do
allow(subject).to receive(:check_ready_vm) allow(subject).to receive(:check_ready_vm)
create_ready_vm(pool,vm,token) create_ready_vm(pool,vm,token)
@ -2992,7 +2990,7 @@ EOT
expect(subject).to receive(:check_ready_vm).and_raise(RuntimeError,'MockError') expect(subject).to receive(:check_ready_vm).and_raise(RuntimeError,'MockError')
expect(logger).to receive(:log).with('d', "[!] [#{pool}] _check_pool failed with an error while evaluating ready VMs: MockError") expect(logger).to receive(:log).with('d', "[!] [#{pool}] _check_pool failed with an error while evaluating ready VMs: MockError")
subject.check_ready_pool_vms(pool, provider, pool_check_response, inventory) subject.check_ready_pool_vms(pool, provider, pool_check_response, inventory, big_lifetime)
end end
it 'should use the pool TTL if set' do it 'should use the pool TTL if set' do
@ -3511,12 +3509,8 @@ EOT
end end
it 'captures #create_inventory errors correctly' do it 'captures #create_inventory errors correctly' do
allow(subject).to receive(:create_inventory).and_raise( allow(subject).to receive(:create_inventory).and_raise(RuntimeError,'Mock Error')
RuntimeError,'Mock Error' subject._check_pool(pool_object, provider)
)
expect {
subject._check_pool(pool_object, provider)
}.to_not raise_error(RuntimeError, /Mock Error/)
end end
it 'should return early if an error occurs' do it 'should return early if an error occurs' do

View file

@ -925,9 +925,10 @@ EOT
end end
describe '#vm_ready?' do describe '#vm_ready?' do
let(:domain) { nil }
context 'When a VM is ready' do context 'When a VM is ready' do
before(:each) do before(:each) do
expect(subject).to receive(:open_socket).with(vmname) expect(subject).to receive(:open_socket).with(vmname, domain)
end end
it 'should return true' do it 'should return true' do
@ -939,7 +940,7 @@ EOT
# TODO not sure how to handle a VM that is passed in but # TODO not sure how to handle a VM that is passed in but
# not located in the pool. Is that ready or not? # not located in the pool. Is that ready or not?
before(:each) do before(:each) do
expect(subject).to receive(:open_socket).with(vmname) expect(subject).to receive(:open_socket).with(vmname, domain)
end end
it 'should return true' do it 'should return true' do