mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-27 02:18:41 -05:00
Revert "Merge pull request #155 from shermdog/RE-7014-cinext"
This reverts commitcc03a86f6a, reversing changes made to5aaab7c5c2.
This commit is contained in:
parent
cc03a86f6a
commit
0fd6fff934
11 changed files with 26 additions and 251 deletions
|
|
@ -1,7 +1,3 @@
|
|||
require 'simplecov'
|
||||
SimpleCov.start do
|
||||
add_filter '/spec/'
|
||||
end
|
||||
require 'helpers'
|
||||
require 'rbvmomi'
|
||||
require 'rspec'
|
||||
|
|
|
|||
|
|
@ -180,7 +180,6 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
describe '/vm' do
|
||||
let(:redis) { double('redis') }
|
||||
let(:statsd) { double('stats') }
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:config) { {
|
||||
config: {
|
||||
|
|
@ -191,27 +190,20 @@ describe Vmpooler::API::V1 do
|
|||
{'name' => 'pool1', 'size' => 5},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
statsd: { 'prefix' => 'vmpooler' }
|
||||
alias: { 'poolone' => 'pool1' }
|
||||
} }
|
||||
|
||||
before do
|
||||
app.settings.set :config, config
|
||||
app.settings.set :redis, redis
|
||||
app.settings.set :statsd, statsd
|
||||
|
||||
allow(redis).to receive(:exists).with('vmpooler__token__abcdefghijklmnopqrstuvwxyz012345').and_return '1'
|
||||
allow(redis).to receive(:exists).with('vmpooler__ready__pool1').and_return '1'
|
||||
allow(redis).to receive(:exists).with('vmpooler__ready__pool2').and_return '1'
|
||||
allow(redis).to receive(:exists).and_return '1'
|
||||
allow(redis).to receive(:hget).with('vmpooler__token__abcdefghijklmnopqrstuvwxyz012345', 'user').and_return 'jdoe'
|
||||
allow(redis).to receive(:hset).and_return '1'
|
||||
allow(redis).to receive(:sadd).and_return '1'
|
||||
allow(redis).to receive(:scard).and_return '5'
|
||||
allow(redis).to receive(:spop).with('vmpooler__ready__pool1').and_return 'abcdefghijklmnop'
|
||||
allow(redis).to receive(:spop).with('vmpooler__ready__pool2').and_return 'qrstuvwxyz012345'
|
||||
allow(statsd).to receive(:increment).with('vmpooler.checkout.success.pool1', 1)
|
||||
allow(statsd).to receive(:increment).with('vmpooler.checkout.success.pool2', 1)
|
||||
allow(statsd).to receive(:increment).with('vmpooler.checkout.fail.pool2', 1)
|
||||
end
|
||||
|
||||
describe 'POST /vm' do
|
||||
|
|
@ -231,7 +223,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns a single VM for an alias' do
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__pool1").and_return(1)
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__poolone").and_return(false)
|
||||
|
||||
post "#{prefix}/vm", '{"poolone":"1"}'
|
||||
|
||||
|
|
@ -249,22 +241,12 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
it 'fails on nonexistent pools' do
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__poolpoolpool").and_return(false)
|
||||
expect(redis).to receive(:exists).with("vmpooler__empty__poolpoolpool").and_return(false)
|
||||
expect(statsd).to receive(:increment).with('vmpooler.checkout.invalid', 1)
|
||||
|
||||
post "#{prefix}/vm", '{"poolpoolpool":"1"}'
|
||||
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
it 'fails on empty pools' do
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__emptypool").and_return(false)
|
||||
expect(redis).to receive(:exists).with("vmpooler__empty__emptypool").and_return(true)
|
||||
expect(statsd).to receive(:increment).with('vmpooler.checkout.empty', 1)
|
||||
post "#{prefix}/vm", '{"emptypool":"1"}'
|
||||
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
it 'returns multiple VMs' do
|
||||
post "#{prefix}/vm", '{"pool1":"1","pool2":"1"}'
|
||||
|
||||
|
|
@ -464,7 +446,6 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
describe '/vm/:template' do
|
||||
let(:redis) { double('redis') }
|
||||
let(:statsd) { double('stats') }
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:config) { {
|
||||
config: {
|
||||
|
|
@ -475,27 +456,20 @@ describe Vmpooler::API::V1 do
|
|||
{'name' => 'pool1', 'size' => 5},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
statsd: { 'prefix' => 'vmpooler' }
|
||||
alias: { 'poolone' => 'pool1' }
|
||||
} }
|
||||
|
||||
before do
|
||||
app.settings.set :config, config
|
||||
app.settings.set :redis, redis
|
||||
app.settings.set :statsd, statsd
|
||||
|
||||
allow(redis).to receive(:exists).with('vmpooler__token__abcdefghijklmnopqrstuvwxyz012345').and_return '1'
|
||||
allow(redis).to receive(:exists).with('vmpooler__ready__pool1').and_return '1'
|
||||
allow(redis).to receive(:exists).with('vmpooler__ready__pool2').and_return '1'
|
||||
allow(redis).to receive(:exists).and_return '1'
|
||||
allow(redis).to receive(:hget).with('vmpooler__token__abcdefghijklmnopqrstuvwxyz012345', 'user').and_return 'jdoe'
|
||||
allow(redis).to receive(:hset).and_return '1'
|
||||
allow(redis).to receive(:sadd).and_return '1'
|
||||
allow(redis).to receive(:scard).and_return '5'
|
||||
allow(redis).to receive(:spop).with('vmpooler__ready__pool1').and_return 'abcdefghijklmnop'
|
||||
allow(redis).to receive(:spop).with('vmpooler__ready__pool2').and_return 'qrstuvwxyz012345'
|
||||
allow(statsd).to receive(:increment).with('vmpooler.checkout.success.pool1', 1)
|
||||
allow(statsd).to receive(:increment).with('vmpooler.checkout.success.pool2', 1)
|
||||
allow(statsd).to receive(:increment).with('vmpooler.checkout.fail.pool2', 1)
|
||||
end
|
||||
|
||||
describe 'POST /vm/:template' do
|
||||
|
|
@ -515,7 +489,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns a single VM for an alias' do
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__pool1").and_return(1)
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__poolone").and_return(false)
|
||||
|
||||
post "#{prefix}/vm/poolone", ''
|
||||
|
||||
|
|
@ -533,23 +507,12 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
it 'fails on nonexistent pools' do
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__poolpoolpool").and_return(false)
|
||||
expect(redis).to receive(:exists).with("vmpooler__empty__poolpoolpool").and_return(false)
|
||||
expect(statsd).to receive(:increment).with('vmpooler.checkout.invalid', 1)
|
||||
|
||||
post "#{prefix}/vm/poolpoolpool", ''
|
||||
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
it 'fails on empty pools' do
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__emptypool").and_return(false)
|
||||
expect(redis).to receive(:exists).with("vmpooler__empty__emptypool").and_return(true)
|
||||
expect(statsd).to receive(:increment).with('vmpooler.checkout.empty', 1)
|
||||
post "#{prefix}/vm/emptypool", ''
|
||||
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
it 'returns multiple VMs' do
|
||||
post "#{prefix}/vm/pool1+pool2", ''
|
||||
|
||||
|
|
|
|||
|
|
@ -5,12 +5,13 @@ describe 'Pool Manager' do
|
|||
let(:logger) { double('logger') }
|
||||
let(:redis) { double('redis') }
|
||||
let(:config) { {} }
|
||||
let(:graphite) { nil }
|
||||
let(:pool) { 'pool1' }
|
||||
let(:vm) { 'vm1' }
|
||||
let(:timeout) { 5 }
|
||||
let(:host) { double('host') }
|
||||
|
||||
subject { Vmpooler::PoolManager.new(config, logger, redis) }
|
||||
subject { Vmpooler::PoolManager.new(config, logger, redis, graphite) }
|
||||
|
||||
describe '#_check_pending_vm' do
|
||||
let(:pool_helper) { double('pool') }
|
||||
|
|
@ -251,86 +252,6 @@ describe 'Pool Manager' do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#_stats_running_ready' do
|
||||
let(:pool_helper) { double('pool') }
|
||||
let(:vsphere) { {pool => pool_helper} }
|
||||
let(:graphite) { double('graphite') }
|
||||
let(:config) { {
|
||||
config: { task_limit: 10 },
|
||||
pools: [ {'name' => 'pool1', 'size' => 5} ],
|
||||
graphite: { 'prefix' => 'vmpooler' }
|
||||
} }
|
||||
|
||||
before do
|
||||
expect(subject).not_to be_nil
|
||||
$vsphere = vsphere
|
||||
allow(logger).to receive(:log)
|
||||
allow(pool_helper).to receive(:find_folder)
|
||||
allow(redis).to receive(:smembers).and_return([])
|
||||
allow(redis).to receive(:set)
|
||||
allow(redis).to receive(:get).with('vmpooler__tasks__clone').and_return(0)
|
||||
allow(redis).to receive(:get).with('vmpooler__empty__pool1').and_return(nil)
|
||||
end
|
||||
|
||||
context 'graphite' do
|
||||
let(:graphite) { double('graphite') }
|
||||
subject { Vmpooler::PoolManager.new(config, logger, redis, graphite) }
|
||||
|
||||
it 'increments graphite when enabled and statsd disabled' do
|
||||
allow(redis).to receive(:scard).with('vmpooler__ready__pool1').and_return(1)
|
||||
allow(redis).to receive(:scard).with('vmpooler__cloning__pool1').and_return(0)
|
||||
allow(redis).to receive(:scard).with('vmpooler__pending__pool1').and_return(0)
|
||||
allow(redis).to receive(:scard).with('vmpooler__running__pool1').and_return(5)
|
||||
|
||||
expect(graphite).to receive(:log).with('vmpooler.ready.pool1', 1)
|
||||
expect(graphite).to receive(:log).with('vmpooler.running.pool1', 5)
|
||||
subject._check_pool(config[:pools][0])
|
||||
end
|
||||
|
||||
it 'increments graphite when ready with 0 when pool empty and statsd disabled' do
|
||||
allow(redis).to receive(:scard).with('vmpooler__ready__pool1').and_return(0)
|
||||
allow(redis).to receive(:scard).with('vmpooler__cloning__pool1').and_return(0)
|
||||
allow(redis).to receive(:scard).with('vmpooler__pending__pool1').and_return(0)
|
||||
allow(redis).to receive(:scard).with('vmpooler__running__pool1').and_return(5)
|
||||
|
||||
expect(graphite).to receive(:log).with('vmpooler.ready.pool1', 0)
|
||||
expect(graphite).to receive(:log).with('vmpooler.running.pool1', 5)
|
||||
subject._check_pool(config[:pools][0])
|
||||
end
|
||||
end
|
||||
|
||||
context 'statsd' do
|
||||
let(:statsd) { double('statsd') }
|
||||
let(:config) { {
|
||||
config: { task_limit: 10 },
|
||||
pools: [ {'name' => 'pool1', 'size' => 5} ],
|
||||
statsd: { 'prefix' => 'vmpooler' }
|
||||
} }
|
||||
subject { Vmpooler::PoolManager.new(config, logger, redis, graphite, statsd) }
|
||||
|
||||
it 'increments statsd when configured' do
|
||||
allow(redis).to receive(:scard).with('vmpooler__ready__pool1').and_return(1)
|
||||
allow(redis).to receive(:scard).with('vmpooler__cloning__pool1').and_return(0)
|
||||
allow(redis).to receive(:scard).with('vmpooler__pending__pool1').and_return(0)
|
||||
allow(redis).to receive(:scard).with('vmpooler__running__pool1').and_return(5)
|
||||
|
||||
expect(statsd).to receive(:gauge).with('vmpooler.ready.pool1', 1)
|
||||
expect(statsd).to receive(:gauge).with('vmpooler.running.pool1', 5)
|
||||
subject._check_pool(config[:pools][0])
|
||||
end
|
||||
|
||||
it 'increments statsd ready with 0 when pool empty' do
|
||||
allow(redis).to receive(:scard).with('vmpooler__running__pool1').and_return(1)
|
||||
allow(redis).to receive(:scard).with('vmpooler__ready__pool1').and_return(0)
|
||||
allow(redis).to receive(:scard).with('vmpooler__pending__pool1').and_return(0)
|
||||
allow(statsd).to receive(:gauge).with('vmpooler.running.pool1', 1)
|
||||
|
||||
expect(statsd).to receive(:gauge).with('vmpooler.ready.pool1', 0)
|
||||
subject._check_pool(config[:pools][0])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#_create_vm_snapshot' do
|
||||
let(:snapshot_manager) { 'snapshot_manager' }
|
||||
let(:pool_helper) { double('snapshot_manager') }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue