(POOLER-31) Expire redis vm key when clone fails

This commit updates pool_manager to expire a redis VM key when a clone fails. Without this change VMs that fail to clone have their metadata left forever.
This commit is contained in:
kirby@puppetlabs.com 2018-06-20 17:27:31 -07:00
parent de813943e9
commit 3a6e2a5cac
2 changed files with 11 additions and 1 deletions

View file

@ -245,7 +245,9 @@ module Vmpooler
$metrics.timing("clone.#{pool_name}", finish)
rescue => _err
$redis.srem('vmpooler__pending__' + pool_name, new_vmname)
$redis.srem("vmpooler__pending__#{pool_name}", new_vmname)
expiration_ttl = $config[:redis]['data_ttl'].to_i * 60 * 60
$redis.expire("vmpooler__vm__#{new_vmname}", expiration_ttl)
raise _err
ensure
$redis.decr('vmpooler__tasks__clone')

View file

@ -583,6 +583,7 @@ EOT
describe '#_clone_vm' do
let (:pool_object) { { 'name' => pool } }
let (:redis_ttl) { 1 }
before do
expect(subject).not_to be_nil
@ -593,6 +594,8 @@ EOT
---
:config:
prefix: "prefix"
:redis:
ttl: #{redis_ttl}
EOT
)
}
@ -664,6 +667,11 @@ EOT
expect(redis.get('vmpooler__tasks__clone')).to eq('1')
end
it 'should expire the vm metadata' do
expect(redis).to receive(:expire)
expect{subject._clone_vm(pool_object,provider)}.to raise_error(/MockError/)
end
it 'should raise the error' do
expect{subject._clone_vm(pool_object,provider)}.to raise_error(/MockError/)
end