mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
(POOLER-70) Update check_pending_vm for VM Provider
Previously the Pool Manager would use vSphere objects directly. This commit - Modifies the pool_manager to use the VM provider methods instead - Removes the open_socket method and tests as it is only required in the vSphere VM provider
This commit is contained in:
parent
4bf32be87e
commit
199bf4a070
2 changed files with 19 additions and 84 deletions
|
|
@ -37,8 +37,6 @@ EOT
|
|||
subject { Vmpooler::PoolManager.new(config, logger, redis, metrics) }
|
||||
|
||||
describe '#check_pending_vm' do
|
||||
let(:provider) { double('provider') }
|
||||
|
||||
before do
|
||||
expect(subject).not_to be_nil
|
||||
end
|
||||
|
|
@ -51,72 +49,14 @@ EOT
|
|||
end
|
||||
end
|
||||
|
||||
describe '#open_socket' do
|
||||
let(:TCPSocket) { double('tcpsocket') }
|
||||
let(:socket) { double('tcpsocket') }
|
||||
let(:hostname) { 'host' }
|
||||
let(:domain) { 'domain.local'}
|
||||
let(:default_socket) { 22 }
|
||||
|
||||
before do
|
||||
expect(subject).not_to be_nil
|
||||
allow(socket).to receive(:close)
|
||||
end
|
||||
|
||||
it 'opens socket with defaults' do
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_return(socket)
|
||||
|
||||
expect(subject.open_socket(hostname)).to eq(nil)
|
||||
end
|
||||
|
||||
it 'yields the socket if a block is given' do
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_return(socket)
|
||||
|
||||
expect{ |socket| subject.open_socket(hostname,nil,nil,default_socket,&socket) }.to yield_control.exactly(1).times
|
||||
end
|
||||
|
||||
it 'closes the opened socket' do
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_return(socket)
|
||||
expect(socket).to receive(:close)
|
||||
|
||||
expect(subject.open_socket(hostname)).to eq(nil)
|
||||
end
|
||||
|
||||
it 'opens a specific socket' do
|
||||
expect(TCPSocket).to receive(:new).with(hostname,80).and_return(socket)
|
||||
|
||||
expect(subject.open_socket(hostname,nil,nil,80)).to eq(nil)
|
||||
end
|
||||
|
||||
it 'uses a specific domain with the hostname' do
|
||||
expect(TCPSocket).to receive(:new).with("#{hostname}.#{domain}",default_socket).and_return(socket)
|
||||
|
||||
expect(subject.open_socket(hostname,domain)).to eq(nil)
|
||||
end
|
||||
|
||||
it 'raises error if host is not resolvable' do
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_raise(SocketError,'getaddrinfo: No such host is known')
|
||||
|
||||
expect { subject.open_socket(hostname,nil,1) }.to raise_error(SocketError)
|
||||
end
|
||||
|
||||
it 'raises error if socket is not listening' do
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_raise(SocketError,'No connection could be made because the target machine actively refused it')
|
||||
|
||||
expect { subject.open_socket(hostname,nil,1) }.to raise_error(SocketError)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#_check_pending_vm' do
|
||||
let(:provider) { double('provider') }
|
||||
|
||||
before do
|
||||
expect(subject).not_to be_nil
|
||||
end
|
||||
|
||||
context 'host does not exist or not in pool' do
|
||||
it 'calls fail_pending_vm' do
|
||||
expect(provider).to receive(:find_vm).and_return(nil)
|
||||
expect(provider).to receive(:get_vm).with(pool,vm).and_return(nil)
|
||||
expect(subject).to receive(:fail_pending_vm).with(vm, pool, timeout, false)
|
||||
|
||||
subject._check_pending_vm(vm, pool, timeout, provider)
|
||||
|
|
@ -124,17 +64,19 @@ EOT
|
|||
end
|
||||
|
||||
context 'host is in pool' do
|
||||
before do
|
||||
expect(provider).to receive(:get_vm).with(pool,vm).and_return(host)
|
||||
end
|
||||
|
||||
it 'calls move_pending_vm_to_ready if host is ready' do
|
||||
expect(provider).to receive(:find_vm).and_return(host)
|
||||
expect(subject).to receive(:open_socket).and_return(nil)
|
||||
expect(provider).to receive(:vm_ready?).with(pool,vm).and_return(true)
|
||||
expect(subject).to receive(:move_pending_vm_to_ready).with(vm, pool, host)
|
||||
|
||||
subject._check_pending_vm(vm, pool, timeout, provider)
|
||||
end
|
||||
|
||||
it 'calls fail_pending_vm if an error is raised' do
|
||||
expect(provider).to receive(:find_vm).and_return(host)
|
||||
expect(subject).to receive(:open_socket).and_raise(SocketError,'getaddrinfo: No such host is known')
|
||||
it 'calls fail_pending_vm if host is not ready' do
|
||||
expect(provider).to receive(:vm_ready?).with(pool,vm).and_return(false)
|
||||
expect(subject).to receive(:fail_pending_vm).with(vm, pool, timeout)
|
||||
|
||||
subject._check_pending_vm(vm, pool, timeout, provider)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue