mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Merge pull request #270 from mattkirby/no_duplicate_vms_in_pool
Do not run duplicate instances of inventory check for a pool
This commit is contained in:
commit
69f8b21ca8
2 changed files with 37 additions and 12 deletions
|
|
@ -710,6 +710,8 @@ module Vmpooler
|
|||
# INVENTORY
|
||||
inventory = {}
|
||||
begin
|
||||
mutex = pool_mutex(pool['name'])
|
||||
mutex.synchronize do
|
||||
provider.vms_in_pool(pool['name']).each do |vm|
|
||||
if !$redis.sismember('vmpooler__running__' + pool['name'], vm['name']) &&
|
||||
!$redis.sismember('vmpooler__ready__' + pool['name'], vm['name']) &&
|
||||
|
|
@ -726,6 +728,7 @@ module Vmpooler
|
|||
|
||||
inventory[vm['name']] = 1
|
||||
end
|
||||
end
|
||||
rescue => err
|
||||
$logger.log('s', "[!] [#{pool['name']}] _check_pool failed with an error while inspecting inventory: #{err}")
|
||||
return pool_check_response
|
||||
|
|
|
|||
|
|
@ -2693,6 +2693,7 @@ EOT
|
|||
let(:pool_object) { config[:pools][0] }
|
||||
let(:new_vm) { 'newvm'}
|
||||
let(:pool_name) { pool_object['name'] }
|
||||
let(:mutex) { Mutex.new }
|
||||
|
||||
before do
|
||||
expect(subject).not_to be_nil
|
||||
|
|
@ -2798,6 +2799,27 @@ EOT
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'should get the pool mutex' do
|
||||
expect(subject).to receive(:pool_mutex).and_return(mutex).at_least(:once)
|
||||
|
||||
subject._check_pool(pool_object,provider)
|
||||
end
|
||||
|
||||
it 'should run synchronize' do
|
||||
expect(subject).to receive(:pool_mutex).and_return(mutex).at_least(:once)
|
||||
expect(mutex).to receive(:synchronize).at_least(:once)
|
||||
|
||||
subject._check_pool(pool_object,provider)
|
||||
end
|
||||
|
||||
it 'should yield when locked' do
|
||||
expect(subject).to receive(:pool_mutex).and_return(mutex).at_least(:once)
|
||||
mutex.lock
|
||||
expect(mutex).to receive(:synchronize).and_yield
|
||||
|
||||
subject._check_pool(pool_object,provider)
|
||||
end
|
||||
end
|
||||
|
||||
# RUNNING
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue