Merge pull request #292 from mattkirby/remove_mutex_on_destroy

(POOLER-128) Remove references to VM mutex when destroying
This commit is contained in:
mchllweeks 2018-07-24 16:18:04 -07:00 committed by GitHub
commit 10efddd43e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

View file

@ -13,6 +13,10 @@ git logs & PR history.
# [Unreleased](https://github.com/puppetlabs/vmpooler/compare/0.1.0...master) # [Unreleased](https://github.com/puppetlabs/vmpooler/compare/0.1.0...master)
### Fixed
- (POOLER-128) VM specific mutex objects are not dereferenced when a VM is destroyed
# [0.1.0](https://github.com/puppetlabs/vmpooler/compare/4c858d012a262093383e57ea6db790521886d8d4...master) # [0.1.0](https://github.com/puppetlabs/vmpooler/compare/4c858d012a262093383e57ea6db790521886d8d4...master)
### Fixed ### Fixed

View file

@ -313,6 +313,7 @@ module Vmpooler
$logger.log('s', "[-] [#{pool}] '#{vm}' destroyed in #{finish} seconds") $logger.log('s', "[-] [#{pool}] '#{vm}' destroyed in #{finish} seconds")
$metrics.timing("destroy.#{pool}", finish) $metrics.timing("destroy.#{pool}", finish)
end end
dereference_mutex(vm)
end end
def purge_unused_vms_and_folders def purge_unused_vms_and_folders
@ -681,6 +682,14 @@ module Vmpooler
@vm_mutex[vmname] || @vm_mutex[vmname] = Mutex.new @vm_mutex[vmname] || @vm_mutex[vmname] = Mutex.new
end end
def dereference_mutex(vmname)
if @vm_mutex.delete(vmname)
return true
else
return
end
end
def sync_pool_template(pool) def sync_pool_template(pool)
pool_template = $redis.hget('vmpooler__config__template', pool['name']) pool_template = $redis.hget('vmpooler__config__template', pool['name'])
if pool_template if pool_template

View file

@ -726,6 +726,12 @@ EOT
subject._destroy_vm(vm,pool,provider) subject._destroy_vm(vm,pool,provider)
end end
it 'should dereference the mutex' do
expect(subject).to receive(:dereference_mutex)
subject._destroy_vm(vm,pool,provider)
end
end end
context 'when the VM destruction raises an eror' do context 'when the VM destruction raises an eror' do
@ -1690,6 +1696,26 @@ EOT
end end
end end
describe '#dereference_mutex' do
it 'should return nil when no mutex is dereferenced' do
expect(subject.dereference_mutex(vm)).to be_nil
end
it 'should return true when a mutex is dereferenced' do
subject.vm_mutex(vm)
expect(subject.dereference_mutex(vm)).to be true
end
it 'should dereference the mutex' do
mutex = subject.vm_mutex(vm)
subject.dereference_mutex(vm)
result = subject.vm_mutex(vm)
expect(result).to_not eq(mutex)
end
end
describe 'sync_pool_template' do describe 'sync_pool_template' do
let(:old_template) { 'templates/old-template' } let(:old_template) { 'templates/old-template' }
let(:new_template) { 'templates/new-template' } let(:new_template) { 'templates/new-template' }