(DIO-1522) Show the VM state (running, destroyed) and colorize in red when it has been deleted

the ABS system does not have a real sense of the current state of the resources
it has allocated. When running list --active it can list VMs that have been
deleted or reaped after their lifetime expired.
This change enables to show more information when a vmpooler_fallback service
is provided to ABS, and will show the state (running, destroyed) and colorize
in red when the VM is destroyed.
This commit is contained in:
Samuel Beaulieu 2021-02-25 10:04:30 -06:00
parent 4192631d70
commit 8143641f83
No known key found for this signature in database
GPG key ID: 12030F74136D0F34
2 changed files with 21 additions and 5 deletions

View file

@ -130,8 +130,13 @@ class Utils
tag_pairs = [] tag_pairs = []
tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } unless host_data['tags'].nil? tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } unless host_data['tags'].nil?
duration = "#{host_data['running']}/#{host_data['lifetime']} hours" duration = "#{host_data['running']}/#{host_data['lifetime']} hours"
metadata = [host_data['template'], duration, *tag_pairs] metadata = [host_data['state'], host_data['template'], duration, *tag_pairs]
output_target.puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})".gsub(/^/, ' ' * indent) message = "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})".gsub(/^/, ' ' * indent)
if host_data['state'] && host_data['state'] == "destroyed"
output_target.puts message.colorize(:red)
else
output_target.puts message
end
when 'NonstandardPooler' when 'NonstandardPooler'
line = "- #{host_data['fqdn']} (#{host_data['os_triple']}" line = "- #{host_data['fqdn']} (#{host_data['os_triple']}"
line += ", #{host_data['hours_left_on_reservation']}h remaining" line += ", #{host_data['hours_left_on_reservation']}h remaining"

View file

@ -283,7 +283,7 @@ describe Utils do
} }
end end
let(:default_output) { "- #{fqdn} (ubuntu-1604-x86_64, 9.66/12 hours)" } let(:default_output) { "- #{fqdn} (running, ubuntu-1604-x86_64, 9.66/12 hours)" }
it 'prints output with host fqdn, template and duration info' do 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)
@ -311,7 +311,7 @@ describe Utils do
end end
it 'prints output with host fqdn, template, duration info, and tags' do it 'prints output with host fqdn, template, duration info, and tags' do
output = "- #{fqdn} (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)" 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)
@ -458,13 +458,24 @@ describe Utils do
it 'prints more information when vmpooler_fallback is set output with job id, host, template, lifetime, user and role' do 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 service.config.merge! fallback
default_output_second_line=" - #{fqdn} (#{template}, 7.67/48 hours, user: bob, role: agent)" 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_first_line)
expect(STDOUT).to receive(:puts).with(default_output_second_line) expect(STDOUT).to receive(:puts).with(default_output_second_line)
subject subject
end end
it 'prints in red when destroyed' do
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)
subject
end
context 'when print_to_stderr option is true' do context 'when print_to_stderr option is true' do
let(:print_to_stderr) { true } let(:print_to_stderr) { true }