mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
(DIO-2675) Undo pool size template overrides
This implements a delete method for pooltemplate and poolsize. The API removes the override from Redis and then adds an entry in Redis that causes the pool manager to wake up and process the removal of the override. To facilitate this, a new variable has been created in lib/vmpooler.rb to hold a copy of the original / pre-override config. This supplemental copy of the pools is then indexed for use as a reference. When pool manager wakes up to process an override removal, it looks up the pre-override value from the config via the new variables mentioned above. Just as with entering overrides, no restart is needed. Template and pool size changes are logged so that anyone watching or reviewing the logs can see what happened when. The new API endpoints also return values for both the pre-revert and post-revert value.
This commit is contained in:
parent
6db71d8589
commit
a0caa41a54
7 changed files with 409 additions and 6 deletions
|
|
@ -26,6 +26,10 @@ describe Vmpooler::API::V1 do
|
|||
{'name' => 'pool1', 'size' => 5, 'template' => 'templates/pool1', 'clone_target' => 'default_cluster'},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
pools_at_startup: [
|
||||
{'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' ]
|
||||
|
|
@ -45,6 +49,47 @@ describe Vmpooler::API::V1 do
|
|||
create_token('abcdefghijklmnopqrstuvwxyz012345', 'jdoe', current_time)
|
||||
end
|
||||
|
||||
describe 'DELETE /config/pooltemplate/:pool' do
|
||||
it 'resets a pool template' do
|
||||
post "#{prefix}/config/pooltemplate", '{"pool1":"templates/new_template"}'
|
||||
delete "#{prefix}/config/pooltemplate/pool1"
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
template_before_reset: 'templates/new_template',
|
||||
template_before_overrides: 'templates/pool1'
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'succeeds when the pool has not been overridden' do
|
||||
delete "#{prefix}/config/pooltemplate/pool1"
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
|
||||
it 'fails on nonexistent pools' do
|
||||
delete "#{prefix}/config/pooltemplate/poolpoolpool"
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
context 'with experimental features disabled' do
|
||||
before(:each) do
|
||||
config[:config]['experimental_features'] = false
|
||||
end
|
||||
|
||||
it 'should return 405' do
|
||||
delete "#{prefix}/config/pooltemplate/pool1"
|
||||
expect_json(ok = false, http = 405)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'POST /config/pooltemplate' do
|
||||
it 'updates a pool template' do
|
||||
post "#{prefix}/config/pooltemplate", '{"pool1":"templates/new_template"}'
|
||||
|
|
@ -142,6 +187,56 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
end
|
||||
|
||||
describe 'DELETE /config/poolsize' do
|
||||
it 'resets a pool size' do
|
||||
post "#{prefix}/config/poolsize", '{"pool1":"2"}'
|
||||
delete "#{prefix}/config/poolsize/pool1"
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool_size_before_reset: 2,
|
||||
pool_size_before_overrides: 5
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when a specified pool does not exist' do
|
||||
delete "#{prefix}/config/poolsize/pool10"
|
||||
expect_json(ok = false, http = 404)
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'succeeds when a pool has not been overridden' do
|
||||
delete "#{prefix}/config/poolsize/pool1"
|
||||
expect_json(ok = true, http = 200)
|
||||
expected = {
|
||||
ok: true,
|
||||
pool_size_before_reset: 5,
|
||||
pool_size_before_overrides: 5
|
||||
}
|
||||
|
||||
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
|
||||
delete "#{prefix}/config/poolsize/pool1"
|
||||
expect_json(ok = false, http = 405)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /config/poolsize' do
|
||||
it 'changes a pool size' do
|
||||
post "#{prefix}/config/poolsize", '{"pool1":"2"}'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue