Skip to content

Commit

Permalink
Fixes #36856 - add check for katello-rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bucher committed Oct 30, 2023
1 parent 06b9c9e commit e2e56e2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions definitions/checks/katello/check_clean_backend_objects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Checks::Katello
class CheckCleanBackendObjects < ForemanMaintain::Check
metadata do
description 'Check whether subscription consumers of backend service is in sync'
tags :pre_upgrade

confine do
feature(:katello)
end
end

def clean_backend_objects_dry_run
found_orphans = nil
missing_sub_info = []
list_cmd = "export RUBYOPT='-W0'; foreman-rake katello:clean_backend_objects"
execute(list_cmd).each_line do |line|
case line
when /^(?<orphans>\d+) orphaned consumer id\(s\) found in candlepin\.$/
found_orphans = Regexp.last_match(:orphans).to_i
puts "Found #{found_orphans} orphans" if found_orphans > 0
when /^Candlepin orphaned consumers: (?<orphaned_consumers>.*)$/
orphaned_consumers = Regexp.last_match(:orphaned_consumers)
puts "Found consumers: #{orphaned_consumers}" if orphaned_consumers != '[]'
when /^Host (?<id>\S*) (?<host>\S*) (?<sub>\S*)? is partially missing subscription information\. Un-registering$/
missing_sub_info << [Regexp.last_match(:id), Regexp.last_match(:host), Regexp.last_match(:sub)]
end
end
unless missing_sub_info.empty?
puts "Hosts missing subscription information and would be un-registered:"
puts missing_sub_info.map { |e| " * #{e[1]}(#{e[0]})" }.join("\n")
end
return found_orphans + missing_sub_info.length
end

def run
assert clean_backend_objects_dry_run.zero?,
"'katello:clean_backend_objects' would remove the above Candlepin consumers and hosts!\n" \
"If this is not intended, please verify. One solution can be to re-subscribe affected host.\n"
end
end
end

0 comments on commit e2e56e2

Please sign in to comment.