Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #3036, #12587, #3956 - Ping command (#394)
- Loading branch information
Showing
10 changed files
with
226 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module HammerCLIForeman | ||
module CommandExtensions | ||
class Ping < HammerCLI::CommandExtensions | ||
before_print do |data| | ||
unless data['results']['foreman'].nil? | ||
status = data['results']['foreman']['database']['active'] | ||
data['results']['foreman']['database']['active'] = status ? 'ok' : 'FAIL' | ||
duration = data['results']['foreman']['database']['duration_ms'] | ||
data['results']['foreman']['database']['duration_ms'] = _("Duration: %sms") % duration | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module HammerCLIForeman | ||
module CommandExtensions | ||
class Status < HammerCLI::CommandExtensions | ||
before_print do |data| | ||
return if data['results'].nil? | ||
|
||
normalize_plugins(data['results']['foreman']['plugins']) | ||
data['results']['foreman']['smart_proxies'].each do |proxy| | ||
proxy['features'] = normalize_features(proxy['features']) | ||
proxy['failed_features'] = normalize_failed_features(proxy['failed_features']) | ||
end | ||
end | ||
|
||
def self.normalize_plugins(plugins) | ||
plugins.map! do |plugin| | ||
name, version = plugin.split(': ', 2)[1].split(', ', 3)[0..1] | ||
{ name: name, version: version } | ||
end | ||
end | ||
|
||
def self.normalize_features(features) | ||
active_features = [] | ||
features.each_pair do |name, version| | ||
active_features << { | ||
name: name, | ||
version: version | ||
} | ||
end | ||
active_features | ||
end | ||
|
||
def self.normalize_failed_features(features) | ||
failed_features = [] | ||
features.each_pair do |name, error| | ||
failed_features << { | ||
name: name, | ||
error: error | ||
} | ||
end | ||
failed_features | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module HammerCLIForeman | ||
class PingCommand < HammerCLIForeman::Command | ||
resource :ping | ||
|
||
class ForemanCommand < HammerCLIForeman::Command | ||
action :ping | ||
command_name 'foreman' | ||
|
||
output do | ||
from 'foreman' do | ||
field :database, _('database'), Fields::Label do | ||
field :active, _('Status') | ||
field :duration_ms, _('Server Response') | ||
end | ||
end | ||
end | ||
|
||
extend_with(HammerCLIForeman::CommandExtensions::Ping.new) | ||
end | ||
|
||
self.default_subcommand = 'foreman' | ||
autoload_subcommands | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module HammerCLIForeman | ||
class StatusCommand < HammerCLIForeman::Command | ||
resource :ping | ||
|
||
class ForemanCommand < HammerCLIForeman::Command | ||
action :statuses | ||
command_name 'foreman' | ||
|
||
output do | ||
from 'foreman' do | ||
field :version, _('Version') | ||
from 'api' do | ||
field :version, _('API Version') | ||
end | ||
field :database, _('Database'), Fields::Label do | ||
field :active, _('Status') | ||
field :duration_ms, _('Server Response') | ||
end | ||
collection :plugins, _('Plugins') do | ||
field :name, _('Name') | ||
field :version, _('Version') | ||
end | ||
collection :smart_proxies, _('Smart Proxies') do | ||
field :name, _('Name') | ||
field :version, _('Version') | ||
field :status, _('Status') | ||
collection :features, _('Features'), hide_blank: true do | ||
field :name, _('Name') | ||
field :version, _('Version') | ||
end | ||
collection :failed_features, _('Failed features'), hide_blank: true do | ||
field :name, _('Name') | ||
field :error, _('Error') | ||
end | ||
end | ||
collection :compute_resources, _('Compute Resources') do | ||
field :name, _('Name') | ||
field :status, _('Status') | ||
collection :errors, _('Errors'), hide_blank: true do | ||
field nil, nil | ||
end | ||
end | ||
end | ||
end | ||
|
||
extend_with(HammerCLIForeman::CommandExtensions::Ping.new(only: :data)) | ||
extend_with(HammerCLIForeman::CommandExtensions::Status.new(only: :data)) | ||
end | ||
|
||
self.default_subcommand = 'foreman' | ||
autoload_subcommands | ||
end | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require File.join(File.dirname(__FILE__), 'test_helper') | ||
|
||
describe 'ping' do | ||
let(:base_cmd) { %w[ping] } | ||
|
||
describe 'foreman' do | ||
let(:cmd) { base_cmd << 'foreman' } | ||
let(:ping_results) do | ||
{ | ||
'results' => { | ||
'foreman' => { | ||
'database' => { 'active' => true, 'duration_ms' => 0 } | ||
} | ||
} | ||
} | ||
end | ||
|
||
it 'pings foreman system' do | ||
api_expects(:ping, :ping, 'Ping').returns(ping_results) | ||
|
||
output = OutputMatcher.new( | ||
[ | ||
'database:', | ||
' Status: ok', | ||
' Server Response: Duration: 0ms' | ||
] | ||
) | ||
|
||
expected_result = success_result(output) | ||
result = run_cmd(cmd) | ||
assert_cmd(expected_result, result) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require File.join(File.dirname(__FILE__), 'test_helper') | ||
|
||
describe 'status' do | ||
let(:base_cmd) { %w[status] } | ||
|
||
describe 'foreman' do | ||
let(:cmd) { base_cmd << 'foreman' } | ||
let(:status_results) do | ||
{ | ||
'results' => { | ||
'foreman' => { | ||
'database' => { 'active' => true, 'duration_ms' => 0 }, | ||
'version' => '1.24.0-develop', | ||
'api' => { 'version' => 'v2' }, | ||
'plugins' => [], | ||
'smart_proxies' => [], | ||
'compute_resources' => [] | ||
} | ||
} | ||
} | ||
end | ||
|
||
it 'checks status of the foreman system' do | ||
api_expects(:ping, :statuses, 'Status').returns(status_results) | ||
|
||
output = OutputMatcher.new( | ||
[ | ||
'Version: 1.24.0-develop', | ||
'API Version: v2', | ||
'Database:', | ||
' Status: ok', | ||
' Server Response: Duration: 0ms', | ||
'Plugins:', | ||
'', | ||
'Smart Proxies:', | ||
'', | ||
'Compute Resources:' | ||
] | ||
) | ||
|
||
expected_result = success_result(output) | ||
result = run_cmd(cmd) | ||
assert_cmd(expected_result, result) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters