Fixing method remove_excess_vms

Before this fix, if the pool had an excessive number of 'pending' vms,
but was not full of 'ready' vms, we would end up clearing all the
'pending' vms regardless, which could bring us back under the max
pool size. This fix makes sure we only remove the excess, see
unit test for an example
This commit is contained in:
Samuel Beaulieu 2018-05-30 16:54:43 -05:00
parent 045a85183f
commit d95e486c8c
2 changed files with 14 additions and 1 deletions

View file

@ -631,8 +631,10 @@ module Vmpooler
move_vm_queue(pool['name'], next_vm, 'ready', 'completed')
end
if total > ready
$redis.smembers("vmpooler__pending__#{pool['name']}").each do |vm|
max_to_remove = total - pool['size']
$redis.smembers("vmpooler__pending__#{pool['name']}").each_with_index do |vm, i|
move_vm_queue(pool['name'], vm, 'pending', 'completed')
if max_to_remove == (i+1) then break end
end
end
end

View file

@ -1669,9 +1669,20 @@ EOT
subject.remove_excess_vms(config[:pools][0], provider, 2, 5)
end
it 'should remove excess pending vms, but only the excess' do
create_pending_vm(pool,'vm1')
create_pending_vm(pool,'vm2')
create_pending_vm(pool,'vm3')
create_pending_vm(pool,'vm4')
expect(subject).to receive(:move_vm_queue).exactly(3).times
subject.remove_excess_vms(config[:pools][0], provider, 1, 5)
end
end
end
describe 'prepare_template' do
let(:mutex) { Mutex.new }
let(:config) { YAML.load(<<-EOT