mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
(POOLER-153) Add endpoint for resetting a pool
This commit adds a capability to vmpooler to reset a pool, deleting its ready and pending instances and replacing them with fresh ones. Without this change vmpooler does not offer a mechanism to reset a pool without also changing its template.
This commit is contained in:
parent
3732ed750e
commit
52b60b074c
5 changed files with 237 additions and 1 deletions
117
spec/integration/api/v1/poolreset.rb
Normal file
117
spec/integration/api/v1/poolreset.rb
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V1 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
Vmpooler::API
|
||||
end
|
||||
|
||||
let(:config) {
|
||||
{
|
||||
config: {
|
||||
'site_name' => 'test pooler',
|
||||
'vm_lifetime_auth' => 2,
|
||||
'experimental_features' => true
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5, 'template' => 'templates/pool1', 'clone_target' => 'default_cluster'},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
pool_names: [ 'pool1', 'pool2', 'poolone' ]
|
||||
}
|
||||
}
|
||||
|
||||
describe '/poolreset' do
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:metrics) { Vmpooler::DummyStatsd.new }
|
||||
|
||||
let(:current_time) { Time.now }
|
||||
|
||||
before(:each) do
|
||||
app.settings.set :config, config
|
||||
app.settings.set :redis, redis
|
||||
app.settings.set :metrics, metrics
|
||||
app.settings.set :config, auth: false
|
||||
create_token('abcdefghijklmnopqrstuvwxyz012345', 'jdoe', current_time)
|
||||
end
|
||||
|
||||
describe 'POST /poolreset' do
|
||||
it 'refreshes ready and pending instances from a pool' do
|
||||
post "#{prefix}/poolreset", '{"pool1":"1"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails on nonexistent pools' do
|
||||
post "#{prefix}/poolreset", '{"poolpoolpool":"1"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
end
|
||||
|
||||
it 'resets multiple pools' do
|
||||
post "#{prefix}/poolreset", '{"pool1":"1","pool2":"1"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when not all pools exist' do
|
||||
post "#{prefix}/poolreset", '{"pool1":"1","pool3":"1"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expected = {
|
||||
ok: false,
|
||||
bad_pools: ['pool3']
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
context 'with experimental features disabled' do
|
||||
before(:each) do
|
||||
config[:config]['experimental_features'] = false
|
||||
end
|
||||
|
||||
it 'should return 405' do
|
||||
post "#{prefix}/poolreset", '{"pool1":"1"}'
|
||||
expect_json(ok = false, http = 405)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
|
||||
it 'should return 400 for invalid json' do
|
||||
post "#{prefix}/poolreset", '{"pool1":"1}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'should return 400 with a bad pool name' do
|
||||
post "#{prefix}/poolreset", '{"pool11":"1"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'should return 404 when there is no payload' do
|
||||
post "#{prefix}/poolreset"
|
||||
expect_json(ok = false, http = 404)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -2874,6 +2874,28 @@ EOT
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with the pool_reset wakeup option' do
|
||||
let(:wakeup_option) {{
|
||||
:pool_reset => true,
|
||||
:poolname => pool
|
||||
}}
|
||||
|
||||
let(:wakeup_period) { -1 } # A negative number forces the wakeup evaluation to always occur
|
||||
|
||||
context 'when a pool reset is requested' do
|
||||
before(:each) do
|
||||
redis.sadd('vmpooler__poolreset', pool)
|
||||
end
|
||||
|
||||
it 'should sleep until the reset request is detected' do
|
||||
expect(subject).to receive(:sleep).exactly(3).times
|
||||
expect(redis).to receive(:sismember).with('vmpooler__poolreset', pool).and_return(false,false,true)
|
||||
|
||||
subject.sleep_with_wakeup_events(loop_delay, wakeup_period, wakeup_option)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#check_pool" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue