mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-25 21:28:40 -05:00
Fix pretty print when multiple backend services
are returned by ABS. Added test with vmpooler and nspooler result
This commit is contained in:
parent
45f0ef031e
commit
2b56448d50
2 changed files with 104 additions and 9 deletions
|
|
@ -114,13 +114,17 @@ class Utils
|
||||||
#
|
#
|
||||||
# Create a vmpooler service to query each hostname there so as to get the metadata too
|
# Create a vmpooler service to query each hostname there so as to get the metadata too
|
||||||
|
|
||||||
vmpooler_service = service.clone
|
|
||||||
vmpooler_service.silent = true
|
|
||||||
vmpooler_service.maybe_use_vmpooler
|
|
||||||
output_target.puts "- [JobID:#{host_data['request']['job']['id']}] <#{host_data['state']}>"
|
output_target.puts "- [JobID:#{host_data['request']['job']['id']}] <#{host_data['state']}>"
|
||||||
|
host_data['allocated_resources'].each do |allocated_resources, _i|
|
||||||
host_data['allocated_resources'].each do |vm_name, _i|
|
if allocated_resources['engine'] == "vmpooler"
|
||||||
self.pretty_print_hosts(verbose, vmpooler_service, vm_name['hostname'].split('.')[0], print_to_stderr, indent+2)
|
vmpooler_service = service.clone
|
||||||
|
vmpooler_service.silent = true
|
||||||
|
vmpooler_service.maybe_use_vmpooler
|
||||||
|
self.pretty_print_hosts(verbose, vmpooler_service, allocated_resources['hostname'].split('.')[0], print_to_stderr, indent+2)
|
||||||
|
else
|
||||||
|
#TODO we could add more specific metadata for the other services, nspooler and aws
|
||||||
|
output_target.puts " - #{allocated_resources['hostname']} (#{allocated_resources['type']})"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
when 'Pooler'
|
when 'Pooler'
|
||||||
tag_pairs = []
|
tag_pairs = []
|
||||||
|
|
|
||||||
|
|
@ -386,7 +386,7 @@ describe Utils do
|
||||||
let(:service) { Service.new(MockOptions.new, 'url' => url, 'type' => 'abs') }
|
let(:service) { Service.new(MockOptions.new, 'url' => url, 'type' => 'abs') }
|
||||||
|
|
||||||
let(:hostname) { '1597952189390' }
|
let(:hostname) { '1597952189390' }
|
||||||
let(:fqdn) { 'example-noun.delivery.puppetlabs.net' }
|
let(:fqdn) { 'example-noun.delivery.mycompany.net' }
|
||||||
let(:fqdn_hostname) {'example-noun'}
|
let(:fqdn_hostname) {'example-noun'}
|
||||||
let(:template) { 'ubuntu-1604-x86_64' }
|
let(:template) { 'ubuntu-1604-x86_64' }
|
||||||
|
|
||||||
|
|
@ -416,7 +416,7 @@ describe Utils do
|
||||||
let(:response_body_vmpooler) do
|
let(:response_body_vmpooler) do
|
||||||
{
|
{
|
||||||
fqdn_hostname => {
|
fqdn_hostname => {
|
||||||
'template' => 'redhat-7-x86_64',
|
'template' => template,
|
||||||
'lifetime' => 48,
|
'lifetime' => 48,
|
||||||
'running' => 7.67,
|
'running' => 7.67,
|
||||||
'state' => 'running',
|
'state' => 'running',
|
||||||
|
|
@ -441,7 +441,7 @@ describe Utils do
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:default_output_first_line) { "- [JobID:#{hostname}] <allocated>" }
|
let(:default_output_first_line) { "- [JobID:#{hostname}] <allocated>" }
|
||||||
let(:default_output_second_line) { " - example-noun.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)" }
|
let(:default_output_second_line) { " - #{fqdn} (#{template}, 7.67/48 hours, user: bob, role: agent)" }
|
||||||
|
|
||||||
it 'prints output with job id, host, and template' do
|
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_first_line)
|
||||||
|
|
@ -461,6 +461,97 @@ describe Utils do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'with ABS service returning vmpooler and nspooler resources' do
|
||||||
|
let(:service) { Service.new(MockOptions.new, 'url' => url, 'type' => 'abs') }
|
||||||
|
|
||||||
|
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(: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,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
# The vmpooler response contains metadata that is printed
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
allow(Utils).to receive(:get_vmpooler_service_config).and_return({
|
||||||
|
'url' => 'http://vmpooler.example.com',
|
||||||
|
'token' => 'krypto-knight'
|
||||||
|
})
|
||||||
|
allow(service).to receive(:query)
|
||||||
|
.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}, 7.67/48 hours, user: bob, role: agent)" }
|
||||||
|
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)
|
||||||
|
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when print_to_stderr option is true' 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)
|
||||||
|
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#get_vmpooler_service_config' do
|
describe '#get_vmpooler_service_config' do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue