Skip to content

Commit

Permalink
Merge pull request #182 from skazi0/repocheck-format
Browse files Browse the repository at this point in the history
upgrade: Better repocheck output
  • Loading branch information
Jiří Suchomel authored Dec 14, 2018
2 parents 18ab62e + eb619c6 commit 31205aa
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions lib/crowbar/client/command/upgrade/repocheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,55 @@ def execute
request.process do |request|
case request.code
when 200
formatter = Formatter::Nested.new(
format: provide_format,
headings: ["Status", "Value"],
values: Filter::Subset.new(
filter: provide_filter,
values: request.parsed_response
).result
)
hint = ""
if provide_format == :table
response = request.parsed_response
repos = {}
response.each do |type, type_data|
type_data["repos"].each do |repo|
next if repo.nil?
repos[repo] = { repo: repo, status: [], type: type } unless repos.key? repo
end
type_data["errors"].each do |error, error_data|
error_data.each do |arch, bad_repos|
bad_repos.each do |bad_repo|
hint = "Some repopositories are not available. " \
"Fix the problem and call the step again."
repos[bad_repo][:status] << "#{error} (#{arch})"
end
end
end
end

repos.values.each do |repo|
repo[:status] = repo[:status].uniq.join(", ")
repo[:status] = "available" if repo[:status].empty?
end

formatter = Formatter::Hash.new(
format: provide_format,
headings: ["Repository", "Status", "Type"],
values: Filter::Hash.new(
filter: provide_filter,
values: repos.values
).result
)
else
formatter = Formatter::Nested.new(
format: provide_format,
values: Filter::Subset.new(
filter: provide_filter,
values: request.parsed_response
).result
)
end

if formatter.empty?
err "No repochecks"
else
say formatter.result
next unless provide_format == :table
say hint unless hint.empty?
say "Next step: 'crowbarctl upgrade admin'" if args.component == "crowbar"
say "Next step: 'crowbarctl upgrade services'" if args.component == "nodes"
end
Expand Down

0 comments on commit 31205aa

Please sign in to comment.