mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(QENG-2360) check_running_vm Spec Tests
Add spec tests for pool_manager#check_running_vm. In the process of writing these tests, the method was broken in to smaller methods for testability reasons.
This commit is contained in:
parent
640b1ef4da
commit
dec95ba693
2 changed files with 85 additions and 17 deletions
|
|
@ -132,31 +132,34 @@ module Vmpooler
|
|||
|
||||
def check_running_vm(vm, pool, ttl)
|
||||
Thread.new do
|
||||
host = $vsphere[pool].find_vm(vm)
|
||||
_check_running_vm(vm, pool, ttl)
|
||||
end
|
||||
end
|
||||
|
||||
if host
|
||||
if
|
||||
(host.runtime) &&
|
||||
def _check_running_vm(vm, pool, ttl)
|
||||
host = $vsphere[pool].find_vm(vm)
|
||||
|
||||
if host
|
||||
queue_from, queue_to = 'running', 'completed'
|
||||
|
||||
if (host.runtime) &&
|
||||
(host.runtime.powerState != 'poweredOn')
|
||||
|
||||
$redis.smove('vmpooler__running__' + pool, 'vmpooler__completed__' + pool, vm)
|
||||
|
||||
$logger.log('d', "[!] [#{pool}] '#{vm}' appears to be powered off or dead")
|
||||
else
|
||||
if
|
||||
(host.runtime) &&
|
||||
move_vm_queue(pool, vm, queue_from, queue_to, 'appears to be powered off or dead')
|
||||
else
|
||||
if (host.runtime) &&
|
||||
(host.runtime.bootTime)
|
||||
((((Time.now - host.runtime.bootTime) / 60).to_s[/^\d+\.\d{1}/].to_f) > ttl)
|
||||
|
||||
$redis.smove('vmpooler__running__' + pool, 'vmpooler__completed__' + pool, vm)
|
||||
|
||||
$logger.log('d', "[!] [#{pool}] '#{vm}' reached end of TTL after #{ttl} minutes")
|
||||
end
|
||||
((((Time.now - host.runtime.bootTime) / 60).to_s[/^\d+\.\d{1}/].to_f) > ttl)
|
||||
move_vm_queue(pool, vm, queue_from, queue_to, "reached end of TTL after #{ttl} minutes")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def move_vm_queue(pool, vm, queue_from, queue_to, msg)
|
||||
$redis.smove("vmpooler__#{queue_from}__#{pool}", "vmpooler__#{queue_to}__#{pool}", vm)
|
||||
$logger.log('d', "[!] [#{pool}] '#{vm}' #{msg}")
|
||||
end
|
||||
|
||||
# Clone a VM
|
||||
def clone_vm(template, folder, datastore, target)
|
||||
Thread.new do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue