Skip to content

Commit

Permalink
Merge pull request #266 from mattkirby/pooler_31
Browse files Browse the repository at this point in the history
(POOLER-31) Expire redis vm key when clone fails
  • Loading branch information
mchllweeks authored Jun 29, 2018
2 parents 8be5784 + 3a6e2a5 commit 0ce66eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/vmpooler/pool_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ def _clone_vm(pool, provider)

$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')
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/pool_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@

describe '#_clone_vm' do
let (:pool_object) { { 'name' => pool } }
let (:redis_ttl) { 1 }

before do
expect(subject).not_to be_nil
Expand All @@ -593,6 +594,8 @@
---
:config:
prefix: "prefix"
:redis:
ttl: #{redis_ttl}
EOT
)
}
Expand Down Expand Up @@ -664,6 +667,11 @@
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
Expand Down

0 comments on commit 0ce66eb

Please sign in to comment.