mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Fix tests based on new dns config
This commit is contained in:
parent
91248fe23a
commit
1df7ab6d34
10 changed files with 386 additions and 141 deletions
|
|
@ -28,10 +28,16 @@ describe Vmpooler::API::V2 do
|
|||
'compute2' => 0
|
||||
}
|
||||
},
|
||||
dns_configs: {
|
||||
:mock => {
|
||||
'dns_class' => 'mock',
|
||||
'domain' => 'example.com'
|
||||
}
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 0, 'clone_target' => 'compute1'},
|
||||
{'name' => 'pool2', 'size' => 0, 'clone_target' => 'compute2'},
|
||||
{'name' => 'pool3', 'size' => 0, 'clone_target' => 'compute1'}
|
||||
{'name' => 'pool1', 'size' => 0, 'clone_target' => 'compute1', 'dns_plugin' => 'mock'},
|
||||
{'name' => 'pool2', 'size' => 0, 'clone_target' => 'compute2', 'dns_plugin' => 'mock'},
|
||||
{'name' => 'pool3', 'size' => 0, 'clone_target' => 'compute1', 'dns_plugin' => 'mock'}
|
||||
],
|
||||
alias: {
|
||||
'poolone' => ['pool1'],
|
||||
|
|
@ -39,9 +45,7 @@ describe Vmpooler::API::V2 do
|
|||
},
|
||||
pool_names: [ 'pool1', 'pool2', 'pool3', 'poolone' ],
|
||||
providers: {
|
||||
:dummy => {
|
||||
'domain' => 'dummy.com'
|
||||
}
|
||||
:dummy => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -117,22 +121,23 @@ describe Vmpooler::API::V2 do
|
|||
post "#{prefix}/ondemandvm", '{"pool2":"1"}'
|
||||
end
|
||||
|
||||
context 'with domain set in the config' do
|
||||
let(:domain) { 'example.com' }
|
||||
before(:each) do
|
||||
config[:config]['domain'] = domain
|
||||
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
|
||||
# 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
|
||||
|
|
@ -266,56 +271,12 @@ describe Vmpooler::API::V2 do
|
|||
"ready": true,
|
||||
"pool1": {
|
||||
"hostname": [
|
||||
vmname
|
||||
"#{vmname}.example.com"
|
||||
]
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
context 'with domain set' do
|
||||
let(:domain) { 'example.com' }
|
||||
before(:each) do
|
||||
config[:config]['domain'] = domain
|
||||
end
|
||||
|
||||
it 'should include the domain in the hostname as fqdn, not a separate key unlike in v1' do
|
||||
get "#{prefix}/ondemandvm/#{uuid}"
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid,
|
||||
"ready": true,
|
||||
"pool1": {
|
||||
"hostname": [
|
||||
"#{vmname}.#{domain}"
|
||||
]
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with domain set in the provider' do
|
||||
let(:domain) { 'dummy.com' }
|
||||
before(:each) do
|
||||
config[:pools][0]['provider'] = 'dummy'
|
||||
end
|
||||
|
||||
it 'should include the domain in the hostname as fqdn, not a separate key unlike in v1' do
|
||||
get "#{prefix}/ondemandvm/#{uuid}"
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid,
|
||||
"ready": true,
|
||||
"pool1": {
|
||||
"hostname": [
|
||||
"#{vmname}.#{domain}"
|
||||
]
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a deleted request' do
|
||||
|
|
|
|||
|
|
@ -25,14 +25,28 @@ describe Vmpooler::API::V2 do
|
|||
'vm_lifetime_auth' => 2
|
||||
},
|
||||
providers: {
|
||||
vsphere: {'domain' => 'one.example.com'},
|
||||
gce: {'domain' => 'two.example.com'},
|
||||
foo: {'domain' => 'three.example.com'}
|
||||
vsphere: {},
|
||||
gce: {},
|
||||
foo: {}
|
||||
},
|
||||
dns_configs: {
|
||||
:one => {
|
||||
'dns_class' => 'mock',
|
||||
'domain' => 'one.example.com'
|
||||
},
|
||||
:two => {
|
||||
'dns_class' => 'mock',
|
||||
'domain' => 'two.example.com'
|
||||
},
|
||||
:three => {
|
||||
'dns_class' => 'mock',
|
||||
'domain' => 'three.example.com'
|
||||
}
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5, 'provider' => 'vsphere'},
|
||||
{'name' => 'pool2', 'size' => 10, 'provider' => 'gce'},
|
||||
{'name' => 'pool3', 'size' => 10, 'provider' => 'foo'}
|
||||
{'name' => 'pool1', 'size' => 5, 'provider' => 'vsphere', 'dns_plugin' => 'one'},
|
||||
{'name' => 'pool2', 'size' => 10, 'provider' => 'gce', 'dns_plugin' => 'two'},
|
||||
{'name' => 'pool3', 'size' => 10, 'provider' => 'foo', 'dns_plugin' => 'three'}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
alias: { 'poolone' => ['pool1'] },
|
||||
|
|
@ -341,27 +355,29 @@ describe Vmpooler::API::V2 do
|
|||
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, redis
|
||||
create_ready_vm 'pool1', "2#{vmname}", redis
|
||||
# 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
|
||||
|
||||
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}"
|
||||
}
|
||||
}
|
||||
# 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
|
||||
|
|
|
|||
|
|
@ -24,11 +24,17 @@ describe Vmpooler::API::V2 do
|
|||
'site_name' => 'test pooler',
|
||||
'vm_lifetime_auth' => 2,
|
||||
},
|
||||
dns_configs: {
|
||||
:example => {
|
||||
'dns_class' => 'mock',
|
||||
'domain' => 'example.com'
|
||||
}
|
||||
},
|
||||
providers: { vsphere: {} },
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5},
|
||||
{'name' => 'pool2', 'size' => 10},
|
||||
{'name' => 'poolone', 'size' => 1}
|
||||
{'name' => 'pool1', 'size' => 5, 'provider' => 'vsphere', 'dns_plugin' => 'example'},
|
||||
{'name' => 'pool2', 'size' => 10, 'provider' => 'vsphere', 'dns_plugin' => 'example'},
|
||||
{'name' => 'poolone', 'size' => 1, 'provider' => 'vsphere', 'dns_plugin' => 'example'}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
|
|
@ -60,7 +66,7 @@ describe Vmpooler::API::V2 do
|
|||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
hostname: 'abcdefghijklmnop.example.com'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +83,7 @@ describe Vmpooler::API::V2 do
|
|||
expected = {
|
||||
ok: true,
|
||||
poolone: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
hostname: 'abcdefghijklmnop.example.com'
|
||||
}
|
||||
}
|
||||
expect_json(ok = true, http = 200)
|
||||
|
|
@ -126,10 +132,10 @@ describe Vmpooler::API::V2 do
|
|||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
hostname: 'abcdefghijklmnop.example.com'
|
||||
},
|
||||
pool2: {
|
||||
hostname: 'qrstuvwxyz012345'
|
||||
hostname: 'qrstuvwxyz012345.example.com'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -151,17 +157,17 @@ describe Vmpooler::API::V2 do
|
|||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: [ '1abcdefghijklmnop', '2abcdefghijklmnop' ]
|
||||
hostname: [ '1abcdefghijklmnop.example.com', '2abcdefghijklmnop.example.com' ]
|
||||
},
|
||||
pool2: {
|
||||
hostname: [ '1qrstuvwxyz012345', '2qrstuvwxyz012345', '3qrstuvwxyz012345' ]
|
||||
hostname: [ '1qrstuvwxyz012345.example.com', '2qrstuvwxyz012345.example.com', '3qrstuvwxyz012345.example.com' ]
|
||||
}
|
||||
}
|
||||
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result['ok']).to eq(true)
|
||||
expect(result['pool1']['hostname']).to include('1abcdefghijklmnop', '2abcdefghijklmnop')
|
||||
expect(result['pool2']['hostname']).to include('1qrstuvwxyz012345', '2qrstuvwxyz012345', '3qrstuvwxyz012345')
|
||||
expect(result['pool1']['hostname']).to include('1abcdefghijklmnop.example.com', '2abcdefghijklmnop.example.com')
|
||||
expect(result['pool2']['hostname']).to include('1qrstuvwxyz012345.example.com', '2qrstuvwxyz012345.example.com', '3qrstuvwxyz012345.example.com')
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
|
||||
|
|
@ -265,7 +271,7 @@ describe Vmpooler::API::V2 do
|
|||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
hostname: 'abcdefghijklmnop.example.com'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -291,7 +297,7 @@ describe Vmpooler::API::V2 do
|
|||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
hostname: 'abcdefghijklmnop.example.com'
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
|
|
@ -311,7 +317,7 @@ describe Vmpooler::API::V2 do
|
|||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
hostname: 'abcdefghijklmnop.example.com'
|
||||
}
|
||||
}
|
||||
expect_json(ok = true, http = 200)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue