mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-27 10:28:41 -05:00
Merge de8af1cd71 into 4e2a1fb62c
This commit is contained in:
commit
058901f1b7
2 changed files with 37 additions and 54 deletions
|
|
@ -22,12 +22,6 @@ module Vmpooler
|
||||||
|
|
||||||
# Check the state of a VM
|
# Check the state of a VM
|
||||||
def check_pending_vm(vm, pool, timeout)
|
def check_pending_vm(vm, pool, timeout)
|
||||||
Thread.new do
|
|
||||||
_check_pending_vm(vm, pool, timeout)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def _check_pending_vm(vm, pool, timeout)
|
|
||||||
host = $vsphere[pool].find_vm(vm)
|
host = $vsphere[pool].find_vm(vm)
|
||||||
|
|
||||||
if host
|
if host
|
||||||
|
|
@ -78,7 +72,6 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_ready_vm(vm, pool, ttl)
|
def check_ready_vm(vm, pool, ttl)
|
||||||
Thread.new do
|
|
||||||
if ttl > 0
|
if ttl > 0
|
||||||
if (((Time.now - host.runtime.bootTime) / 60).to_s[/^\d+\.\d{1}/].to_f) > ttl
|
if (((Time.now - host.runtime.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)
|
||||||
|
|
@ -89,8 +82,7 @@ module Vmpooler
|
||||||
|
|
||||||
check_stamp = $redis.hget('vmpooler__vm__' + vm, 'check')
|
check_stamp = $redis.hget('vmpooler__vm__' + vm, 'check')
|
||||||
|
|
||||||
if
|
if (!check_stamp) ||
|
||||||
(!check_stamp) ||
|
|
||||||
(((Time.now - Time.parse(check_stamp)) / 60) > $config[:config]['vm_checktime'])
|
(((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)
|
||||||
|
|
@ -99,8 +91,7 @@ module Vmpooler
|
||||||
$vsphere[pool].find_vm_heavy(vm)[vm]
|
$vsphere[pool].find_vm_heavy(vm)[vm]
|
||||||
|
|
||||||
if host
|
if host
|
||||||
if
|
if (host.runtime) &&
|
||||||
(host.runtime) &&
|
|
||||||
(host.runtime.powerState) &&
|
(host.runtime.powerState) &&
|
||||||
(host.runtime.powerState != 'poweredOn')
|
(host.runtime.powerState != 'poweredOn')
|
||||||
|
|
||||||
|
|
@ -109,8 +100,7 @@ module Vmpooler
|
||||||
$logger.log('d', "[!] [#{pool}] '#{vm}' appears to be powered off, removed from 'ready' queue")
|
$logger.log('d', "[!] [#{pool}] '#{vm}' appears to be powered off, removed from 'ready' queue")
|
||||||
end
|
end
|
||||||
|
|
||||||
if
|
if (host.summary.guest) &&
|
||||||
(host.summary.guest) &&
|
|
||||||
(host.summary.guest.hostName) &&
|
(host.summary.guest.hostName) &&
|
||||||
(host.summary.guest.hostName != vm)
|
(host.summary.guest.hostName != vm)
|
||||||
|
|
||||||
|
|
@ -135,15 +125,8 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def check_running_vm(vm, pool, ttl)
|
def check_running_vm(vm, pool, ttl)
|
||||||
Thread.new do
|
|
||||||
_check_running_vm(vm, pool, ttl)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def _check_running_vm(vm, pool, ttl)
|
|
||||||
host = $vsphere[pool].find_vm(vm)
|
host = $vsphere[pool].find_vm(vm)
|
||||||
|
|
||||||
if host
|
if host
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ describe 'Pool Manager' do
|
||||||
|
|
||||||
subject { Vmpooler::PoolManager.new(config, logger, redis, graphite) }
|
subject { Vmpooler::PoolManager.new(config, logger, redis, graphite) }
|
||||||
|
|
||||||
describe '#_check_pending_vm' do
|
describe '#check_pending_vm' do
|
||||||
let(:pool_helper) { double('pool') }
|
let(:pool_helper) { double('pool') }
|
||||||
let(:vsphere) { {pool => pool_helper} }
|
let(:vsphere) { {pool => pool_helper} }
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ describe 'Pool Manager' do
|
||||||
allow(pool_helper).to receive(:find_vm).and_return(nil)
|
allow(pool_helper).to receive(:find_vm).and_return(nil)
|
||||||
allow(redis).to receive(:hget)
|
allow(redis).to receive(:hget)
|
||||||
expect(redis).to receive(:hget).with(String, 'clone').once
|
expect(redis).to receive(:hget).with(String, 'clone').once
|
||||||
subject._check_pending_vm(vm, pool, timeout)
|
subject.check_pending_vm(vm, pool, timeout)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
@ -47,7 +47,7 @@ describe 'Pool Manager' do
|
||||||
expect(vm_finder).to receive(:summary).once
|
expect(vm_finder).to receive(:summary).once
|
||||||
expect(redis).not_to receive(:hget).with(String, 'clone')
|
expect(redis).not_to receive(:hget).with(String, 'clone')
|
||||||
|
|
||||||
subject._check_pending_vm(vm, pool, timeout)
|
subject.check_pending_vm(vm, pool, timeout)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -150,7 +150,7 @@ describe 'Pool Manager' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#_check_running_vm' do
|
describe '#check_running_vm' do
|
||||||
let(:pool_helper) { double('pool') }
|
let(:pool_helper) { double('pool') }
|
||||||
let(:vsphere) { {pool => pool_helper} }
|
let(:vsphere) { {pool => pool_helper} }
|
||||||
|
|
||||||
|
|
@ -162,7 +162,7 @@ describe 'Pool Manager' do
|
||||||
it 'does nothing with nil host' do
|
it 'does nothing with nil host' do
|
||||||
allow(pool_helper).to receive(:find_vm).and_return(nil)
|
allow(pool_helper).to receive(:find_vm).and_return(nil)
|
||||||
expect(redis).not_to receive(:smove)
|
expect(redis).not_to receive(:smove)
|
||||||
subject._check_running_vm(vm, pool, timeout)
|
subject.check_running_vm(vm, pool, timeout)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'valid host' do
|
context 'valid host' do
|
||||||
|
|
@ -177,7 +177,7 @@ describe 'Pool Manager' do
|
||||||
expect(redis).not_to receive(:smove)
|
expect(redis).not_to receive(:smove)
|
||||||
expect(logger).not_to receive(:log).with('d', "[!] [#{pool}] '#{vm}' appears to be powered off or dead")
|
expect(logger).not_to receive(:log).with('d', "[!] [#{pool}] '#{vm}' appears to be powered off or dead")
|
||||||
|
|
||||||
subject._check_running_vm(vm, pool, timeout)
|
subject.check_running_vm(vm, pool, timeout)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'moves vm when poweredOn, but past TTL' do
|
it 'moves vm when poweredOn, but past TTL' do
|
||||||
|
|
@ -189,7 +189,7 @@ describe 'Pool Manager' do
|
||||||
expect(redis).to receive(:smove)
|
expect(redis).to receive(:smove)
|
||||||
expect(logger).to receive(:log).with('d', "[!] [#{pool}] '#{vm}' reached end of TTL after #{timeout} hours")
|
expect(logger).to receive(:log).with('d', "[!] [#{pool}] '#{vm}' reached end of TTL after #{timeout} hours")
|
||||||
|
|
||||||
subject._check_running_vm(vm, pool, timeout)
|
subject.check_running_vm(vm, pool, timeout)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue