mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Fix no implicit conversion to rational from nil (#239)
* Fix no implicit conversion to rational from nil Before this change if the boottime was nil, the check_ready loop would exit on Time.now - host['boottime'] with a TypeError in jruby. The boottime is nil when the power is Off so moving that check earlier should catch that bug. * set test data properly
This commit is contained in:
parent
be61501260
commit
0b5abd9bd3
2 changed files with 11 additions and 8 deletions
|
|
@ -119,8 +119,17 @@ module Vmpooler
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
$redis.hset('vmpooler__vm__' + vm, 'check', Time.now)
|
||||||
|
# Check if the VM is not powered on, before checking TTL
|
||||||
|
unless host['powerstate'].casecmp('poweredon').zero?
|
||||||
|
$redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm)
|
||||||
|
$logger.log('d', "[!] [#{pool}] '#{vm}' appears to be powered off, removed from 'ready' queue")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
# Check if the hosts TTL has expired
|
# Check if the hosts TTL has expired
|
||||||
if ttl > 0
|
if ttl > 0
|
||||||
|
# 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, 'vmpooler__completed__' + pool, vm)
|
$redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm)
|
||||||
|
|
||||||
|
|
@ -129,14 +138,6 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
$redis.hset('vmpooler__vm__' + vm, 'check', Time.now)
|
|
||||||
# Check if the VM is not powered on
|
|
||||||
unless host['powerstate'].casecmp('poweredon').zero?
|
|
||||||
$redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm)
|
|
||||||
$logger.log('d', "[!] [#{pool}] '#{vm}' appears to be powered off, removed from 'ready' queue")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
# Check if the hostname has magically changed from underneath Pooler
|
# Check if the hostname has magically changed from underneath Pooler
|
||||||
if host['hostname'] != vm
|
if host['hostname'] != vm
|
||||||
$redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm)
|
$redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm)
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,9 @@ EOT
|
||||||
|
|
||||||
context 'is turned off' do
|
context 'is turned off' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
host['boottime'] = nil
|
||||||
host['powerstate'] = 'PoweredOff'
|
host['powerstate'] = 'PoweredOff'
|
||||||
|
ttl = 1440
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should move the VM to the completed queue' do
|
it 'should move the VM to the completed queue' do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue