mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(POOLER-70) Update check_running_vm for VM Provider
Previously the Pool Manager would use vSphere objects directly. This commit - Modifies the pool_manager to use the VM provider methods instead
This commit is contained in:
parent
8c421aa3bd
commit
cc1910fd76
2 changed files with 16 additions and 12 deletions
|
|
@ -149,12 +149,17 @@ module Vmpooler
|
||||||
|
|
||||||
def check_running_vm(vm, pool, ttl, provider)
|
def check_running_vm(vm, pool, ttl, provider)
|
||||||
Thread.new do
|
Thread.new do
|
||||||
|
begin
|
||||||
_check_running_vm(vm, pool, ttl, provider)
|
_check_running_vm(vm, pool, ttl, provider)
|
||||||
|
rescue => err
|
||||||
|
$logger.log('s', "[!] [#{pool}] '#{vm}' failed while checking VM with an error: #{err}")
|
||||||
|
raise
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def _check_running_vm(vm, pool, ttl, provider)
|
def _check_running_vm(vm, pool, ttl, provider)
|
||||||
host = provider.find_vm(vm)
|
host = provider.get_vm(pool, vm)
|
||||||
|
|
||||||
if host
|
if host
|
||||||
queue_from, queue_to = 'running', 'completed'
|
queue_from, queue_to = 'running', 'completed'
|
||||||
|
|
|
||||||
|
|
@ -407,7 +407,7 @@ EOT
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#_check_running_vm' do
|
describe '#_check_running_vm' do
|
||||||
let(:provider) { double('provider') }
|
let(:host) { {} }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
expect(subject).not_to be_nil
|
expect(subject).not_to be_nil
|
||||||
|
|
@ -415,24 +415,26 @@ EOT
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
create_running_vm(pool,vm)
|
create_running_vm(pool,vm)
|
||||||
|
|
||||||
|
# Create a VM which is powered on
|
||||||
|
host['hostname'] = vm
|
||||||
|
host['powerstate'] = 'PoweredOn'
|
||||||
|
allow(provider).to receive(:get_vm).with(pool,vm).and_return(host)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does nothing with a missing VM' do
|
it 'does nothing with a missing VM' do
|
||||||
allow(provider).to receive(:find_vm).and_return(nil)
|
expect(provider).to receive(:get_vm).with(pool,vm).and_return(nil)
|
||||||
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
||||||
subject._check_running_vm(vm, pool, timeout, provider)
|
subject._check_running_vm(vm, pool, timeout, provider)
|
||||||
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'valid host' do
|
context 'valid host' do
|
||||||
let(:vm_host) { double('vmhost') }
|
|
||||||
|
|
||||||
it 'should not move VM when not poweredOn' do
|
it 'should not move VM when not poweredOn' do
|
||||||
# I'm not sure this test is useful. There is no codepath
|
# I'm not sure this test is useful. There is no codepath
|
||||||
# in _check_running_vm that looks at Power State
|
# in _check_running_vm that looks at Power State
|
||||||
allow(provider).to receive(:find_vm).and_return vm_host
|
host['powerstate'] = 'PoweredOff'
|
||||||
allow(vm_host).to receive(:runtime).and_return true
|
|
||||||
allow(vm_host).to receive_message_chain(:runtime, :powerState).and_return 'poweredOff'
|
|
||||||
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")
|
||||||
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
||||||
subject._check_running_vm(vm, pool, timeout, provider)
|
subject._check_running_vm(vm, pool, timeout, provider)
|
||||||
|
|
@ -440,14 +442,12 @@ EOT
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not move VM if it has no checkout time' do
|
it 'should not move VM if it has no checkout time' do
|
||||||
allow(provider).to receive(:find_vm).and_return vm_host
|
|
||||||
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
||||||
subject._check_running_vm(vm, pool, 0, provider)
|
subject._check_running_vm(vm, pool, 0, provider)
|
||||||
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not move VM if TTL is zero' do
|
it 'should not move VM if TTL is zero' do
|
||||||
allow(provider).to receive(:find_vm).and_return vm_host
|
|
||||||
redis.hset("vmpooler__active__#{pool}", vm,(Time.now - timeout*60*60).to_s)
|
redis.hset("vmpooler__active__#{pool}", vm,(Time.now - timeout*60*60).to_s)
|
||||||
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
||||||
subject._check_running_vm(vm, pool, 0, provider)
|
subject._check_running_vm(vm, pool, 0, provider)
|
||||||
|
|
@ -455,7 +455,6 @@ EOT
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should move VM when past TTL' do
|
it 'should move VM when past TTL' do
|
||||||
allow(provider).to receive(:find_vm).and_return vm_host
|
|
||||||
redis.hset("vmpooler__active__#{pool}", vm,(Time.now - timeout*60*60).to_s)
|
redis.hset("vmpooler__active__#{pool}", vm,(Time.now - timeout*60*60).to_s)
|
||||||
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
expect(redis.sismember("vmpooler__running__#{pool}", vm)).to be(true)
|
||||||
expect(redis.sismember("vmpooler__completed__#{pool}", vm)).to be(false)
|
expect(redis.sismember("vmpooler__completed__#{pool}", vm)).to be(false)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue