Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like redis is taking seconds for this value, so data_ttl is in units of hours? Can this be documented somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there is a mention of this in the example configuration file https://github.com/puppetlabs/vmpooler/blob/master/vmpooler.yaml.example#L180 .

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

$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