diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index dfd98ab..386182c 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -661,7 +661,9 @@ module Vmpooler $logger.log('s', "[*] [#{pool['name']}] is ready for use") end - def remove_excess_vms(pool, provider, ready, total) + def remove_excess_vms(pool) + ready = $redis.scard("vmpooler__ready__#{pool['name']}") + total = $redis.scard("vmpooler__pending__#{pool['name']}") + ready return if total.nil? return if total == 0 mutex = pool_mutex(pool['name']) @@ -893,11 +895,8 @@ module Vmpooler repopulate_pool_vms(pool['name'], provider, pool_check_response, pool['size']) - # query redis again until we refactor remove_excess_vms, duplicate of a line moved to refactored method repopulate_pool_vms - ready = $redis.scard("vmpooler__ready__#{pool['name']}") - total = $redis.scard("vmpooler__pending__#{pool['name']}") + ready # Remove VMs in excess of the configured pool size - remove_excess_vms(pool, provider, ready, total) + remove_excess_vms(pool) pool_check_response end diff --git a/spec/unit/pool_manager_spec.rb b/spec/unit/pool_manager_spec.rb index e799e92..ec425dd 100644 --- a/spec/unit/pool_manager_spec.rb +++ b/spec/unit/pool_manager_spec.rb @@ -3215,21 +3215,6 @@ EOT # end end - context 'when an excess number of ready vms exist' do - - before(:each) do - allow(redis).to receive(:scard) - expect(redis).to receive(:scard).with("vmpooler__ready__#{pool}").and_return(1) - expect(redis).to receive(:scard).with("vmpooler__pending__#{pool}").and_return(1) - end - - it 'should call remove_excess_vms' do - expect(subject).to receive(:remove_excess_vms).with(config[:pools][0], provider, 1, 2) - - subject._check_pool(config[:pools][0],provider) - end - end - context 'export metrics' do it 'increments metrics for ready queue' do create_ready_vm(pool,'vm1') @@ -3557,6 +3542,23 @@ EOT end end + #remove_excess_vms + context 'when an excess number of ready vms exist' do + + before(:each) do + allow(redis).to receive(:scard) + expect(redis).to receive(:scard).with("vmpooler__ready__#{pool}").and_return(1) + expect(redis).to receive(:scard).with("vmpooler__pending__#{pool}").and_return(1) + end + + it 'should call remove_excess_vms' do + allow(subject).to receive(:create_inventory).and_return({}) + expect(subject).to receive(:remove_excess_vms).with(config[:pools][0]) + + subject._check_pool(config[:pools][0],provider) + end + end + #