mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(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:
parent
de813943e9
commit
3a6e2a5cac
2 changed files with 11 additions and 1 deletions
|
|
@ -245,7 +245,9 @@ module Vmpooler
|
||||||
|
|
||||||
$metrics.timing("clone.#{pool_name}", finish)
|
$metrics.timing("clone.#{pool_name}", finish)
|
||||||
rescue => _err
|
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
|
raise _err
|
||||||
ensure
|
ensure
|
||||||
$redis.decr('vmpooler__tasks__clone')
|
$redis.decr('vmpooler__tasks__clone')
|
||||||
|
|
|
||||||
|
|
@ -583,6 +583,7 @@ EOT
|
||||||
|
|
||||||
describe '#_clone_vm' do
|
describe '#_clone_vm' do
|
||||||
let (:pool_object) { { 'name' => pool } }
|
let (:pool_object) { { 'name' => pool } }
|
||||||
|
let (:redis_ttl) { 1 }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
expect(subject).not_to be_nil
|
expect(subject).not_to be_nil
|
||||||
|
|
@ -593,6 +594,8 @@ EOT
|
||||||
---
|
---
|
||||||
:config:
|
:config:
|
||||||
prefix: "prefix"
|
prefix: "prefix"
|
||||||
|
:redis:
|
||||||
|
ttl: #{redis_ttl}
|
||||||
EOT
|
EOT
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -664,6 +667,11 @@ EOT
|
||||||
expect(redis.get('vmpooler__tasks__clone')).to eq('1')
|
expect(redis.get('vmpooler__tasks__clone')).to eq('1')
|
||||||
end
|
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
|
it 'should raise the error' do
|
||||||
expect{subject._clone_vm(pool_object,provider)}.to raise_error(/MockError/)
|
expect{subject._clone_vm(pool_object,provider)}.to raise_error(/MockError/)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue