Fix up tests to pass with additions

This commit is contained in:
kirby@puppetlabs.com 2018-05-23 13:56:22 -07:00
parent ddecb8b8d0
commit c8426b0076
2 changed files with 34 additions and 22 deletions

View file

@ -617,18 +617,20 @@ module Vmpooler
end end
def remove_excess_vms(pool, provider, ready, total) def remove_excess_vms(pool, provider, ready, total)
unless total == 0 if total
mutex = @reconfigure_pool[pool['name']] || @reconfigure_pool[pool['name']] = Mutex.new unless total == 0
mutex.synchronize do mutex = @reconfigure_pool[pool['name']] || @reconfigure_pool[pool['name']] = Mutex.new
if total > pool['size'] mutex.synchronize do
difference = ready - pool['size'] if total > pool['size']
difference.times do difference = ready - pool['size']
next_vm = $redis.spop("vmpooler__ready__#{pool['name']}") difference.times do
move_vm_queue(pool['name'], next_vm, 'ready', 'completed') next_vm = $redis.spop("vmpooler__ready__#{pool['name']}")
end move_vm_queue(pool['name'], next_vm, 'ready', 'completed')
if total > ready end
$redis.smembers("vmpooler__pending__#{pool['name']}").each do |vm| if total > ready
move_vm_queue(pool['name'], vm, 'pending', 'completed') $redis.smembers("vmpooler__pending__#{pool['name']}").each do |vm|
move_vm_queue(pool['name'], vm, 'pending', 'completed')
end
end end
end end
end end

View file

@ -1581,11 +1581,17 @@ EOT
end end
it 'should log a message for removing ready vms' do it 'should log a message for removing ready vms' do
expect(logger).to receive(:log).with('s', "[*] [#{pool}] removing ready instances")
expect(logger).to receive(:log).with('s', "[*] [#{pool}] removing ready and pending instances")
subject.update_pool_template(config[:pools][0], provider) subject.update_pool_template(config[:pools][0], provider)
end end
it 'should log a message for removing pending vms' do
expect(logger).to receive(:log).with('s', "[*] [#{pool}] removing pending instances")
subject.update_pool_template(config[:pools][0], provider)
end
it 'should remove ready vms' do it 'should remove ready vms' do
expect(redis).to receive(:smove).with("vmpooler__ready__#{pool}", "vmpooler__completed__#{pool}", vmname) expect(redis).to receive(:smove).with("vmpooler__ready__#{pool}", "vmpooler__completed__#{pool}", vmname)
@ -1627,23 +1633,29 @@ EOT
expect(subject).not_to be_nil expect(subject).not_to be_nil
end end
context 'with a nil ready value' do context 'with a 0 total value' do
let(:ready) { 0 }
let(:total) { 0 }
it 'should return nil' do it 'should return nil' do
expect(subject.remove_excess_vms(config[:pools][0], provider, nil, nil)).to be_nil expect(subject.remove_excess_vms(config[:pools][0], provider, ready, total)).to be_nil
end end
end end
context 'with a total size less than the pool size' do context 'with a total size less than the pool size' do
let(:ready) { 1 }
let(:total) { 2 }
it 'should return nil' do it 'should return nil' do
expect(subject.remove_excess_vms(config[:pools][0], provider, 1, 2)).to be_nil expect(subject.remove_excess_vms(config[:pools][0], provider, ready, total)).to be_nil
end end
end end
context 'with a total size greater than the pool size' do context 'with a total size greater than the pool size' do
let(:ready) { 4 }
let(:total) { 4 }
it 'should remove excess ready vms' do it 'should remove excess ready vms' do
expect(subject).to receive(:move_vm_queue).exactly(2).times expect(subject).to receive(:move_vm_queue).exactly(2).times
subject.remove_excess_vms(config[:pools][0], provider, 4, 4) subject.remove_excess_vms(config[:pools][0], provider, ready, total)
end end
it 'should remove excess pending vms' do it 'should remove excess pending vms' do
@ -3018,18 +3030,16 @@ EOT
end end
context 'when a pool template is updating' do context 'when a pool template is updating' do
let(:poolsize) { 2 }
before(:each) do before(:each) do
redis.hset('vmpooler__config__updating', pool, 1) redis.hset('vmpooler__config__updating', pool, 1)
expect(provider).to receive(:vms_in_pool).with(pool).and_return([]) expect(provider).to receive(:vms_in_pool).with(pool).and_return([])
end end
it 'should not call clone_vm to populate the pool' do it 'should not call clone_vm to populate the pool' do
pool_size = 5
config[:pools][0]['size'] = pool_size
expect(subject).to_not receive(:clone_vm) expect(subject).to_not receive(:clone_vm)
subject._check_pool(pool_object,provider) subject._check_pool(config[:pools][0],provider)
end end
end end