mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(POOLER-70) Update fail_pending_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 - Modified to return true or false to indicate that the VM was failed
This commit is contained in:
parent
199bf4a070
commit
9f4fc903b9
2 changed files with 10 additions and 8 deletions
|
|
@ -52,7 +52,7 @@ module Vmpooler
|
||||||
|
|
||||||
def fail_pending_vm(vm, pool, timeout, exists = true)
|
def fail_pending_vm(vm, pool, timeout, exists = true)
|
||||||
clone_stamp = $redis.hget("vmpooler__vm__#{vm}", 'clone')
|
clone_stamp = $redis.hget("vmpooler__vm__#{vm}", 'clone')
|
||||||
return if ! clone_stamp
|
return true if !clone_stamp
|
||||||
|
|
||||||
time_since_clone = (Time.now - Time.parse(clone_stamp)) / 60
|
time_since_clone = (Time.now - Time.parse(clone_stamp)) / 60
|
||||||
if time_since_clone > timeout
|
if time_since_clone > timeout
|
||||||
|
|
@ -63,8 +63,10 @@ module Vmpooler
|
||||||
remove_nonexistent_vm(vm, pool)
|
remove_nonexistent_vm(vm, pool)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
true
|
||||||
rescue => err
|
rescue => err
|
||||||
$logger.log('d', "Fail pending VM failed with an error: #{err}")
|
$logger.log('d', "Fail pending VM failed with an error: #{err}")
|
||||||
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def move_pending_vm_to_ready(vm, pool, host)
|
def move_pending_vm_to_ready(vm, pool, host)
|
||||||
|
|
|
||||||
|
|
@ -114,19 +114,19 @@ EOT
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'takes no action if VM is not cloning' do
|
it 'takes no action if VM is not cloning' do
|
||||||
expect(subject.fail_pending_vm(vm, pool, timeout)).to eq(nil)
|
expect(subject.fail_pending_vm(vm, pool, timeout)).to eq(true)
|
||||||
expect(redis.sismember("vmpooler__pending__#{pool}", vm)).to be(true)
|
expect(redis.sismember("vmpooler__pending__#{pool}", vm)).to be(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'takes no action if VM is within timeout' do
|
it 'takes no action if VM is within timeout' do
|
||||||
redis.hset("vmpooler__vm__#{vm}", 'clone',Time.now.to_s)
|
redis.hset("vmpooler__vm__#{vm}", 'clone',Time.now.to_s)
|
||||||
expect(subject.fail_pending_vm(vm, pool, timeout)).to eq(nil)
|
expect(subject.fail_pending_vm(vm, pool, timeout)).to eq(true)
|
||||||
expect(redis.sismember("vmpooler__pending__#{pool}", vm)).to be(true)
|
expect(redis.sismember("vmpooler__pending__#{pool}", vm)).to be(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'moves VM to completed queue if VM has exceeded timeout and exists' do
|
it 'moves VM to completed queue if VM has exceeded timeout and exists' do
|
||||||
redis.hset("vmpooler__vm__#{vm}", 'clone',Date.new(2001,1,1).to_s)
|
redis.hset("vmpooler__vm__#{vm}", 'clone',Date.new(2001,1,1).to_s)
|
||||||
expect(subject.fail_pending_vm(vm, pool, timeout,true)).to eq(nil)
|
expect(subject.fail_pending_vm(vm, pool, timeout,true)).to eq(true)
|
||||||
expect(redis.sismember("vmpooler__pending__#{pool}", vm)).to be(false)
|
expect(redis.sismember("vmpooler__pending__#{pool}", vm)).to be(false)
|
||||||
expect(redis.sismember("vmpooler__completed__#{pool}", vm)).to be(true)
|
expect(redis.sismember("vmpooler__completed__#{pool}", vm)).to be(true)
|
||||||
end
|
end
|
||||||
|
|
@ -134,18 +134,18 @@ EOT
|
||||||
it 'logs message if VM has exceeded timeout and exists' do
|
it 'logs message if VM has exceeded timeout and exists' do
|
||||||
redis.hset("vmpooler__vm__#{vm}", 'clone',Date.new(2001,1,1).to_s)
|
redis.hset("vmpooler__vm__#{vm}", 'clone',Date.new(2001,1,1).to_s)
|
||||||
expect(logger).to receive(:log).with('d', "[!] [#{pool}] '#{vm}' marked as 'failed' after #{timeout} minutes")
|
expect(logger).to receive(:log).with('d', "[!] [#{pool}] '#{vm}' marked as 'failed' after #{timeout} minutes")
|
||||||
expect(subject.fail_pending_vm(vm, pool, timeout,true)).to eq(nil)
|
expect(subject.fail_pending_vm(vm, pool, timeout,true)).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls remove_nonexistent_vm if VM has exceeded timeout and does not exist' do
|
it 'calls remove_nonexistent_vm if VM has exceeded timeout and does not exist' do
|
||||||
redis.hset("vmpooler__vm__#{vm}", 'clone',Date.new(2001,1,1).to_s)
|
redis.hset("vmpooler__vm__#{vm}", 'clone',Date.new(2001,1,1).to_s)
|
||||||
expect(subject).to receive(:remove_nonexistent_vm).with(vm, pool)
|
expect(subject).to receive(:remove_nonexistent_vm).with(vm, pool)
|
||||||
expect(subject.fail_pending_vm(vm, pool, timeout,false)).to eq(nil)
|
expect(subject.fail_pending_vm(vm, pool, timeout,false)).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'swallows error if an error is raised' do
|
it 'swallows error if an error is raised' do
|
||||||
redis.hset("vmpooler__vm__#{vm}", 'clone','iamnotparsable_asdate')
|
redis.hset("vmpooler__vm__#{vm}", 'clone','iamnotparsable_asdate')
|
||||||
expect(subject.fail_pending_vm(vm, pool, timeout,true)).to eq(nil)
|
expect(subject.fail_pending_vm(vm, pool, timeout,true)).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'logs message if an error is raised' do
|
it 'logs message if an error is raised' do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue