mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(POOLER-70) Update check_pool for VM Provider
Previously the Pool Manager would use a single VM provider per Pool. This commit changes Pool Manager to use a single provider that services multiple pools.
This commit is contained in:
parent
3f6ead8134
commit
7c3ad716af
2 changed files with 22 additions and 28 deletions
|
|
@ -522,18 +522,24 @@ module Vmpooler
|
||||||
def check_pool(pool, maxloop = 0, loop_delay = 5)
|
def check_pool(pool, maxloop = 0, loop_delay = 5)
|
||||||
$logger.log('d', "[*] [#{pool['name']}] starting worker thread")
|
$logger.log('d', "[*] [#{pool['name']}] starting worker thread")
|
||||||
|
|
||||||
$providers[pool['name']] ||= Vmpooler::VsphereHelper.new $config, $metrics
|
|
||||||
|
|
||||||
$threads[pool['name']] = Thread.new do
|
$threads[pool['name']] = Thread.new do
|
||||||
loop_count = 1
|
begin
|
||||||
loop do
|
loop_count = 1
|
||||||
_check_pool(pool, $providers[pool['name']])
|
provider = get_provider_for_pool(pool['name'])
|
||||||
sleep(loop_delay)
|
raise("Could not find provider '#{pool['provider']}") if provider.nil?
|
||||||
|
loop do
|
||||||
|
_check_pool(pool, provider)
|
||||||
|
|
||||||
unless maxloop.zero?
|
sleep(loop_delay)
|
||||||
break if loop_count >= maxloop
|
|
||||||
loop_count += 1
|
unless maxloop.zero?
|
||||||
|
break if loop_count >= maxloop
|
||||||
|
loop_count += 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
rescue => err
|
||||||
|
$logger.log('s', "[!] [#{pool['name']}] Error while checking the pool: #{err}")
|
||||||
|
raise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1855,48 +1855,40 @@ EOT
|
||||||
|
|
||||||
describe "#check_pool" do
|
describe "#check_pool" do
|
||||||
let(:threads) {{}}
|
let(:threads) {{}}
|
||||||
let(:provider) {{}}
|
let(:provider_name) { 'mock_provider' }
|
||||||
|
|
||||||
let(:config) {
|
let(:config) {
|
||||||
YAML.load(<<-EOT
|
YAML.load(<<-EOT
|
||||||
---
|
---
|
||||||
:pools:
|
:pools:
|
||||||
- name: #{pool}
|
- name: #{pool}
|
||||||
|
provider: #{provider_name}
|
||||||
EOT
|
EOT
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:thread) { double('thread') }
|
|
||||||
let(:pool_object) { config[:pools][0] }
|
let(:pool_object) { config[:pools][0] }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
expect(subject).not_to be_nil
|
expect(subject).not_to be_nil
|
||||||
expect(Thread).to receive(:new).and_yield
|
expect(Thread).to receive(:new).and_yield
|
||||||
|
allow(subject).to receive(:get_provider_for_pool).with(pool).and_return(provider)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on startup' do
|
context 'on startup' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
# Note the Vmpooler::VsphereHelper is not mocked
|
allow(subject).to receive(:_check_pool)
|
||||||
allow(subject).to receive(:_check_pool)
|
|
||||||
expect(logger).to receive(:log).with('d', "[*] [#{pool}] starting worker thread")
|
expect(logger).to receive(:log).with('d', "[*] [#{pool}] starting worker thread")
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:each) do
|
after(:each) do
|
||||||
# Reset the global variable - Note this is a code smell
|
# Reset the global variable - Note this is a code smell
|
||||||
$threads = nil
|
$threads = nil
|
||||||
$providers = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should log a message the worker thread is starting' do
|
it 'should log a message the worker thread is starting' do
|
||||||
subject.check_pool(pool_object,1,0)
|
subject.check_pool(pool_object,1,0)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should populate the providers global variable' do
|
|
||||||
subject.check_pool(pool_object,1,0)
|
|
||||||
|
|
||||||
expect($providers[pool]).to_not be_nil
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should populate the threads global variable' do
|
it 'should populate the threads global variable' do
|
||||||
subject.check_pool(pool_object,1,0)
|
subject.check_pool(pool_object,1,0)
|
||||||
|
|
||||||
|
|
@ -1913,22 +1905,18 @@ EOT
|
||||||
before(:each) do
|
before(:each) do
|
||||||
allow(logger).to receive(:log)
|
allow(logger).to receive(:log)
|
||||||
# Note the Vmpooler::VsphereHelper is not mocked
|
# Note the Vmpooler::VsphereHelper is not mocked
|
||||||
allow(subject).to receive(:_check_pool)
|
allow(subject).to receive(:_check_pool)
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:each) do
|
after(:each) do
|
||||||
# Reset the global variable - Note this is a code smell
|
# Reset the global variable - Note this is a code smell
|
||||||
$threads = nil
|
$threads = nil
|
||||||
$provider = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'when a non-default loop delay is specified' do
|
it 'when a non-default loop delay is specified' do
|
||||||
start_time = Time.now
|
expect(subject).to receive(:sleep).with(loop_delay).exactly(maxloop).times
|
||||||
subject.check_pool(pool_object,maxloop,loop_delay)
|
|
||||||
finish_time = Time.now
|
|
||||||
|
|
||||||
# Use a generous delta to take into account various CPU load etc.
|
subject.check_pool(pool_object,maxloop,loop_delay)
|
||||||
expect(finish_time - start_time).to be_within(0.75).of(maxloop * loop_delay)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue