Skip to content

(DIO-1522) Show the VM state (running, destroyed) and colorize in red… #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/vmfloaty/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ def self.pretty_print_hosts(verbose, service, hostnames = [], print_to_stderr =
tag_pairs = []
tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } unless host_data['tags'].nil?
duration = "#{host_data['running']}/#{host_data['lifetime']} hours"
metadata = [host_data['template'], duration, *tag_pairs]
output_target.puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})".gsub(/^/, ' ' * indent)
metadata = [host_data['state'], host_data['template'], duration, *tag_pairs]
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'
line = "- #{host_data['fqdn']} (#{host_data['os_triple']}"
line += ", #{host_data['hours_left_on_reservation']}h remaining"
Expand Down
17 changes: 14 additions & 3 deletions spec/vmfloaty/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class Service
}
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
expect(STDOUT).to receive(:puts).with(default_output)
Expand Down Expand Up @@ -311,7 +311,7 @@ class Service
end

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)

Expand Down Expand Up @@ -458,13 +458,24 @@ class Service
it 'prints more information when vmpooler_fallback is set output with job id, host, template, lifetime, user and role' do
fallback = {'vmpooler_fallback' => 'vmpooler'}
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_second_line)

subject
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
let(:print_to_stderr) { true }

Expand Down