Skip to content

Commit e2e56e2

Browse files
committed
Fixes #36856 - add check for katello-rake task
1 parent 06b9c9e commit e2e56e2

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module Checks::Katello
2+
class CheckCleanBackendObjects < ForemanMaintain::Check
3+
metadata do
4+
description 'Check whether subscription consumers of backend service is in sync'
5+
tags :pre_upgrade
6+
7+
confine do
8+
feature(:katello)
9+
end
10+
end
11+
12+
def clean_backend_objects_dry_run
13+
found_orphans = nil
14+
missing_sub_info = []
15+
list_cmd = "export RUBYOPT='-W0'; foreman-rake katello:clean_backend_objects"
16+
execute(list_cmd).each_line do |line|
17+
case line
18+
when /^(?<orphans>\d+) orphaned consumer id\(s\) found in candlepin\.$/
19+
found_orphans = Regexp.last_match(:orphans).to_i
20+
puts "Found #{found_orphans} orphans" if found_orphans > 0
21+
when /^Candlepin orphaned consumers: (?<orphaned_consumers>.*)$/
22+
orphaned_consumers = Regexp.last_match(:orphaned_consumers)
23+
puts "Found consumers: #{orphaned_consumers}" if orphaned_consumers != '[]'
24+
when /^Host (?<id>\S*) (?<host>\S*) (?<sub>\S*)? is partially missing subscription information\. Un-registering$/
25+
missing_sub_info << [Regexp.last_match(:id), Regexp.last_match(:host), Regexp.last_match(:sub)]
26+
end
27+
end
28+
unless missing_sub_info.empty?
29+
puts "Hosts missing subscription information and would be un-registered:"
30+
puts missing_sub_info.map { |e| " * #{e[1]}(#{e[0]})" }.join("\n")
31+
end
32+
return found_orphans + missing_sub_info.length
33+
end
34+
35+
def run
36+
assert clean_backend_objects_dry_run.zero?,
37+
"'katello:clean_backend_objects' would remove the above Candlepin consumers and hosts!\n" \
38+
"If this is not intended, please verify. One solution can be to re-subscribe affected host.\n"
39+
end
40+
end
41+
end

0 commit comments

Comments
 (0)