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 24, 2023
1 parent ad8d414 commit a1791d9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions definitions/checks/katello/check_clean_backend_objects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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
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 != '[]'
end
end
return found_orphans
end

def run
assert clean_backend_objects_dry_run.zero?,
"'katello:clean_backend_objects' would remove the above Candlepin consumers!"
end
end
end

0 comments on commit a1791d9

Please sign in to comment.