mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-25 21:28:40 -05:00
Run the rubocop auto_correct
fixed 27 files inspected, 975 offenses detected, 804 offenses corrected
This commit is contained in:
parent
7041df82f0
commit
eb99ba1dec
21 changed files with 516 additions and 511 deletions
|
|
@ -4,9 +4,9 @@ require 'simplecov'
|
|||
require 'coveralls'
|
||||
|
||||
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
||||
SimpleCov::Formatter::HTMLFormatter,
|
||||
Coveralls::SimpleCov::Formatter
|
||||
])
|
||||
SimpleCov::Formatter::HTMLFormatter,
|
||||
Coveralls::SimpleCov::Formatter
|
||||
])
|
||||
SimpleCov.start do
|
||||
add_filter %r{^/spec/}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ describe Pooler do
|
|||
|
||||
it 'returns a token from abs' do
|
||||
stub_request(:post, 'https://first.last:password@abs.example.com/api/v2/token')
|
||||
.to_return(:status => 200, :body => @get_token_response, :headers => {})
|
||||
.to_return(status: 200, body: @get_token_response, headers: {})
|
||||
|
||||
token = Auth.get_token(false, @abs_url, 'first.last', 'password')
|
||||
expect(token).to eq @token
|
||||
|
|
@ -24,7 +24,7 @@ describe Pooler do
|
|||
|
||||
it 'raises a token error if something goes wrong' do
|
||||
stub_request(:post, 'https://first.last:password@abs.example.com/api/v2/token')
|
||||
.to_return(:status => 500, :body => '{"ok":false}', :headers => {})
|
||||
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
||||
|
||||
expect { Auth.get_token(false, @abs_url, 'first.last', 'password') }.to raise_error(TokenError)
|
||||
end
|
||||
|
|
@ -38,14 +38,15 @@ describe Pooler do
|
|||
|
||||
it 'deletes the specified token' do
|
||||
stub_request(:delete, 'https://first.last:password@abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
||||
.to_return(:status => 200, :body => @delete_token_response, :headers => {})
|
||||
.to_return(status: 200, body: @delete_token_response, headers: {})
|
||||
|
||||
expect(Auth.delete_token(false, @abs_url, 'first.last', 'password', @token)).to eq JSON.parse(@delete_token_response)
|
||||
expect(Auth.delete_token(false, @abs_url, 'first.last', 'password',
|
||||
@token)).to eq JSON.parse(@delete_token_response)
|
||||
end
|
||||
|
||||
it 'raises a token error if something goes wrong' do
|
||||
stub_request(:delete, 'https://first.last:password@abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
||||
.to_return(:status => 500, :body => '{"ok":false}', :headers => {})
|
||||
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
||||
|
||||
expect { Auth.delete_token(false, @abs_url, 'first.last', 'password', @token) }.to raise_error(TokenError)
|
||||
end
|
||||
|
|
@ -63,16 +64,16 @@ describe Pooler do
|
|||
|
||||
it 'checks the status of a token' do
|
||||
stub_request(:get, "#{@abs_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
||||
.with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' })
|
||||
.to_return(:status => 200, :body => @token_status_response, :headers => {})
|
||||
.with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' })
|
||||
.to_return(status: 200, body: @token_status_response, headers: {})
|
||||
|
||||
expect(Auth.token_status(false, @abs_url, @token)).to eq JSON.parse(@token_status_response)
|
||||
end
|
||||
|
||||
it 'raises a token error if something goes wrong' do
|
||||
stub_request(:get, "#{@abs_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
||||
.with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' })
|
||||
.to_return(:status => 500, :body => '{"ok":false}', :headers => {})
|
||||
.with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' })
|
||||
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
||||
|
||||
expect { Auth.token_status(false, @abs_url, @token) }.to raise_error(TokenError)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ describe ABS do
|
|||
|
||||
describe '#list' do
|
||||
it 'skips empty platforms and lists aws' do
|
||||
stub_request(:get, "http://foo/api/v2/status/platforms/vmpooler").
|
||||
to_return(:status => 200, :body => "", :headers => {})
|
||||
stub_request(:get, "http://foo/api/v2/status/platforms/ondemand_vmpooler").
|
||||
to_return(:status => 200, :body => "", :headers => {})
|
||||
stub_request(:get, "http://foo/api/v2/status/platforms/nspooler").
|
||||
to_return(:status => 200, :body => "", :headers => {})
|
||||
stub_request(:get, 'http://foo/api/v2/status/platforms/vmpooler')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
stub_request(:get, 'http://foo/api/v2/status/platforms/ondemand_vmpooler')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
stub_request(:get, 'http://foo/api/v2/status/platforms/nspooler')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
body = '{
|
||||
"aws_platforms": [
|
||||
"amazon-6-x86_64",
|
||||
|
|
@ -26,50 +26,55 @@ describe ABS do
|
|||
"redhat-8-arm64"
|
||||
]
|
||||
}'
|
||||
stub_request(:get, "http://foo/api/v2/status/platforms/aws").
|
||||
to_return(:status => 200, :body => body, :headers => {})
|
||||
stub_request(:get, 'http://foo/api/v2/status/platforms/aws')
|
||||
.to_return(status: 200, body: body, headers: {})
|
||||
|
||||
results = ABS.list(false, 'http://foo')
|
||||
|
||||
results = ABS.list(false, "http://foo")
|
||||
|
||||
expect(results).to include("amazon-6-x86_64", "amazon-7-x86_64", "amazon-7-arm64", "centos-7-x86-64-west", "redhat-8-arm64")
|
||||
expect(results).to include('amazon-6-x86_64', 'amazon-7-x86_64', 'amazon-7-arm64', 'centos-7-x86-64-west',
|
||||
'redhat-8-arm64')
|
||||
end
|
||||
it 'legacy JSON string, prior to PR 306' do
|
||||
stub_request(:get, "http://foo/api/v2/status/platforms/vmpooler").
|
||||
to_return(:status => 200, :body => "", :headers => {})
|
||||
stub_request(:get, "http://foo/api/v2/status/platforms/ondemand_vmpooler").
|
||||
to_return(:status => 200, :body => "", :headers => {})
|
||||
stub_request(:get, "http://foo/api/v2/status/platforms/nspooler").
|
||||
to_return(:status => 200, :body => "", :headers => {})
|
||||
stub_request(:get, 'http://foo/api/v2/status/platforms/vmpooler')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
stub_request(:get, 'http://foo/api/v2/status/platforms/ondemand_vmpooler')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
stub_request(:get, 'http://foo/api/v2/status/platforms/nspooler')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
body = '{
|
||||
"aws_platforms": "[\"amazon-6-x86_64\",\"amazon-7-x86_64\",\"amazon-7-arm64\",\"centos-7-x86-64-west\",\"redhat-8-arm64\"]"
|
||||
}'
|
||||
stub_request(:get, "http://foo/api/v2/status/platforms/aws").
|
||||
to_return(:status => 200, :body => body, :headers => {})
|
||||
stub_request(:get, 'http://foo/api/v2/status/platforms/aws')
|
||||
.to_return(status: 200, body: body, headers: {})
|
||||
|
||||
results = ABS.list(false, "http://foo")
|
||||
results = ABS.list(false, 'http://foo')
|
||||
|
||||
expect(results).to include("amazon-6-x86_64", "amazon-7-x86_64", "amazon-7-arm64", "centos-7-x86-64-west", "redhat-8-arm64")
|
||||
expect(results).to include('amazon-6-x86_64', 'amazon-7-x86_64', 'amazon-7-arm64', 'centos-7-x86-64-west',
|
||||
'redhat-8-arm64')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#format' do
|
||||
it 'returns an hash formatted like a vmpooler return, plus the job_id' do
|
||||
job_id = "generated_by_floaty_12345"
|
||||
job_id = 'generated_by_floaty_12345'
|
||||
abs_formatted_response = [
|
||||
{ 'hostname' => 'aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64', 'engine' => 'vmpooler' },
|
||||
{ 'hostname' => 'aaaaaaaaaaaaaab.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64', 'engine' => 'vmpooler' },
|
||||
{ 'hostname' => 'aaaaaaaaaaaaaac.delivery.puppetlabs.net', 'type' => 'ubuntu-7.2-x86_64', 'engine' => 'vmpooler' },
|
||||
{ 'hostname' => 'aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64',
|
||||
'engine' => 'vmpooler' },
|
||||
{ 'hostname' => 'aaaaaaaaaaaaaab.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64',
|
||||
'engine' => 'vmpooler' },
|
||||
{ 'hostname' => 'aaaaaaaaaaaaaac.delivery.puppetlabs.net', 'type' => 'ubuntu-7.2-x86_64',
|
||||
'engine' => 'vmpooler' }
|
||||
]
|
||||
|
||||
vmpooler_formatted_response = ABS.translated(abs_formatted_response, job_id)
|
||||
|
||||
vmpooler_formatted_compare = {
|
||||
'centos-7.2-x86_64' => {},
|
||||
'ubuntu-7.2-x86_64' => {},
|
||||
'ubuntu-7.2-x86_64' => {}
|
||||
}
|
||||
|
||||
vmpooler_formatted_compare['centos-7.2-x86_64']['hostname'] = ['aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'aaaaaaaaaaaaaab.delivery.puppetlabs.net']
|
||||
vmpooler_formatted_compare['centos-7.2-x86_64']['hostname'] =
|
||||
['aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'aaaaaaaaaaaaaab.delivery.puppetlabs.net']
|
||||
vmpooler_formatted_compare['ubuntu-7.2-x86_64']['hostname'] = ['aaaaaaaaaaaaaac.delivery.puppetlabs.net']
|
||||
|
||||
vmpooler_formatted_compare['ok'] = true
|
||||
|
|
@ -86,22 +91,22 @@ describe ABS do
|
|||
hosts = ['host1']
|
||||
allocated_resources = [
|
||||
{
|
||||
'hostname' => 'host1',
|
||||
'hostname' => 'host1'
|
||||
},
|
||||
{
|
||||
'hostname' => 'host2',
|
||||
},
|
||||
'hostname' => 'host2'
|
||||
}
|
||||
]
|
||||
expect(ABS.all_job_resources_accounted_for(allocated_resources, hosts)).to eq(false)
|
||||
|
||||
hosts = ['host1', 'host2']
|
||||
hosts = %w[host1 host2]
|
||||
allocated_resources = [
|
||||
{
|
||||
'hostname' => 'host1',
|
||||
'hostname' => 'host1'
|
||||
},
|
||||
{
|
||||
'hostname' => 'host2',
|
||||
},
|
||||
'hostname' => 'host2'
|
||||
}
|
||||
]
|
||||
expect(ABS.all_job_resources_accounted_for(allocated_resources, hosts)).to eq(true)
|
||||
end
|
||||
|
|
@ -126,16 +131,16 @@ describe ABS do
|
|||
|
||||
it 'will skip a line with a null value returned from abs' do
|
||||
stub_request(:get, 'https://abs.example.com/api/v2/status/queue')
|
||||
.to_return(:status => 200, :body => @active_requests_response, :headers => {})
|
||||
.to_return(status: 200, body: @active_requests_response, headers: {})
|
||||
|
||||
ret = ABS.get_active_requests(false, @abs_url, @test_user)
|
||||
|
||||
expect(ret[0]).to include(
|
||||
'allocated_resources' => [{
|
||||
'hostname' => 'take-this.delivery.puppetlabs.net',
|
||||
'type' => 'win-2012r2-x86_64',
|
||||
'engine' => 'vmpooler',
|
||||
}],
|
||||
'type' => 'win-2012r2-x86_64',
|
||||
'engine' => 'vmpooler'
|
||||
}]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
@ -147,7 +152,7 @@ describe ABS do
|
|||
[
|
||||
{ "state":"allocated", "last_processed":"2020-01-17 22:29:13 +0000", "allocated_resources":[{"hostname":"craggy-chord.delivery.puppetlabs.net", "type":"centos-7-x86_64", "engine":"vmpooler"}, {"hostname":"visible-revival.delivery.puppetlabs.net", "type":"centos-7-x86_64", "engine":"vmpooler"}], "audit_log":{"2020-01-17 22:28:45 +0000":"Allocated craggy-chord.delivery.puppetlabs.net, visible-revival.delivery.puppetlabs.net for job 1579300120799"}, "request":{"resources":{"centos-7-x86_64":2}, "job":{"id":"1579300120799", "tags":{"user":"test-user"}, "user":"test-user", "time-received":1579300120}, "priority":3}}
|
||||
]'
|
||||
@return_request = { '{"job_id":"1579300120799","hosts":{"hostname":"craggy-chord.delivery.puppetlabs.net","type":"centos-7-x86_64","engine":"vmpooler"},{"hostname":"visible-revival.delivery.puppetlabs.net","type":"centos-7-x86_64","engine":"vmpooler"}}'=>true }
|
||||
@return_request = { '{"job_id":"1579300120799","hosts":{"hostname":"craggy-chord.delivery.puppetlabs.net","type":"centos-7-x86_64","engine":"vmpooler"},{"hostname":"visible-revival.delivery.puppetlabs.net","type":"centos-7-x86_64","engine":"vmpooler"}}' => true }
|
||||
# rubocop:enable Layout/LineLength
|
||||
@token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
|
||||
@test_user = 'test-user'
|
||||
|
|
@ -157,15 +162,15 @@ describe ABS do
|
|||
|
||||
it 'will delete the whole job' do
|
||||
stub_request(:get, 'https://abs.example.com/api/v2/status/queue')
|
||||
.to_return(:status => 200, :body => @active_requests_response, :headers => {})
|
||||
.to_return(status: 200, body: @active_requests_response, headers: {})
|
||||
stub_request(:post, 'https://abs.example.com/api/v2/return')
|
||||
.with(:body => @return_request)
|
||||
.to_return(:status => 200, :body => 'OK', :headers => {})
|
||||
.with(body: @return_request)
|
||||
.to_return(status: 200, body: 'OK', headers: {})
|
||||
|
||||
ret = ABS.delete(false, @abs_url, @hosts, @token, @test_user)
|
||||
|
||||
expect(ret).to include(
|
||||
'craggy-chord.delivery.puppetlabs.net' => { 'ok'=>true }, 'visible-revival.delivery.puppetlabs.net' => { 'ok'=>true },
|
||||
'craggy-chord.delivery.puppetlabs.net' => { 'ok' => true }, 'visible-revival.delivery.puppetlabs.net' => { 'ok' => true }
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ describe Pooler do
|
|||
|
||||
it 'returns a token from vmpooler' do
|
||||
stub_request(:post, 'https://first.last:password@vmpooler.example.com/token')
|
||||
.to_return(:status => 200, :body => @get_token_response, :headers => {})
|
||||
.to_return(status: 200, body: @get_token_response, headers: {})
|
||||
|
||||
token = Auth.get_token(false, @vmpooler_url, 'first.last', 'password')
|
||||
expect(token).to eq @token
|
||||
|
|
@ -24,7 +24,7 @@ describe Pooler do
|
|||
|
||||
it 'raises a token error if something goes wrong' do
|
||||
stub_request(:post, 'https://first.last:password@vmpooler.example.com/token')
|
||||
.to_return(:status => 500, :body => '{"ok":false}', :headers => {})
|
||||
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
||||
|
||||
expect { Auth.get_token(false, @vmpooler_url, 'first.last', 'password') }.to raise_error(TokenError)
|
||||
end
|
||||
|
|
@ -38,14 +38,15 @@ describe Pooler do
|
|||
|
||||
it 'deletes the specified token' do
|
||||
stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
||||
.to_return(:status => 200, :body => @delete_token_response, :headers => {})
|
||||
.to_return(status: 200, body: @delete_token_response, headers: {})
|
||||
|
||||
expect(Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token)).to eq JSON.parse(@delete_token_response)
|
||||
expect(Auth.delete_token(false, @vmpooler_url, 'first.last', 'password',
|
||||
@token)).to eq JSON.parse(@delete_token_response)
|
||||
end
|
||||
|
||||
it 'raises a token error if something goes wrong' do
|
||||
stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
||||
.to_return(:status => 500, :body => '{"ok":false}', :headers => {})
|
||||
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
||||
|
||||
expect { Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token) }.to raise_error(TokenError)
|
||||
end
|
||||
|
|
@ -63,14 +64,14 @@ describe Pooler do
|
|||
|
||||
it 'checks the status of a token' do
|
||||
stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
||||
.to_return(:status => 200, :body => @token_status_response, :headers => {})
|
||||
.to_return(status: 200, body: @token_status_response, headers: {})
|
||||
|
||||
expect(Auth.token_status(false, @vmpooler_url, @token)).to eq JSON.parse(@token_status_response)
|
||||
end
|
||||
|
||||
it 'raises a token error if something goes wrong' do
|
||||
stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
||||
.to_return(:status => 500, :body => '{"ok":false}', :headers => {})
|
||||
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
||||
|
||||
expect { Auth.token_status(false, @vmpooler_url, @token) }.to raise_error(TokenError)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ describe NonstandardPooler do
|
|||
before :each do
|
||||
@nspooler_url = 'https://nspooler.example.com'
|
||||
@auth_token_headers = {
|
||||
'X-Auth-Token' => 'token-value',
|
||||
'X-Auth-Token' => 'token-value'
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ describe NonstandardPooler do
|
|||
|
||||
it 'returns an array with operating systems from the pooler' do
|
||||
stub_request(:get, "#{@nspooler_url}/status")
|
||||
.to_return(:status => 200, :body => @status_response_body, :headers => {})
|
||||
.to_return(status: 200, body: @status_response_body, headers: {})
|
||||
|
||||
list = NonstandardPooler.list(false, @nspooler_url, nil)
|
||||
expect(list).to be_an_instance_of Array
|
||||
|
|
@ -44,7 +44,7 @@ describe NonstandardPooler do
|
|||
|
||||
it 'filters operating systems based on the filter param' do
|
||||
stub_request(:get, "#{@nspooler_url}/status")
|
||||
.to_return(:status => 200, :body => @status_response_body, :headers => {})
|
||||
.to_return(status: 200, body: @status_response_body, headers: {})
|
||||
|
||||
list = NonstandardPooler.list(false, @nspooler_url, 'aix')
|
||||
expect(list).to be_an_instance_of Array
|
||||
|
|
@ -53,7 +53,7 @@ describe NonstandardPooler do
|
|||
|
||||
it 'returns nothing if the filter does not match' do
|
||||
stub_request(:get, "#{@nspooler_url}/status")
|
||||
.to_return(:status => 199, :body => @status_response_body, :headers => {})
|
||||
.to_return(status: 199, body: @status_response_body, headers: {})
|
||||
|
||||
list = NonstandardPooler.list(false, @nspooler_url, 'windows')
|
||||
expect(list).to be_an_instance_of Array
|
||||
|
|
@ -89,7 +89,7 @@ describe NonstandardPooler do
|
|||
.and_return(JSON.parse(@token_status_body_active))
|
||||
|
||||
list = NonstandardPooler.list_active(false, @nspooler_url, 'token-value', 'user')
|
||||
expect(list).to eql ['sol10-9', 'sol10-11']
|
||||
expect(list).to eql %w[sol10-9 sol10-11]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -121,17 +121,19 @@ describe NonstandardPooler do
|
|||
|
||||
it 'raises an AuthError if the token is invalid' do
|
||||
stub_request(:post, "#{@nspooler_url}/host/solaris-11-sparc")
|
||||
.with(:headers => @auth_token_headers)
|
||||
.to_return(:status => 401, :body => '{"ok":false,"reason": "token: token-value does not exist"}', :headers => {})
|
||||
.with(headers: @auth_token_headers)
|
||||
.to_return(status: 401, body: '{"ok":false,"reason": "token: token-value does not exist"}', headers: {})
|
||||
|
||||
vm_hash = { 'solaris-11-sparc' => 1 }
|
||||
expect { NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {}) }.to raise_error(AuthError)
|
||||
expect do
|
||||
NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {})
|
||||
end.to raise_error(AuthError)
|
||||
end
|
||||
|
||||
it 'retrieves a single vm with a token' do
|
||||
stub_request(:post, "#{@nspooler_url}/host/solaris-11-sparc")
|
||||
.with(:headers => @auth_token_headers)
|
||||
.to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
|
||||
.with(headers: @auth_token_headers)
|
||||
.to_return(status: 200, body: @retrieve_response_body_single, headers: {})
|
||||
|
||||
vm_hash = { 'solaris-11-sparc' => 1 }
|
||||
vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {})
|
||||
|
|
@ -142,15 +144,16 @@ describe NonstandardPooler do
|
|||
|
||||
it 'retrieves a multiple vms with a token' do
|
||||
stub_request(:post, "#{@nspooler_url}/host/aix-7.1-power+solaris-10-sparc+solaris-10-sparc")
|
||||
.with(:headers => @auth_token_headers)
|
||||
.to_return(:status => 200, :body => @retrieve_response_body_many, :headers => {})
|
||||
.with(headers: @auth_token_headers)
|
||||
.to_return(status: 200, body: @retrieve_response_body_many, headers: {})
|
||||
|
||||
vm_hash = { 'aix-7.1-power' => 1, 'solaris-10-sparc' => 2 }
|
||||
vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {})
|
||||
expect(vm_req).to be_an_instance_of Hash
|
||||
expect(vm_req['ok']).to equal true
|
||||
expect(vm_req['solaris-10-sparc']['hostname']).to be_an_instance_of Array
|
||||
expect(vm_req['solaris-10-sparc']['hostname']).to eq ['sol10-9.delivery.puppetlabs.net', 'sol10-10.delivery.puppetlabs.net']
|
||||
expect(vm_req['solaris-10-sparc']['hostname']).to eq ['sol10-9.delivery.puppetlabs.net',
|
||||
'sol10-10.delivery.puppetlabs.net']
|
||||
expect(vm_req['aix-7.1-power']['hostname']).to eq 'pe-aix-71-ci-acceptance.delivery.puppetlabs.net'
|
||||
end
|
||||
end
|
||||
|
|
@ -162,10 +165,10 @@ describe NonstandardPooler do
|
|||
|
||||
it 'raises an error if the user tries to modify an unsupported attribute' do
|
||||
stub_request(:put, 'https://nspooler.example.com/host/myfakehost')
|
||||
.with(:body => { '{}' => true },
|
||||
:headers => @auth_token_headers)
|
||||
.to_return(:status => 200, :body => '', :headers => {})
|
||||
details = { :lifetime => 12 }
|
||||
.with(body: { '{}' => true },
|
||||
headers: @auth_token_headers)
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
details = { lifetime: 12 }
|
||||
expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) }
|
||||
.to raise_error(ModifyError)
|
||||
end
|
||||
|
|
@ -173,11 +176,11 @@ describe NonstandardPooler do
|
|||
it 'modifies the reason of a vm' do
|
||||
modify_request_body = { '{"reserved_for_reason":"testing"}' => true }
|
||||
stub_request(:put, "#{@nspooler_url}/host/myfakehost")
|
||||
.with(:body => modify_request_body,
|
||||
:headers => @auth_token_headers)
|
||||
.to_return(:status => 200, :body => '{"ok": true}', :headers => {})
|
||||
.with(body: modify_request_body,
|
||||
headers: @auth_token_headers)
|
||||
.to_return(status: 200, body: '{"ok": true}', headers: {})
|
||||
|
||||
modify_hash = { :reason => 'testing' }
|
||||
modify_hash = { reason: 'testing' }
|
||||
modify_req = NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', modify_hash)
|
||||
expect(modify_req['ok']).to be true
|
||||
end
|
||||
|
|
@ -208,7 +211,7 @@ describe NonstandardPooler do
|
|||
|
||||
it 'prints the status' do
|
||||
stub_request(:get, "#{@nspooler_url}/status")
|
||||
.to_return(:status => 200, :body => @status_response_body, :headers => {})
|
||||
.to_return(status: 200, body: @status_response_body, headers: {})
|
||||
|
||||
status = NonstandardPooler.status(false, @nspooler_url)
|
||||
expect(status).to be_an_instance_of Hash
|
||||
|
|
@ -231,7 +234,7 @@ describe NonstandardPooler do
|
|||
|
||||
it 'prints the summary' do
|
||||
stub_request(:get, "#{@nspooler_url}/summary")
|
||||
.to_return(:status => 200, :body => @status_response_body, :headers => {})
|
||||
.to_return(status: 200, body: @status_response_body, headers: {})
|
||||
|
||||
summary = NonstandardPooler.summary(false, @nspooler_url)
|
||||
expect(summary).to be_an_instance_of Hash
|
||||
|
|
@ -256,7 +259,7 @@ describe NonstandardPooler do
|
|||
|
||||
it 'makes a query about a vm' do
|
||||
stub_request(:get, "#{@nspooler_url}/host/sol10-11")
|
||||
.to_return(:status => 200, :body => @query_response_body, :headers => {})
|
||||
.to_return(status: 200, body: @query_response_body, headers: {})
|
||||
|
||||
query_req = NonstandardPooler.query(false, @nspooler_url, 'sol10-11')
|
||||
expect(query_req).to be_an_instance_of Hash
|
||||
|
|
@ -271,8 +274,8 @@ describe NonstandardPooler do
|
|||
|
||||
it 'deletes a single existing vm' do
|
||||
stub_request(:delete, "#{@nspooler_url}/host/sol11-7")
|
||||
.with(:headers => @auth_token_headers)
|
||||
.to_return(:status => 200, :body => @delete_response_success, :headers => {})
|
||||
.with(headers: @auth_token_headers)
|
||||
.to_return(status: 200, body: @delete_response_success, headers: {})
|
||||
|
||||
request = NonstandardPooler.delete(false, @nspooler_url, 'sol11-7', 'token-value', nil)
|
||||
expect(request['sol11-7']['ok']).to be true
|
||||
|
|
@ -280,8 +283,8 @@ describe NonstandardPooler do
|
|||
|
||||
it 'does not delete a nonexistant vm' do
|
||||
stub_request(:delete, "#{@nspooler_url}/host/fakehost")
|
||||
.with(:headers => @auth_token_headers)
|
||||
.to_return(:status => 401, :body => @delete_response_failure, :headers => {})
|
||||
.with(headers: @auth_token_headers)
|
||||
.to_return(status: 401, body: @delete_response_failure, headers: {})
|
||||
|
||||
request = NonstandardPooler.delete(false, @nspooler_url, 'fakehost', 'token-value', nil)
|
||||
expect(request['fakehost']['ok']).to be false
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ describe Pooler do
|
|||
|
||||
it 'returns a hash with operating systems from the pooler' do
|
||||
stub_request(:get, "#{@vmpooler_url}/vm")
|
||||
.to_return(:status => 200, :body => @list_response_body, :headers => {})
|
||||
.to_return(status: 200, body: @list_response_body, headers: {})
|
||||
|
||||
list = Pooler.list(false, @vmpooler_url, nil)
|
||||
expect(list).to be_an_instance_of Array
|
||||
|
|
@ -23,7 +23,7 @@ describe Pooler do
|
|||
|
||||
it 'filters operating systems based on the filter param' do
|
||||
stub_request(:get, "#{@vmpooler_url}/vm")
|
||||
.to_return(:status => 200, :body => @list_response_body, :headers => {})
|
||||
.to_return(status: 200, body: @list_response_body, headers: {})
|
||||
|
||||
list = Pooler.list(false, @vmpooler_url, 'deb')
|
||||
expect(list).to be_an_instance_of Array
|
||||
|
|
@ -32,7 +32,7 @@ describe Pooler do
|
|||
|
||||
it 'returns nothing if the filter does not match' do
|
||||
stub_request(:get, "#{@vmpooler_url}/vm")
|
||||
.to_return(:status => 200, :body => @list_response_body, :headers => {})
|
||||
.to_return(status: 200, body: @list_response_body, headers: {})
|
||||
|
||||
list = Pooler.list(false, @vmpooler_url, 'windows')
|
||||
expect(list).to be_an_instance_of Array
|
||||
|
|
@ -48,8 +48,8 @@ describe Pooler do
|
|||
|
||||
it 'raises an AuthError if the token is invalid' do
|
||||
stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386")
|
||||
.with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(:status => 401, :body => '{"ok":false}', :headers => {})
|
||||
.with(headers: { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(status: 401, body: '{"ok":false}', headers: {})
|
||||
|
||||
vm_hash = {}
|
||||
vm_hash['debian-7-i386'] = 1
|
||||
|
|
@ -58,8 +58,8 @@ describe Pooler do
|
|||
|
||||
it 'retrieves a single vm with a token' do
|
||||
stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386")
|
||||
.with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
|
||||
.with(headers: { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(status: 200, body: @retrieve_response_body_single, headers: {})
|
||||
|
||||
vm_hash = {}
|
||||
vm_hash['debian-7-i386'] = 1
|
||||
|
|
@ -71,8 +71,8 @@ describe Pooler do
|
|||
|
||||
it 'retrieves a multiple vms with a token' do
|
||||
stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386+debian-7-i386+centos-7-x86_64")
|
||||
.with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(:status => 200, :body => @retrieve_response_body_double, :headers => {})
|
||||
.with(headers: { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(status: 200, body: @retrieve_response_body_double, headers: {})
|
||||
|
||||
vm_hash = {}
|
||||
vm_hash['debian-7-i386'] = 2
|
||||
|
|
@ -89,11 +89,11 @@ describe Pooler do
|
|||
let(:ondemand_response) { '{"ok":true,"request_id":"1234"}' }
|
||||
it 'retreives the vm with a token' do
|
||||
stub_request(:post, "#{@vmpooler_url}/ondemandvm/debian-7-i386")
|
||||
.with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(:status => 200, :body => ondemand_response, :headers => {})
|
||||
.with(headers: { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(status: 200, body: ondemand_response, headers: {})
|
||||
|
||||
stub_request(:get, "#{@vmpooler_url}/ondemandvm/1234")
|
||||
.to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
|
||||
.to_return(status: 200, body: @retrieve_response_body_single, headers: {})
|
||||
|
||||
vm_hash = {}
|
||||
vm_hash['debian-7-i386'] = 1
|
||||
|
|
@ -117,11 +117,11 @@ describe Pooler do
|
|||
end
|
||||
|
||||
it 'modifies the TTL of a vm' do
|
||||
modify_hash = { :lifetime => 12 }
|
||||
modify_hash = { lifetime: 12 }
|
||||
stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
|
||||
.with(:body => { '{"lifetime":12}' => true },
|
||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded', 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(:status => 200, :body => @modify_response_body_success, :headers => {})
|
||||
.with(body: { '{"lifetime":12}' => true },
|
||||
headers: { 'Content-Type' => 'application/x-www-form-urlencoded', 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(status: 200, body: @modify_response_body_success, headers: {})
|
||||
|
||||
modify_req = Pooler.modify(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', modify_hash)
|
||||
expect(modify_req['ok']).to be true
|
||||
|
|
@ -136,8 +136,8 @@ describe Pooler do
|
|||
|
||||
it 'deletes a specified vm' do
|
||||
stub_request(:delete, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
|
||||
.with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(:status => 200, :body => @delete_response_body_success, :headers => {})
|
||||
.with(headers: { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(status: 200, body: @delete_response_body_success, headers: {})
|
||||
|
||||
expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile', nil)).to eq @delete_response
|
||||
end
|
||||
|
|
@ -155,7 +155,7 @@ describe Pooler do
|
|||
|
||||
it 'prints the status' do
|
||||
stub_request(:get, "#{@vmpooler_url}/status")
|
||||
.to_return(:status => 200, :body => @status_response_body, :headers => {})
|
||||
.to_return(status: 200, body: @status_response_body, headers: {})
|
||||
|
||||
status = Pooler.status(false, @vmpooler_url)
|
||||
expect(status).to be_an_instance_of Hash
|
||||
|
|
@ -178,7 +178,7 @@ describe Pooler do
|
|||
|
||||
it 'makes a query about a vm' do
|
||||
stub_request(:get, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
|
||||
.to_return(:status => 200, :body => @query_response_body, :headers => {})
|
||||
.to_return(status: 200, body: @query_response_body, headers: {})
|
||||
|
||||
query_req = Pooler.query(false, @vmpooler_url, 'fq6qlpjlsskycq6')
|
||||
expect(query_req).to be_an_instance_of Hash
|
||||
|
|
@ -192,8 +192,8 @@ describe Pooler do
|
|||
|
||||
it 'makes a snapshot for a single vm' do
|
||||
stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot")
|
||||
.with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(:status => 200, :body => @snapshot_response_body, :headers => {})
|
||||
.with(headers: { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(status: 200, body: @snapshot_response_body, headers: {})
|
||||
|
||||
snapshot_req = Pooler.snapshot(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile')
|
||||
expect(snapshot_req['ok']).to be true
|
||||
|
|
@ -207,15 +207,18 @@ describe Pooler do
|
|||
|
||||
it 'makes a request to revert a vm from a snapshot' do
|
||||
stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot/dAfewKNfaweLKNve")
|
||||
.with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(:status => 200, :body => @revert_response_body, :headers => {})
|
||||
.with(headers: { 'X-Auth-Token' => 'mytokenfile' })
|
||||
.to_return(status: 200, body: @revert_response_body, headers: {})
|
||||
|
||||
revert_req = Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 'dAfewKNfaweLKNve')
|
||||
expect(revert_req['ok']).to be true
|
||||
end
|
||||
|
||||
it "doesn't make a request to revert a vm if snapshot is not provided" do
|
||||
expect { Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', nil) }.to raise_error(RuntimeError, 'Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6')
|
||||
expect do
|
||||
Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile',
|
||||
nil)
|
||||
end.to raise_error(RuntimeError, 'Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6')
|
||||
end
|
||||
|
||||
it 'raises a TokenError if no token was provided' do
|
||||
|
|
@ -231,7 +234,7 @@ describe Pooler do
|
|||
|
||||
it 'makes a request to extend disk space of a vm' do
|
||||
stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/disk/12")
|
||||
.with(:headers => { 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @disk_response_body_success, :headers => {})
|
||||
.with(headers: { 'X-Auth-Token' => 'mytokenfile' }).to_return(status: 200, body: @disk_response_body_success, headers: {})
|
||||
|
||||
disk_req = Pooler.disk(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 12)
|
||||
expect(disk_req['ok']).to be true
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ describe Service do
|
|||
it 'prompts the user for their password and retrieves a token' do
|
||||
config = { 'user' => 'first.last', 'url' => 'http://default.url' }
|
||||
service = Service.new(MockOptions.new, config)
|
||||
allow(STDOUT).to receive(:puts).with('Enter your http://default.url service password:')
|
||||
allow($stdout).to receive(:puts).with('Enter your http://default.url service password:')
|
||||
allow(Commander::UI).to(receive(:password)
|
||||
.with('Enter your http://default.url service password:', '*')
|
||||
.and_return('hunter2'))
|
||||
|
|
@ -29,9 +29,9 @@ describe Service do
|
|||
it 'prompts the user for their username and password if the username is unknown' do
|
||||
config = { 'url' => 'http://default.url' }
|
||||
service = Service.new(MockOptions.new({}), config)
|
||||
allow(STDOUT).to receive(:puts).with 'Enter your http://default.url service username:'
|
||||
allow(STDOUT).to receive(:puts).with "\n"
|
||||
allow(STDIN).to receive(:gets).and_return('first.last')
|
||||
allow($stdout).to receive(:puts).with 'Enter your http://default.url service username:'
|
||||
allow($stdout).to receive(:puts).with "\n"
|
||||
allow($stdin).to receive(:gets).and_return('first.last')
|
||||
allow(Commander::UI).to(receive(:password)
|
||||
.with('Enter your http://default.url service password:', '*')
|
||||
.and_return('hunter2'))
|
||||
|
|
@ -59,16 +59,16 @@ describe Service do
|
|||
it 'reports the status of a token' do
|
||||
config = {
|
||||
'user' => 'first.last',
|
||||
'url' => 'http://default.url',
|
||||
'url' => 'http://default.url'
|
||||
}
|
||||
options = MockOptions.new('token' => 'token-value')
|
||||
service = Service.new(options, config)
|
||||
status = {
|
||||
'ok' => true,
|
||||
'user' => config['user'],
|
||||
'created' => '2017-09-22 02:04:18 +0000',
|
||||
'last_accessed' => '2017-09-22 02:04:28 +0000',
|
||||
'reserved_hosts' => [],
|
||||
'ok' => true,
|
||||
'user' => config['user'],
|
||||
'created' => '2017-09-22 02:04:18 +0000',
|
||||
'last_accessed' => '2017-09-22 02:04:28 +0000',
|
||||
'reserved_hosts' => []
|
||||
}
|
||||
allow(Auth).to(receive(:token_status)
|
||||
.with(nil, config['url'], 'token-value')
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@ class ServiceStub
|
|||
if os_types.keys[0] == 'abs_host_string'
|
||||
return {
|
||||
os_types.keys[0] => { 'hostname' => ['abs-hostname.delivery.puppetlabs.net'] },
|
||||
'ok' => true,
|
||||
'ok' => true
|
||||
}
|
||||
end
|
||||
|
||||
{
|
||||
os_types.keys[0] => { 'hostname' => 'vmpooler-hostname' },
|
||||
'domain' => 'delivery.puppetlabs.net',
|
||||
'ok' => true,
|
||||
'domain' => 'delivery.puppetlabs.net',
|
||||
'ok' => true
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -36,13 +36,14 @@ describe Utils do
|
|||
|
||||
it 'formats a result from vmpooler into a hash of os to hostnames' do
|
||||
result = Utils.standardize_hostnames(JSON.parse(@vmpooler_response_body))
|
||||
expect(result).to eq('centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
|
||||
'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net'])
|
||||
expect(result).to eq('centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
|
||||
'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net',
|
||||
'ctnktsd0u11p9tm.delivery.mycompany.net'])
|
||||
end
|
||||
|
||||
it 'formats a result from the nonstandard pooler into a hash of os to hostnames' do
|
||||
result = Utils.standardize_hostnames(JSON.parse(@nonstandard_response_body))
|
||||
expect(result).to eq('solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
|
||||
expect(result).to eq('solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
|
||||
'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'])
|
||||
end
|
||||
end
|
||||
|
|
@ -50,12 +51,12 @@ describe Utils do
|
|||
describe '#format_host_output' do
|
||||
before :each do
|
||||
@vmpooler_results = {
|
||||
'centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
|
||||
'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net'],
|
||||
'centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
|
||||
'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net']
|
||||
}
|
||||
@nonstandard_results = {
|
||||
'solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
|
||||
'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'],
|
||||
'solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
|
||||
'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net']
|
||||
}
|
||||
@vmpooler_output = <<~OUT.chomp
|
||||
- dlgietfmgeegry2.delivery.mycompany.net (centos-7-x86_64)
|
||||
|
|
@ -98,23 +99,23 @@ describe Utils do
|
|||
describe '#get_service_config' do
|
||||
before :each do
|
||||
@default_config = {
|
||||
'url' => 'http://default.url',
|
||||
'user' => 'first.last.default',
|
||||
'token' => 'default-token',
|
||||
'url' => 'http://default.url',
|
||||
'user' => 'first.last.default',
|
||||
'token' => 'default-token'
|
||||
}
|
||||
@services_config = {
|
||||
'services' => {
|
||||
'vm' => {
|
||||
'url' => 'http://vmpooler.url',
|
||||
'user' => 'first.last.vmpooler',
|
||||
'token' => 'vmpooler-token',
|
||||
'url' => 'http://vmpooler.url',
|
||||
'user' => 'first.last.vmpooler',
|
||||
'token' => 'vmpooler-token'
|
||||
},
|
||||
'ns' => {
|
||||
'url' => 'http://nspooler.url',
|
||||
'user' => 'first.last.nspooler',
|
||||
'token' => 'nspooler-token',
|
||||
},
|
||||
},
|
||||
'url' => 'http://nspooler.url',
|
||||
'user' => 'first.last.nspooler',
|
||||
'token' => 'nspooler-token'
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -126,26 +127,26 @@ describe Utils do
|
|||
|
||||
it 'allows selection by configured service key' do
|
||||
config = @default_config.merge @services_config
|
||||
options = MockOptions.new(:service => 'ns')
|
||||
options = MockOptions.new(service: 'ns')
|
||||
expect(Utils.get_service_config(config, options)).to include @services_config['services']['ns']
|
||||
end
|
||||
|
||||
it 'uses top-level service config values as defaults when configured service values are missing' do
|
||||
config = @default_config.merge @services_config
|
||||
config['services']['vm'].delete 'url'
|
||||
options = MockOptions.new(:service => 'vm')
|
||||
options = MockOptions.new(service: 'vm')
|
||||
expect(Utils.get_service_config(config, options)['url']).to eq 'http://default.url'
|
||||
end
|
||||
|
||||
it "raises an error if passed a service name that hasn't been configured" do
|
||||
config = @default_config.merge @services_config
|
||||
options = MockOptions.new(:service => 'none')
|
||||
options = MockOptions.new(service: 'none')
|
||||
expect { Utils.get_service_config(config, options) }.to raise_error ArgumentError
|
||||
end
|
||||
|
||||
it 'prioritizes values passed as command line options over configuration options' do
|
||||
config = @default_config
|
||||
options = MockOptions.new(:url => 'http://alternate.url', :token => 'alternate-token')
|
||||
options = MockOptions.new(url: 'http://alternate.url', token: 'alternate-token')
|
||||
expected = config.merge('url' => 'http://alternate.url', 'token' => 'alternate-token')
|
||||
expect(Utils.get_service_config(config, options)).to include expected
|
||||
end
|
||||
|
|
@ -182,15 +183,15 @@ describe Utils do
|
|||
{
|
||||
'template' => 'ubuntu-1604-x86_64',
|
||||
'lifetime' => 12,
|
||||
'running' => 9.66,
|
||||
'state' => 'running',
|
||||
'ip' => '127.0.0.1',
|
||||
'domain' => domain,
|
||||
'running' => 9.66,
|
||||
'state' => 'running',
|
||||
'ip' => '127.0.0.1',
|
||||
'domain' => domain
|
||||
}
|
||||
end
|
||||
|
||||
it 'outputs fqdn for host' do
|
||||
expect(STDOUT).to receive(:puts).with(fqdn)
|
||||
expect($stdout).to receive(:puts).with(fqdn)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -201,17 +202,17 @@ describe Utils do
|
|||
let(:hostname) { 'sol11-9.delivery.mycompany.net' }
|
||||
let(:host_data) do
|
||||
{
|
||||
'fqdn' => hostname,
|
||||
'os_triple' => 'solaris-11-sparc',
|
||||
'reserved_by_user' => 'first.last',
|
||||
'reserved_for_reason' => '',
|
||||
'hours_left_on_reservation' => 35.89,
|
||||
'fqdn' => hostname,
|
||||
'os_triple' => 'solaris-11-sparc',
|
||||
'reserved_by_user' => 'first.last',
|
||||
'reserved_for_reason' => '',
|
||||
'hours_left_on_reservation' => 35.89
|
||||
}
|
||||
end
|
||||
let(:fqdn) { hostname } # for nspooler these are the same
|
||||
|
||||
it 'outputs fqdn for host' do
|
||||
expect(STDOUT).to receive(:puts).with(fqdn)
|
||||
expect($stdout).to receive(:puts).with(fqdn)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -231,19 +232,19 @@ describe Utils do
|
|||
{
|
||||
'hostname' => fqdn,
|
||||
'type' => template,
|
||||
'enging' => 'vmpooler',
|
||||
},
|
||||
'enging' => 'vmpooler'
|
||||
}
|
||||
],
|
||||
'request' => {
|
||||
'job' => {
|
||||
'id' => hostname,
|
||||
'id' => hostname
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
it 'outputs fqdn for host' do
|
||||
expect(STDOUT).to receive(:puts).with(fqdn)
|
||||
expect($stdout).to receive(:puts).with(fqdn)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -275,10 +276,10 @@ describe Utils do
|
|||
hostname => {
|
||||
'template' => 'ubuntu-1604-x86_64',
|
||||
'lifetime' => 12,
|
||||
'running' => 9.66,
|
||||
'state' => 'running',
|
||||
'ip' => '127.0.0.1',
|
||||
'domain' => domain,
|
||||
'running' => 9.66,
|
||||
'state' => 'running',
|
||||
'ip' => '127.0.0.1',
|
||||
'domain' => domain
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
@ -286,7 +287,7 @@ describe Utils do
|
|||
let(:default_output) { "- #{fqdn} (running, ubuntu-1604-x86_64, 9.66/12 hours)" }
|
||||
|
||||
it 'prints output with host fqdn, template and duration info' do
|
||||
expect(STDOUT).to receive(:puts).with(default_output)
|
||||
expect($stdout).to receive(:puts).with(default_output)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -298,14 +299,14 @@ describe Utils do
|
|||
hostname => {
|
||||
'template' => 'redhat-7-x86_64',
|
||||
'lifetime' => 48,
|
||||
'running' => 7.67,
|
||||
'state' => 'running',
|
||||
'tags' => {
|
||||
'running' => 7.67,
|
||||
'state' => 'running',
|
||||
'tags' => {
|
||||
'user' => 'bob',
|
||||
'role' => 'agent',
|
||||
'role' => 'agent'
|
||||
},
|
||||
'ip' => '127.0.0.1',
|
||||
'domain' => domain,
|
||||
'ip' => '127.0.0.1',
|
||||
'domain' => domain
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
@ -313,7 +314,7 @@ describe Utils do
|
|||
it 'prints output with host fqdn, template, duration info, and tags' do
|
||||
output = "- #{fqdn} (running, redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)"
|
||||
|
||||
expect(STDOUT).to receive(:puts).with(output)
|
||||
expect($stdout).to receive(:puts).with(output)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -323,7 +324,7 @@ describe Utils do
|
|||
let(:print_to_stderr) { true }
|
||||
|
||||
it 'outputs to stderr instead of stdout' do
|
||||
expect(STDERR).to receive(:puts).with(default_output)
|
||||
expect($stderr).to receive(:puts).with(default_output)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -337,11 +338,11 @@ describe Utils do
|
|||
let(:response_body) do
|
||||
{
|
||||
hostname => {
|
||||
'fqdn' => hostname,
|
||||
'os_triple' => 'solaris-11-sparc',
|
||||
'reserved_by_user' => 'first.last',
|
||||
'reserved_for_reason' => '',
|
||||
'hours_left_on_reservation' => 35.89,
|
||||
'fqdn' => hostname,
|
||||
'os_triple' => 'solaris-11-sparc',
|
||||
'reserved_by_user' => 'first.last',
|
||||
'reserved_for_reason' => '',
|
||||
'hours_left_on_reservation' => 35.89
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
@ -349,7 +350,7 @@ describe Utils do
|
|||
let(:default_output) { "- #{hostname} (solaris-11-sparc, 35.89h remaining)" }
|
||||
|
||||
it 'prints output with host, template, and time remaining' do
|
||||
expect(STDOUT).to receive(:puts).with(default_output)
|
||||
expect($stdout).to receive(:puts).with(default_output)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -358,11 +359,11 @@ describe Utils do
|
|||
let(:response_body) do
|
||||
{
|
||||
hostname => {
|
||||
'fqdn' => hostname,
|
||||
'os_triple' => 'solaris-11-sparc',
|
||||
'reserved_by_user' => 'first.last',
|
||||
'reserved_for_reason' => 'testing',
|
||||
'hours_left_on_reservation' => 35.89,
|
||||
'fqdn' => hostname,
|
||||
'os_triple' => 'solaris-11-sparc',
|
||||
'reserved_by_user' => 'first.last',
|
||||
'reserved_for_reason' => 'testing',
|
||||
'hours_left_on_reservation' => 35.89
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
@ -370,7 +371,7 @@ describe Utils do
|
|||
it 'prints output with host, template, time remaining, and reason' do
|
||||
output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)'
|
||||
|
||||
expect(STDOUT).to receive(:puts).with(output)
|
||||
expect($stdout).to receive(:puts).with(output)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -380,7 +381,7 @@ describe Utils do
|
|||
let(:print_to_stderr) { true }
|
||||
|
||||
it 'outputs to stderr instead of stdout' do
|
||||
expect(STDERR).to receive(:puts).with(default_output)
|
||||
expect($stderr).to receive(:puts).with(default_output)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -392,7 +393,7 @@ describe Utils do
|
|||
|
||||
let(:hostname) { '1597952189390' }
|
||||
let(:fqdn) { 'example-noun.delivery.mycompany.net' }
|
||||
let(:fqdn_hostname) {'example-noun'}
|
||||
let(:fqdn_hostname) { 'example-noun' }
|
||||
let(:template) { 'ubuntu-1604-x86_64' }
|
||||
|
||||
# This seems to be the miminal stub response from ABS for the current output
|
||||
|
|
@ -404,14 +405,14 @@ describe Utils do
|
|||
{
|
||||
'hostname' => fqdn,
|
||||
'type' => template,
|
||||
'engine' => 'vmpooler',
|
||||
},
|
||||
'engine' => 'vmpooler'
|
||||
}
|
||||
],
|
||||
'request' => {
|
||||
'job' => {
|
||||
'id' => hostname,
|
||||
'id' => hostname
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
@ -420,58 +421,58 @@ describe Utils do
|
|||
let(:domain) { 'delivery.mycompany.net' }
|
||||
let(:response_body_vmpooler) do
|
||||
{
|
||||
fqdn_hostname => {
|
||||
'template' => template,
|
||||
'lifetime' => 48,
|
||||
'running' => 7.67,
|
||||
'state' => 'running',
|
||||
'tags' => {
|
||||
'user' => 'bob',
|
||||
'role' => 'agent',
|
||||
},
|
||||
'ip' => '127.0.0.1',
|
||||
'domain' => domain,
|
||||
}
|
||||
fqdn_hostname => {
|
||||
'template' => template,
|
||||
'lifetime' => 48,
|
||||
'running' => 7.67,
|
||||
'state' => 'running',
|
||||
'tags' => {
|
||||
'user' => 'bob',
|
||||
'role' => 'agent'
|
||||
},
|
||||
'ip' => '127.0.0.1',
|
||||
'domain' => domain
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
allow(Utils).to receive(:get_vmpooler_service_config).and_return({
|
||||
'url' => 'http://vmpooler.example.com',
|
||||
'token' => 'krypto-knight'
|
||||
})
|
||||
'url' => 'http://vmpooler.example.com',
|
||||
'token' => 'krypto-knight'
|
||||
})
|
||||
allow(service).to receive(:query)
|
||||
.with(anything, fqdn_hostname)
|
||||
.and_return(response_body_vmpooler)
|
||||
.with(anything, fqdn_hostname)
|
||||
.and_return(response_body_vmpooler)
|
||||
end
|
||||
|
||||
let(:default_output_first_line) { "- [JobID:#{hostname}] <allocated>" }
|
||||
let(:default_output_second_line) { " - #{fqdn} (#{template})" }
|
||||
|
||||
it 'prints output with job id, host, and template' do
|
||||
expect(STDOUT).to receive(:puts).with(default_output_first_line)
|
||||
expect(STDOUT).to receive(:puts).with(default_output_second_line)
|
||||
expect($stdout).to receive(:puts).with(default_output_first_line)
|
||||
expect($stdout).to receive(:puts).with(default_output_second_line)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it 'prints more information when vmpooler_fallback is set output with job id, host, template, lifetime, user and role' do
|
||||
fallback = {'vmpooler_fallback' => 'vmpooler'}
|
||||
fallback = { 'vmpooler_fallback' => 'vmpooler' }
|
||||
service.config.merge! fallback
|
||||
default_output_second_line=" - #{fqdn} (running, #{template}, 7.67/48 hours, user: bob, role: agent)"
|
||||
expect(STDOUT).to receive(:puts).with(default_output_first_line)
|
||||
expect(STDOUT).to receive(:puts).with(default_output_second_line)
|
||||
default_output_second_line = " - #{fqdn} (running, #{template}, 7.67/48 hours, user: bob, role: agent)"
|
||||
expect($stdout).to receive(:puts).with(default_output_first_line)
|
||||
expect($stdout).to receive(:puts).with(default_output_second_line)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it 'prints in red when destroyed' do
|
||||
fallback = {'vmpooler_fallback' => 'vmpooler'}
|
||||
fallback = { 'vmpooler_fallback' => 'vmpooler' }
|
||||
service.config.merge! fallback
|
||||
response_body_vmpooler[fqdn_hostname]['state'] = "destroyed"
|
||||
default_output_second_line_red=" - #{fqdn} (destroyed, #{template}, 7.67/48 hours, user: bob, role: agent)".red
|
||||
expect(STDOUT).to receive(:puts).with(default_output_first_line)
|
||||
expect(STDOUT).to receive(:puts).with(default_output_second_line_red)
|
||||
response_body_vmpooler[fqdn_hostname]['state'] = 'destroyed'
|
||||
default_output_second_line_red = " - #{fqdn} (destroyed, #{template}, 7.67/48 hours, user: bob, role: agent)".red
|
||||
expect($stdout).to receive(:puts).with(default_output_first_line)
|
||||
expect($stdout).to receive(:puts).with(default_output_second_line_red)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -480,8 +481,8 @@ describe Utils do
|
|||
let(:print_to_stderr) { true }
|
||||
|
||||
it 'outputs to stderr instead of stdout' do
|
||||
expect(STDERR).to receive(:puts).with(default_output_first_line)
|
||||
expect(STDERR).to receive(:puts).with(default_output_second_line)
|
||||
expect($stderr).to receive(:puts).with(default_output_first_line)
|
||||
expect($stderr).to receive(:puts).with(default_output_second_line)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -494,34 +495,34 @@ describe Utils do
|
|||
let(:hostname) { '1597952189390' }
|
||||
let(:fqdn) { 'this-noun.delivery.mycompany.net' }
|
||||
let(:fqdn_ns) { 'that-noun.delivery.mycompany.net' }
|
||||
let(:fqdn_hostname) {'this-noun'}
|
||||
let(:fqdn_ns_hostname) {'that-noun'}
|
||||
let(:fqdn_hostname) { 'this-noun' }
|
||||
let(:fqdn_ns_hostname) { 'that-noun' }
|
||||
let(:template) { 'ubuntu-1604-x86_64' }
|
||||
let(:template_ns) { 'solaris-10-sparc' }
|
||||
|
||||
# This seems to be the miminal stub response from ABS for the current output
|
||||
let(:response_body) do
|
||||
{
|
||||
hostname => {
|
||||
'state' => 'allocated',
|
||||
'allocated_resources' => [
|
||||
{
|
||||
'hostname' => fqdn,
|
||||
'type' => template,
|
||||
'engine' => 'vmpooler',
|
||||
},
|
||||
{
|
||||
'hostname' => fqdn_ns,
|
||||
'type' => template_ns,
|
||||
'engine' => 'nspooler',
|
||||
},
|
||||
],
|
||||
'request' => {
|
||||
'job' => {
|
||||
'id' => hostname,
|
||||
}
|
||||
},
|
||||
hostname => {
|
||||
'state' => 'allocated',
|
||||
'allocated_resources' => [
|
||||
{
|
||||
'hostname' => fqdn,
|
||||
'type' => template,
|
||||
'engine' => 'vmpooler'
|
||||
},
|
||||
{
|
||||
'hostname' => fqdn_ns,
|
||||
'type' => template_ns,
|
||||
'engine' => 'nspooler'
|
||||
}
|
||||
],
|
||||
'request' => {
|
||||
'job' => {
|
||||
'id' => hostname
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -529,29 +530,29 @@ describe Utils do
|
|||
let(:domain) { 'delivery.mycompany.net' }
|
||||
let(:response_body_vmpooler) do
|
||||
{
|
||||
fqdn_hostname => {
|
||||
'template' => template,
|
||||
'lifetime' => 48,
|
||||
'running' => 7.67,
|
||||
'state' => 'running',
|
||||
'tags' => {
|
||||
'user' => 'bob',
|
||||
'role' => 'agent',
|
||||
},
|
||||
'ip' => '127.0.0.1',
|
||||
'domain' => domain,
|
||||
}
|
||||
fqdn_hostname => {
|
||||
'template' => template,
|
||||
'lifetime' => 48,
|
||||
'running' => 7.67,
|
||||
'state' => 'running',
|
||||
'tags' => {
|
||||
'user' => 'bob',
|
||||
'role' => 'agent'
|
||||
},
|
||||
'ip' => '127.0.0.1',
|
||||
'domain' => domain
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
allow(Utils).to receive(:get_vmpooler_service_config).and_return({
|
||||
'url' => 'http://vmpooler.example.com',
|
||||
'token' => 'krypto-knight'
|
||||
'url' => 'http://vmpooler.example.com',
|
||||
'token' => 'krypto-knight'
|
||||
})
|
||||
allow(service).to receive(:query)
|
||||
.with(anything, fqdn_hostname)
|
||||
.and_return(response_body_vmpooler)
|
||||
.with(anything, fqdn_hostname)
|
||||
.and_return(response_body_vmpooler)
|
||||
end
|
||||
|
||||
let(:default_output_first_line) { "- [JobID:#{hostname}] <allocated>" }
|
||||
|
|
@ -559,9 +560,9 @@ describe Utils do
|
|||
let(:default_output_third_line) { " - #{fqdn_ns} (#{template_ns})" }
|
||||
|
||||
it 'prints output with job id, host, and template' do
|
||||
expect(STDOUT).to receive(:puts).with(default_output_first_line)
|
||||
expect(STDOUT).to receive(:puts).with(default_output_second_line)
|
||||
expect(STDOUT).to receive(:puts).with(default_output_third_line)
|
||||
expect($stdout).to receive(:puts).with(default_output_first_line)
|
||||
expect($stdout).to receive(:puts).with(default_output_second_line)
|
||||
expect($stdout).to receive(:puts).with(default_output_third_line)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -570,9 +571,9 @@ describe Utils do
|
|||
let(:print_to_stderr) { true }
|
||||
|
||||
it 'outputs to stderr instead of stdout' do
|
||||
expect(STDERR).to receive(:puts).with(default_output_first_line)
|
||||
expect(STDERR).to receive(:puts).with(default_output_second_line)
|
||||
expect(STDERR).to receive(:puts).with(default_output_third_line)
|
||||
expect($stderr).to receive(:puts).with(default_output_first_line)
|
||||
expect($stderr).to receive(:puts).with(default_output_second_line)
|
||||
expect($stderr).to receive(:puts).with(default_output_third_line)
|
||||
|
||||
subject
|
||||
end
|
||||
|
|
@ -586,54 +587,59 @@ describe Utils do
|
|||
config = {
|
||||
'user' => 'foo',
|
||||
'services' => {
|
||||
'myabs' => {
|
||||
'url' => 'http://abs.com',
|
||||
'token' => 'krypto-night',
|
||||
'type' => 'abs'
|
||||
}
|
||||
'myabs' => {
|
||||
'url' => 'http://abs.com',
|
||||
'token' => 'krypto-night',
|
||||
'type' => 'abs'
|
||||
}
|
||||
}
|
||||
}
|
||||
allow(Conf).to receive(:read_config).and_return(config)
|
||||
expect{Utils.get_vmpooler_service_config(config['services']['myabs']['vmpooler_fallback'])}.to raise_error(ArgumentError)
|
||||
expect do
|
||||
Utils.get_vmpooler_service_config(config['services']['myabs']['vmpooler_fallback'])
|
||||
end.to raise_error(ArgumentError)
|
||||
end
|
||||
it 'returns an error if the vmpooler_fallback is setup but cannot be found' do
|
||||
config = {
|
||||
'user' => 'foo',
|
||||
'services' => {
|
||||
'myabs' => {
|
||||
'url' => 'http://abs.com',
|
||||
'token' => 'krypto-night',
|
||||
'type' => 'abs',
|
||||
'vmpooler_fallback' => 'myvmpooler'
|
||||
'url' => 'http://abs.com',
|
||||
'token' => 'krypto-night',
|
||||
'type' => 'abs',
|
||||
'vmpooler_fallback' => 'myvmpooler'
|
||||
}
|
||||
}
|
||||
}
|
||||
allow(Conf).to receive(:read_config).and_return(config)
|
||||
expect{Utils.get_vmpooler_service_config(config['services']['myabs']['vmpooler_fallback'])}.to raise_error(ArgumentError, /myvmpooler/)
|
||||
expect do
|
||||
Utils.get_vmpooler_service_config(config['services']['myabs']['vmpooler_fallback'])
|
||||
end.to raise_error(ArgumentError,
|
||||
/myvmpooler/)
|
||||
end
|
||||
it 'returns the vmpooler_fallback config' do
|
||||
config = {
|
||||
'user' => 'foo',
|
||||
'services' => {
|
||||
'myabs' => {
|
||||
'url' => 'http://abs.com',
|
||||
'token' => 'krypto-night',
|
||||
'type' => 'abs',
|
||||
'vmpooler_fallback' => 'myvmpooler'
|
||||
'url' => 'http://abs.com',
|
||||
'token' => 'krypto-night',
|
||||
'type' => 'abs',
|
||||
'vmpooler_fallback' => 'myvmpooler'
|
||||
},
|
||||
'myvmpooler' => {
|
||||
'url' => 'http://vmpooler.com',
|
||||
'token' => 'krypto-knight'
|
||||
'url' => 'http://vmpooler.com',
|
||||
'token' => 'krypto-knight'
|
||||
}
|
||||
}
|
||||
}
|
||||
allow(Conf).to receive(:read_config).and_return(config)
|
||||
expect(Utils.get_vmpooler_service_config(config['services']['myabs']['vmpooler_fallback'])).to include({
|
||||
'url' => 'http://vmpooler.com',
|
||||
'token' => 'krypto-knight',
|
||||
'user' => 'foo',
|
||||
'type' => 'vmpooler'
|
||||
})
|
||||
'url' => 'http://vmpooler.com',
|
||||
'token' => 'krypto-knight',
|
||||
'user' => 'foo',
|
||||
'type' => 'vmpooler'
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue