mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(POOLER-143) Add clone_target config change to API
This allows the user to change the cluster in which the targeted pool will clone to. Upon configuration change, the thread will wake up and execute the change within 1 second.
This commit is contained in:
parent
5bbaf7e8cf
commit
98a547b807
4 changed files with 222 additions and 3 deletions
|
|
@ -16,7 +16,7 @@ describe Vmpooler::API::V1 do
|
|||
'experimental_features' => true
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5, 'template' => 'templates/pool1'},
|
||||
{'name' => 'pool1', 'size' => 5, 'template' => 'templates/pool1', 'clone_target' => 'default_cluster'},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
|
|
@ -223,6 +223,69 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'POST /config/clonetarget' do
|
||||
it 'changes the clone target' do
|
||||
post "#{prefix}/config/clonetarget", '{"pool1":"cluster1"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'changes a pool size for multiple pools' do
|
||||
post "#{prefix}/config/clonetarget", '{"pool1":"cluster1","pool2":"cluster2"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when a specified pool does not exist' do
|
||||
post "#{prefix}/config/clonetarget", '{"pool10":"cluster1"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
expected = {
|
||||
ok: false,
|
||||
bad_templates: ['pool10']
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'succeeds with 200 when no change is required' do
|
||||
post "#{prefix}/config/clonetarget", '{"pool1":"default_cluster"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'succeeds with 201 when at least one pool changes' do
|
||||
post "#{prefix}/config/clonetarget", '{"pool1":"default_cluster","pool2":"cluster2"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
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}/config/clonetarget", '{"pool1":"cluster1"}'
|
||||
expect_json(ok = false, http = 405)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /config' do
|
||||
let(:prefix) { '/api/v1' }
|
||||
|
||||
|
|
|
|||
|
|
@ -2390,6 +2390,59 @@ EOT
|
|||
end
|
||||
end
|
||||
|
||||
describe 'update_clone_target' do
|
||||
let(:newtarget) { 'cluster2' }
|
||||
let(:config) {
|
||||
YAML.load(<<-EOT
|
||||
---
|
||||
:pools:
|
||||
- name: #{pool}
|
||||
clone_target: 'cluster1'
|
||||
EOT
|
||||
)
|
||||
}
|
||||
let(:poolconfig) { config[:pools][0] }
|
||||
|
||||
context 'with a locked mutex' do
|
||||
|
||||
let(:mutex) { Mutex.new }
|
||||
before(:each) do
|
||||
mutex.lock
|
||||
expect(subject).to receive(:pool_mutex).with(pool).and_return(mutex)
|
||||
end
|
||||
|
||||
it 'should return nil' do
|
||||
expect(subject.update_clone_target(poolconfig)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
it 'should get the pool clone target configuration from redis' do
|
||||
expect(redis).to receive(:hget).with('vmpooler__config__clone_target', pool)
|
||||
|
||||
subject.update_clone_target(poolconfig)
|
||||
end
|
||||
|
||||
it 'should return when clone_target is not set in redis' do
|
||||
expect(redis).to receive(:hget).with('vmpooler__config__clone_target', pool).and_return(nil)
|
||||
|
||||
expect(subject.update_clone_target(poolconfig)).to be_nil
|
||||
end
|
||||
|
||||
it 'should return when no change in configuration is required' do
|
||||
expect(redis).to receive(:hget).with('vmpooler__config__clone_target', pool).and_return('cluster1')
|
||||
|
||||
expect(subject.update_clone_target(poolconfig)).to be_nil
|
||||
end
|
||||
|
||||
it 'should update the clone target' do
|
||||
expect(redis).to receive(:hget).with('vmpooler__config__clone_target', pool).and_return(newtarget)
|
||||
|
||||
subject.update_clone_target(poolconfig)
|
||||
|
||||
expect(poolconfig['clone_target']).to eq(newtarget)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#execute!" do
|
||||
let(:config) {
|
||||
YAML.load(<<-EOT
|
||||
|
|
@ -2759,7 +2812,7 @@ EOT
|
|||
|
||||
expect(subject).to receive(:sleep).exactly(2).times
|
||||
expect(subject).to receive(:time_passed?).with(:exit_by, Time).and_return(false, false, false, true)
|
||||
|
||||
|
||||
subject.sleep_with_wakeup_events(loop_delay)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue