mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Add v3 api and remove v2
This commit is contained in:
parent
d0d97dd0a8
commit
93201756a0
13 changed files with 627 additions and 2009 deletions
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
describe Vmpooler::API::V3 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -37,7 +37,7 @@ describe Vmpooler::API::V2 do
|
|||
}
|
||||
|
||||
describe '/config/pooltemplate' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
|
||||
let(:current_time) { Time.now }
|
||||
|
|
@ -388,7 +388,7 @@ describe Vmpooler::API::V2 do
|
|||
end
|
||||
|
||||
describe 'GET /config' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:prefix) { '/api/v3' }
|
||||
|
||||
it 'returns pool configuration when set' do
|
||||
get "#{prefix}/config"
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
describe Vmpooler::API::V3 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -15,7 +15,7 @@ describe Vmpooler::API::V2 do
|
|||
end
|
||||
|
||||
describe '/ondemandvm' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
let(:config) {
|
||||
{
|
||||
|
|
@ -120,24 +120,6 @@ describe Vmpooler::API::V2 do
|
|||
expect(redis).to receive(:hset).with("vmpooler__odrequest__#{uuid}", 'requested', 'pool2:pool1:1')
|
||||
post "#{prefix}/ondemandvm", '{"pool2":"1"}'
|
||||
end
|
||||
|
||||
# Domain is always included in reply now
|
||||
# context 'with domain set in the config' do
|
||||
# let(:domain) { 'example.com' }
|
||||
# before(:each) do
|
||||
# config[:config]['domain'] = domain
|
||||
# end
|
||||
|
||||
# it 'should include domain in the return reply' do
|
||||
# post "#{prefix}/ondemandvm", '{"poolone":"1"}'
|
||||
# expect_json(true, 201)
|
||||
# expected = {
|
||||
# "ok": true,
|
||||
# "request_id": uuid,
|
||||
# }
|
||||
# expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
context 'with a resource request that exceeds the specified limit' do
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
describe Vmpooler::API::V3 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -30,7 +30,7 @@ describe Vmpooler::API::V2 do
|
|||
}
|
||||
|
||||
describe '/poolreset' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
|
||||
let(:current_time) { Time.now }
|
||||
|
|
@ -5,7 +5,7 @@ def has_set_tag?(vm, tag, value)
|
|||
value == redis.hget("vmpooler__vm__#{vm}", "tag:#{tag}")
|
||||
end
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
describe Vmpooler::API::V3 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -20,7 +20,7 @@ describe Vmpooler::API::V2 do
|
|||
end
|
||||
|
||||
describe 'status and metrics endpoints' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:prefix) { '/api/v3' }
|
||||
|
||||
let(:config) {
|
||||
{
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
describe Vmpooler::API::V3 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -16,7 +16,7 @@ describe Vmpooler::API::V2 do
|
|||
end
|
||||
|
||||
describe '/token' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:current_time) { Time.now }
|
||||
let(:config) { {
|
||||
config: {}
|
||||
|
|
@ -111,7 +111,7 @@ describe Vmpooler::API::V2 do
|
|||
end
|
||||
|
||||
describe '/token/:token' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:current_time) { Time.now }
|
||||
|
||||
before(:each) do
|
||||
|
|
@ -5,7 +5,7 @@ def has_set_tag?(vm, tag, value)
|
|||
value == redis.hget("vmpooler__vm__#{vm}", "tag:#{tag}")
|
||||
end
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
describe Vmpooler::API::V3 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -20,7 +20,7 @@ describe Vmpooler::API::V2 do
|
|||
end
|
||||
|
||||
describe '/vm/:hostname' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
|
||||
let(:config) {
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
describe Vmpooler::API::V3 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -16,7 +16,7 @@ describe Vmpooler::API::V2 do
|
|||
end
|
||||
|
||||
describe '/vm' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
let(:config) {
|
||||
{
|
||||
|
|
@ -355,29 +355,27 @@ describe Vmpooler::API::V2 do
|
|||
expect(pool_has_ready_vm?('pool1', '2abcdefghijklmnop', redis)).to eq(true)
|
||||
end
|
||||
|
||||
# The helper create_ready_vm inherently means that the vm has already reached a
|
||||
# ready state and that open_socket already returned sucessfully before being moved to ready.
|
||||
# it 'returns the second VM when the first fails to respond' do
|
||||
# create_running_vm 'pool1', vmname, redis
|
||||
# create_ready_vm 'pool1', "2#{vmname}", redis
|
||||
it 'returns the second VM when the first fails to respond' do
|
||||
create_running_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)
|
||||
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)
|
||||
|
||||
# post "#{prefix}/vm", '{"pool1":"1"}'
|
||||
# expect_json(ok = true, http = 200)
|
||||
post "#{prefix}/vm", '{"pool1":"1"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
# expected = {
|
||||
# ok: true,
|
||||
# pool1: {
|
||||
# hostname: "2#{vmname}.one.example.com"
|
||||
# }
|
||||
# }
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: "2#{vmname}.one.example.com"
|
||||
}
|
||||
}
|
||||
|
||||
# expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
|
||||
# expect(pool_has_ready_vm?('pool1', vmname, redis)).to be false
|
||||
# end
|
||||
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
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
describe Vmpooler::API::V3 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -16,7 +16,7 @@ describe Vmpooler::API::V2 do
|
|||
end
|
||||
|
||||
describe '/vm/:template' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
let(:config) {
|
||||
{
|
||||
Loading…
Add table
Add a link
Reference in a new issue