mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Fix tests for changes
This commit is contained in:
parent
90e09bfe1c
commit
2b96d7e476
10 changed files with 268 additions and 189 deletions
|
|
@ -50,7 +50,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns the number of ready vms for each pool' do
|
||||
3.times {|i| create_ready_vm("pool1", "vm-#{i}") }
|
||||
3.times {|i| create_ready_vm("pool1", "vm-#{i}", redis) }
|
||||
get "#{prefix}/status/"
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
|
|
@ -61,8 +61,8 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns the number of running vms for each pool' do
|
||||
3.times {|i| create_running_vm("pool1", "vm-#{i}") }
|
||||
4.times {|i| create_running_vm("pool2", "vm-#{i}") }
|
||||
3.times {|i| create_running_vm("pool1", "vm-#{i}", redis) }
|
||||
4.times {|i| create_running_vm("pool2", "vm-#{i}", redis) }
|
||||
|
||||
get "#{prefix}/status/"
|
||||
|
||||
|
|
@ -74,8 +74,8 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns the number of pending vms for each pool' do
|
||||
3.times {|i| create_pending_vm("pool1", "vm-#{i}") }
|
||||
4.times {|i| create_pending_vm("pool2", "vm-#{i}") }
|
||||
3.times {|i| create_pending_vm("pool1", "vm-#{i}", redis) }
|
||||
4.times {|i| create_pending_vm("pool2", "vm-#{i}", redis) }
|
||||
|
||||
get "#{prefix}/status/"
|
||||
|
||||
|
|
@ -230,8 +230,8 @@ describe Vmpooler::API::V1 do
|
|||
it 'returns the number of running VMs' do
|
||||
get "#{prefix}/totalrunning"
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
5.times {|i| create_running_vm("pool1", "vm-#{i}") }
|
||||
5.times {|i| create_running_vm("pool3", "vm-#{i}") }
|
||||
5.times {|i| create_running_vm("pool1", "vm-#{i}", redis, redis) }
|
||||
5.times {|i| create_running_vm("pool3", "vm-#{i}", redis, redis) }
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["running"] == 10)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
describe 'PUT /vm/:hostname' do
|
||||
it 'allows tags to be set' do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"tested_by":"rspec"}}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'skips empty tags' do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"tested_by":""}}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'does not set tags if request body format is invalid' do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"tested"}}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ describe Vmpooler::API::V1 do
|
|||
app.settings.set :config,
|
||||
{ :config => { 'allowed_tags' => ['created_by', 'project', 'url'] } }
|
||||
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"created_by":"rspec","tested_by":"rspec"}}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
|
@ -84,7 +84,7 @@ describe Vmpooler::API::V1 do
|
|||
} }
|
||||
|
||||
it 'correctly filters tags' do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"url":"foo.com/something.html"}}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
|
@ -93,7 +93,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it "doesn't eat tags not matching filter" do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"url":"foo.com"}}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ describe Vmpooler::API::V1 do
|
|||
let(:config) { { auth: false } }
|
||||
|
||||
it 'allows VM lifetime to be modified without a token' do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"1"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
|
@ -115,7 +115,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'does not allow a lifetime to be 0' do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"0"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
|
@ -125,7 +125,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'does not enforce a lifetime' do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"20000"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
|
@ -137,7 +137,7 @@ describe Vmpooler::API::V1 do
|
|||
it 'does not allow a lifetime to be initially past config max_lifetime_upper_limit' do
|
||||
app.settings.set :config,
|
||||
{ :config => { 'max_lifetime_upper_limit' => 168 } }
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"200"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
|
@ -146,6 +146,18 @@ describe Vmpooler::API::V1 do
|
|||
expect(vm['lifetime']).to be_nil
|
||||
end
|
||||
|
||||
it 'does not allow a lifetime to be extended past config 168' do
|
||||
app.settings.set :config,
|
||||
{ :config => { 'max_lifetime_upper_limit' => 168 } }
|
||||
create_vm('testhost', redis)
|
||||
|
||||
set_vm_data('testhost', "checkout", (Time.now - (69*60*60)), redis)
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"100"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
vm = fetch_vm('testhost')
|
||||
expect(vm['lifetime']).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
|
|
@ -154,7 +166,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'allows VM lifetime to be modified with a token' do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"1"}', {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
|
|
@ -166,7 +178,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'does not allows VM lifetime to be modified without a token' do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"1"}'
|
||||
expect_json(ok = false, http = 401)
|
||||
|
|
@ -182,7 +194,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'deletes an existing VM' do
|
||||
create_running_vm('pool1', 'testhost')
|
||||
create_running_vm('pool1', 'testhost', redis)
|
||||
expect fetch_vm('testhost')
|
||||
|
||||
delete "#{prefix}/vm/testhost"
|
||||
|
|
@ -198,7 +210,7 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
context '(checked-out without token)' do
|
||||
it 'deletes a VM without supplying a token' do
|
||||
create_running_vm('pool1', 'testhost')
|
||||
create_running_vm('pool1', 'testhost', redis)
|
||||
expect fetch_vm('testhost')
|
||||
|
||||
delete "#{prefix}/vm/testhost"
|
||||
|
|
@ -209,7 +221,7 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
context '(checked-out with token)' do
|
||||
it 'fails to delete a VM without supplying a token' do
|
||||
create_running_vm('pool1', 'testhost', 'abcdefghijklmnopqrstuvwxyz012345')
|
||||
create_running_vm('pool1', 'testhost', redis, 'abcdefghijklmnopqrstuvwxyz012345')
|
||||
expect fetch_vm('testhost')
|
||||
|
||||
delete "#{prefix}/vm/testhost"
|
||||
|
|
@ -218,7 +230,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'deletes a VM when token is supplied' do
|
||||
create_running_vm('pool1', 'testhost', 'abcdefghijklmnopqrstuvwxyz012345')
|
||||
create_running_vm('pool1', 'testhost', redis, 'abcdefghijklmnopqrstuvwxyz012345')
|
||||
expect fetch_vm('testhost')
|
||||
|
||||
delete "#{prefix}/vm/testhost", "", {
|
||||
|
|
@ -235,7 +247,7 @@ describe Vmpooler::API::V1 do
|
|||
describe 'POST /vm/:hostname/snapshot' do
|
||||
context '(auth not configured)' do
|
||||
it 'creates a snapshot' do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
post "#{prefix}/vm/testhost/snapshot"
|
||||
expect_json(ok = true, http = 202)
|
||||
expect(JSON.parse(last_response.body)['testhost']['snapshot'].length).to be(32)
|
||||
|
|
@ -250,19 +262,19 @@ describe Vmpooler::API::V1 do
|
|||
it 'returns a 401 if not authed' do
|
||||
post "#{prefix}/vm/testhost/snapshot"
|
||||
expect_json(ok = false, http = 401)
|
||||
expect !has_vm_snapshot?('testhost')
|
||||
expect !has_vm_snapshot?('testhost', redis)
|
||||
end
|
||||
|
||||
it 'creates a snapshot if authed' do
|
||||
create_vm('testhost')
|
||||
snapshot_vm('testhost', 'testsnapshot')
|
||||
create_vm('testhost', redis)
|
||||
snapshot_vm('testhost', 'testsnapshot', redis)
|
||||
|
||||
post "#{prefix}/vm/testhost/snapshot", "", {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = true, http = 202)
|
||||
expect(JSON.parse(last_response.body)['testhost']['snapshot'].length).to be(32)
|
||||
expect has_vm_snapshot?('testhost')
|
||||
expect has_vm_snapshot?('testhost', redis)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -270,22 +282,22 @@ describe Vmpooler::API::V1 do
|
|||
describe 'POST /vm/:hostname/snapshot/:snapshot' do
|
||||
context '(auth not configured)' do
|
||||
it 'reverts to a snapshot' do
|
||||
create_vm('testhost')
|
||||
snapshot_vm('testhost', 'testsnapshot')
|
||||
create_vm('testhost', redis)
|
||||
snapshot_vm('testhost', 'testsnapshot', redis)
|
||||
|
||||
post "#{prefix}/vm/testhost/snapshot/testsnapshot"
|
||||
expect_json(ok = true, http = 202)
|
||||
expect vm_reverted_to_snapshot?('testhost', 'testsnapshot')
|
||||
expect vm_reverted_to_snapshot?('testhost', redis, 'testsnapshot')
|
||||
end
|
||||
|
||||
it 'fails if the specified snapshot does not exist' do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
|
||||
post "#{prefix}/vm/testhost/snapshot/testsnapshot", "", {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = false, http = 404)
|
||||
expect !vm_reverted_to_snapshot?('testhost', 'testsnapshot')
|
||||
expect !vm_reverted_to_snapshot?('testhost', redis, 'testsnapshot')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -295,33 +307,33 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns a 401 if not authed' do
|
||||
create_vm('testhost')
|
||||
snapshot_vm('testhost', 'testsnapshot')
|
||||
create_vm('testhost', redis)
|
||||
snapshot_vm('testhost', 'testsnapshot', redis)
|
||||
|
||||
post "#{prefix}/vm/testhost/snapshot/testsnapshot"
|
||||
expect_json(ok = false, http = 401)
|
||||
expect !vm_reverted_to_snapshot?('testhost', 'testsnapshot')
|
||||
expect !vm_reverted_to_snapshot?('testhost', redis, 'testsnapshot')
|
||||
end
|
||||
|
||||
it 'fails if authed and the specified snapshot does not exist' do
|
||||
create_vm('testhost')
|
||||
create_vm('testhost', redis)
|
||||
|
||||
post "#{prefix}/vm/testhost/snapshot/testsnapshot", "", {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = false, http = 404)
|
||||
expect !vm_reverted_to_snapshot?('testhost', 'testsnapshot')
|
||||
expect !vm_reverted_to_snapshot?('testhost', redis, 'testsnapshot')
|
||||
end
|
||||
|
||||
it 'reverts to a snapshot if authed' do
|
||||
create_vm('testhost')
|
||||
snapshot_vm('testhost', 'testsnapshot')
|
||||
create_vm('testhost', redis)
|
||||
snapshot_vm('testhost', 'testsnapshot', redis)
|
||||
|
||||
post "#{prefix}/vm/testhost/snapshot/testsnapshot", "", {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = true, http = 202)
|
||||
expect vm_reverted_to_snapshot?('testhost', 'testsnapshot')
|
||||
expect vm_reverted_to_snapshot?('testhost', redis, 'testsnapshot')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
describe 'GET /vm/:hostname' do
|
||||
it 'returns correct information on a running vm' do
|
||||
create_running_vm 'pool1', vmname
|
||||
create_running_vm 'pool1', vmname, redis
|
||||
get "#{prefix}/vm/#{vmname}"
|
||||
expect_json(ok = true, http = 200)
|
||||
response_body = (JSON.parse(last_response.body)[vmname])
|
||||
|
|
@ -63,7 +63,7 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
let(:socket) { double('socket') }
|
||||
it 'returns a single VM' do
|
||||
create_ready_vm 'pool1', vmname
|
||||
create_ready_vm 'pool1', vmname, redis
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"1"}'
|
||||
|
|
@ -80,7 +80,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns a single VM for an alias' do
|
||||
create_ready_vm 'pool1', vmname
|
||||
create_ready_vm 'pool1', vmname, redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ describe Vmpooler::API::V1 do
|
|||
Vmpooler::API.settings.config.delete(:alias)
|
||||
Vmpooler::API.settings.config[:pool_names] = ['pool1', 'pool2']
|
||||
|
||||
create_ready_vm 'pool1', vmname
|
||||
create_ready_vm 'pool1', vmname, redis
|
||||
post "#{prefix}/vm/pool1"
|
||||
post "#{prefix}/vm/pool1"
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns 503 for empty pool referenced by alias' do
|
||||
create_ready_vm 'pool1', vmname
|
||||
create_ready_vm 'pool1', vmname, redis
|
||||
post "#{prefix}/vm/poolone"
|
||||
post "#{prefix}/vm/poolone"
|
||||
|
||||
|
|
@ -128,8 +128,8 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns multiple VMs' do
|
||||
create_ready_vm 'pool1', vmname
|
||||
create_ready_vm 'pool2', 'qrstuvwxyz012345'
|
||||
create_ready_vm 'pool1', vmname, redis
|
||||
create_ready_vm 'pool2', 'qrstuvwxyz012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -150,9 +150,9 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns multiple VMs even when multiple instances from the same pool are requested' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop'
|
||||
create_ready_vm 'pool2', 'qrstuvwxyz012345'
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool2', 'qrstuvwxyz012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -177,11 +177,11 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns multiple VMs even when multiple instances from multiple pools are requested' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop'
|
||||
create_ready_vm 'pool2', '1qrstuvwxyz012345'
|
||||
create_ready_vm 'pool2', '2qrstuvwxyz012345'
|
||||
create_ready_vm 'pool2', '3qrstuvwxyz012345'
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool2', '1qrstuvwxyz012345', redis
|
||||
create_ready_vm 'pool2', '2qrstuvwxyz012345', redis
|
||||
create_ready_vm 'pool2', '3qrstuvwxyz012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -208,9 +208,9 @@ describe Vmpooler::API::V1 do
|
|||
it 'returns VMs from multiple backend pools requested by an alias' do
|
||||
Vmpooler::API.settings.config[:alias]['genericpool'] = ['pool1', 'pool2', 'pool3']
|
||||
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop'
|
||||
create_ready_vm 'pool2', '2abcdefghijklmnop'
|
||||
create_ready_vm 'pool3', '1qrstuvwxyz012345'
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool2', '2abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool3', '1qrstuvwxyz012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -231,9 +231,9 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns the first VM that was moved to the ready state when checking out a VM' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '3abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '3abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -251,7 +251,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'fails when not all requested vms can be allocated' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"1","pool2":"1"}'
|
||||
|
||||
|
|
@ -262,7 +262,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns any checked out vms to their pools when not all requested vms can be allocated' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -273,11 +273,11 @@ describe Vmpooler::API::V1 do
|
|||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', '1abcdefghijklmnop')).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool1', '1abcdefghijklmnop', redis)).to eq(true)
|
||||
end
|
||||
|
||||
it 'fails when not all requested vms can be allocated, when requesting multiple instances from a pool' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"2","pool2":"1"}'
|
||||
|
||||
|
|
@ -288,7 +288,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns any checked out vms to their pools when not all requested vms can be allocated, when requesting multiple instances from a pool' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -299,11 +299,11 @@ describe Vmpooler::API::V1 do
|
|||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', '1abcdefghijklmnop')).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool1', '1abcdefghijklmnop', redis)).to eq(true)
|
||||
end
|
||||
|
||||
it 'fails when not all requested vms can be allocated, when requesting multiple instances from multiple pools' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"2","pool2":"3"}'
|
||||
|
||||
|
|
@ -314,8 +314,8 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns any checked out vms to their pools when not all requested vms can be allocated, when requesting multiple instances from multiple pools' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -326,13 +326,13 @@ describe Vmpooler::API::V1 do
|
|||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', '1abcdefghijklmnop')).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool1', '2abcdefghijklmnop')).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool1', '1abcdefghijklmnop', redis)).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool1', '2abcdefghijklmnop', redis)).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns the second VM when the first fails to respond' do
|
||||
create_ready_vm 'pool1', vmname
|
||||
create_ready_vm 'pool1', "2#{vmname}"
|
||||
create_ready_vm 'pool1', vmname, redis
|
||||
create_ready_vm 'pool1', "2#{vmname}", redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).with(vmname, nil).and_raise('mockerror')
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).with("2#{vmname}", nil).and_return(socket)
|
||||
|
|
@ -349,14 +349,14 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', vmname)).to be false
|
||||
expect(pool_has_ready_vm?('pool1', vmname, redis)).to be false
|
||||
end
|
||||
|
||||
context '(auth not configured)' do
|
||||
it 'does not extend VM lifetime if auth token is provided' do
|
||||
app.settings.set :config, auth: false
|
||||
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -382,7 +382,7 @@ describe Vmpooler::API::V1 do
|
|||
it 'extends VM lifetime if auth token is provided' do
|
||||
app.settings.set :config, auth: true
|
||||
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -405,7 +405,7 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
it 'does not extend VM lifetime if auth token is not provided' do
|
||||
app.settings.set :config, auth: true
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ describe Vmpooler::API::V1 do
|
|||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
{'name' => 'pool2', 'size' => 10},
|
||||
{'name' => 'poolone', 'size' => 0}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
|
|
@ -42,7 +43,7 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
describe 'POST /vm/:template' do
|
||||
it 'returns a single VM' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -60,7 +61,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns a single VM for an alias' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -86,7 +87,7 @@ describe Vmpooler::API::V1 do
|
|||
Vmpooler::API.settings.config.delete(:alias)
|
||||
Vmpooler::API.settings.config[:pool_names] = ['pool1', 'pool2']
|
||||
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
post "#{prefix}/vm/pool1"
|
||||
post "#{prefix}/vm/pool1"
|
||||
|
||||
|
|
@ -97,8 +98,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns 503 for empty pool referenced by alias' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
post "#{prefix}/vm/poolone"
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
post "#{prefix}/vm/poolone"
|
||||
|
||||
expected = { ok: false }
|
||||
|
|
@ -108,8 +108,8 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns multiple VMs' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool2', 'qrstuvwxyz012345'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool2', 'qrstuvwxyz012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -130,12 +130,12 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns multiple VMs even when multiple instances from multiple pools are requested' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop', redis
|
||||
|
||||
create_ready_vm 'pool2', '1qrstuvwxyz012345'
|
||||
create_ready_vm 'pool2', '2qrstuvwxyz012345'
|
||||
create_ready_vm 'pool2', '3qrstuvwxyz012345'
|
||||
create_ready_vm 'pool2', '1qrstuvwxyz012345', redis
|
||||
create_ready_vm 'pool2', '2qrstuvwxyz012345', redis
|
||||
create_ready_vm 'pool2', '3qrstuvwxyz012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -159,7 +159,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'fails when not all requested vms can be allocated' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
post "#{prefix}/vm/pool1+pool2", ''
|
||||
|
||||
|
|
@ -170,7 +170,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns any checked out vms to their pools when not all requested vms can be allocated' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -181,12 +181,12 @@ describe Vmpooler::API::V1 do
|
|||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', 'abcdefghijklmnop')).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool1', 'abcdefghijklmnop', redis)).to eq(true)
|
||||
end
|
||||
|
||||
it 'fails when not all requested vms can be allocated, when requesting multiple instances from a pool' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '0123456789012345'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '0123456789012345', redis
|
||||
|
||||
post "#{prefix}/vm/pool1+pool1+pool2", ''
|
||||
|
||||
|
|
@ -197,8 +197,8 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns any checked out vms to their pools when not all requested vms can be allocated, when requesting multiple instances from a pool' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', '0123456789012345'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '0123456789012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -209,13 +209,13 @@ describe Vmpooler::API::V1 do
|
|||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', 'abcdefghijklmnop')).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool1', '0123456789012345')).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool1', 'abcdefghijklmnop', redis)).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool1', '0123456789012345', redis)).to eq(true)
|
||||
end
|
||||
|
||||
it 'fails when not all requested vms can be allocated, when requesting multiple instances from multiple pools' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool2', '0123456789012345'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool2', '0123456789012345', redis
|
||||
|
||||
post "#{prefix}/vm/pool1+pool1+pool2+pool2+pool2", ''
|
||||
|
||||
|
|
@ -226,8 +226,8 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns any checked out vms to their pools when not all requested vms can be allocated, when requesting multiple instances from multiple pools' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool2', '0123456789012345'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool2', '0123456789012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -238,15 +238,15 @@ describe Vmpooler::API::V1 do
|
|||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', 'abcdefghijklmnop')).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool2', '0123456789012345')).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool1', 'abcdefghijklmnop', redis)).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool2', '0123456789012345', redis)).to eq(true)
|
||||
end
|
||||
|
||||
context '(auth not configured)' do
|
||||
it 'does not extend VM lifetime if auth token is provided' do
|
||||
app.settings.set :config, auth: false
|
||||
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -272,7 +272,7 @@ describe Vmpooler::API::V1 do
|
|||
it 'extends VM lifetime if auth token is provided' do
|
||||
app.settings.set :config, auth: true
|
||||
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
@ -295,7 +295,7 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
it 'does not extend VM lifetime if auth token is not provided' do
|
||||
app.settings.set :config, auth: true
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop'
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
|
|
|
|||
|
|
@ -56,11 +56,11 @@ describe Vmpooler::API do
|
|||
|
||||
context 'without history param' do
|
||||
it 'returns basic JSON' do
|
||||
create_ready_vm('pool1', 'vm1')
|
||||
create_ready_vm('pool1', 'vm2')
|
||||
create_ready_vm('pool1', 'vm3')
|
||||
create_ready_vm('pool2', 'vm4')
|
||||
create_ready_vm('pool2', 'vm5')
|
||||
create_ready_vm('pool1', 'vm1', redis)
|
||||
create_ready_vm('pool1', 'vm2', redis)
|
||||
create_ready_vm('pool1', 'vm3', redis)
|
||||
create_ready_vm('pool2', 'vm4', redis)
|
||||
create_ready_vm('pool2', 'vm5', redis)
|
||||
|
||||
get '/dashboard/stats/vmpooler/pool'
|
||||
|
||||
|
|
@ -90,11 +90,11 @@ describe Vmpooler::API do
|
|||
end
|
||||
|
||||
it 'returns JSON with history when redis has values' do
|
||||
create_ready_vm('pool1', 'vm1')
|
||||
create_ready_vm('pool1', 'vm2')
|
||||
create_ready_vm('pool1', 'vm3')
|
||||
create_ready_vm('pool2', 'vm4')
|
||||
create_ready_vm('pool2', 'vm5')
|
||||
create_ready_vm('pool1', 'vm1', redis)
|
||||
create_ready_vm('pool1', 'vm2', redis)
|
||||
create_ready_vm('pool1', 'vm3', redis)
|
||||
create_ready_vm('pool2', 'vm4', redis)
|
||||
create_ready_vm('pool2', 'vm5', redis)
|
||||
|
||||
get '/dashboard/stats/vmpooler/pool', :history => true
|
||||
|
||||
|
|
@ -140,18 +140,18 @@ describe Vmpooler::API do
|
|||
end
|
||||
|
||||
it 'adds major correctly' do
|
||||
create_running_vm('pool-1', 'vm1')
|
||||
create_running_vm('pool-1', 'vm2')
|
||||
create_running_vm('pool-1', 'vm3')
|
||||
create_running_vm('pool-1', 'vm1', redis)
|
||||
create_running_vm('pool-1', 'vm2', redis)
|
||||
create_running_vm('pool-1', 'vm3', redis)
|
||||
|
||||
create_running_vm('pool-2', 'vm4')
|
||||
create_running_vm('pool-2', 'vm5')
|
||||
create_running_vm('pool-2', 'vm6')
|
||||
create_running_vm('pool-2', 'vm7')
|
||||
create_running_vm('pool-2', 'vm8')
|
||||
create_running_vm('pool-2', 'vm4', redis)
|
||||
create_running_vm('pool-2', 'vm5', redis)
|
||||
create_running_vm('pool-2', 'vm6', redis)
|
||||
create_running_vm('pool-2', 'vm7', redis)
|
||||
create_running_vm('pool-2', 'vm8', redis)
|
||||
|
||||
create_running_vm('diffpool-1', 'vm9')
|
||||
create_running_vm('diffpool-1', 'vm10')
|
||||
create_running_vm('diffpool-1', 'vm9', redis)
|
||||
create_running_vm('diffpool-1', 'vm10', redis)
|
||||
|
||||
get '/dashboard/stats/vmpooler/running'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue