From 9f4fc903b9fa44cc3db8c90f281abfd313100f51 Mon Sep 17 00:00:00 2001 From: Glenn Sarti Date: Fri, 31 Mar 2017 13:42:09 -0700 Subject: [PATCH] (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 --- lib/vmpooler/pool_manager.rb | 6 ++++-- spec/unit/pool_manager_spec.rb | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index 87c0588..5e57dca 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -50,9 +50,9 @@ module Vmpooler $logger.log('d', "[!] [#{pool}] '#{vm}' no longer exists. Removing from pending.") end - 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') - return if ! clone_stamp + return true if !clone_stamp time_since_clone = (Time.now - Time.parse(clone_stamp)) / 60 if time_since_clone > timeout @@ -63,8 +63,10 @@ module Vmpooler remove_nonexistent_vm(vm, pool) end end + true rescue => err $logger.log('d', "Fail pending VM failed with an error: #{err}") + false end def move_pending_vm_to_ready(vm, pool, host) diff --git a/spec/unit/pool_manager_spec.rb b/spec/unit/pool_manager_spec.rb index df17f5c..fcdee1d 100644 --- a/spec/unit/pool_manager_spec.rb +++ b/spec/unit/pool_manager_spec.rb @@ -114,19 +114,19 @@ EOT end 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) end it 'takes no action if VM is within timeout' do 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) end 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) - 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__completed__#{pool}", vm)).to be(true) end @@ -134,18 +134,18 @@ EOT it 'logs message if VM has exceeded timeout and exists' do 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(subject.fail_pending_vm(vm, pool, timeout,true)).to eq(nil) + expect(subject.fail_pending_vm(vm, pool, timeout,true)).to eq(true) end 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) 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 it 'swallows error if an error is raised' do 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 it 'logs message if an error is raised' do