mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Fix up tests to pass with additions
This commit is contained in:
parent
ddecb8b8d0
commit
c8426b0076
2 changed files with 34 additions and 22 deletions
|
|
@ -617,6 +617,7 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_excess_vms(pool, provider, ready, total)
|
def remove_excess_vms(pool, provider, ready, total)
|
||||||
|
if total
|
||||||
unless total == 0
|
unless total == 0
|
||||||
mutex = @reconfigure_pool[pool['name']] || @reconfigure_pool[pool['name']] = Mutex.new
|
mutex = @reconfigure_pool[pool['name']] || @reconfigure_pool[pool['name']] = Mutex.new
|
||||||
mutex.synchronize do
|
mutex.synchronize do
|
||||||
|
|
@ -635,6 +636,7 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def _check_pool(pool, provider)
|
def _check_pool(pool, provider)
|
||||||
pool_check_response = {
|
pool_check_response = {
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue