Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36716 - Add task to fix candlepin DB #10740

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions lib/katello/tasks/fix_candlepin_product_content.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace :katello do
desc "Fix missing repository content in candlepin"
task :fix_candlepin_content => ["environment", "check_ping"] do
logger = Logger.new(STDOUT)
User.current = User.anonymous_api_admin

Katello::Resources::Candlepin::Owner.all.each do |owner|
logger.debug("Checking Products in Organization #{owner['name']}(#{owner['key']})")
org = Organization.find_by(label: owner['key'])

# find_missing associations
Katello::Resources::Candlepin::Product.all(owner['key']).each do |cp_product|
katello_product = Katello::Product.find_by_cp_id(cp_product['id'], org)
logger.debug("Checking '#{cp_product['name']}'")
content_count_in_cp = cp_product['productContent'].length
content_count_in_katello = katello_product.contents.count
logger.debug("Product has #{content_count_in_cp} content entries in Candlepin and #{content_count_in_katello} in Katello")
if content_count_in_cp != content_count_in_katello
logger.info("Product '#{cp_product['name']}' has #{content_count_in_cp} content entries in Candlepin but #{content_count_in_katello} in Katello")

existing_content_ids = cp_product['productContent'].
map { |e| e['content']['id'] }.uniq
missing_content = katello_product.contents.where.not(cp_content_id: existing_content_ids)

missing_content.each do |katello_content|
logger.warn("Product #{katello_product.name.inspect} is missing Content #{katello_content.name.inspect}")
Katello::Resources::Candlepin::Product.remove_content(
owner['key'],
cp_product['id'],
katello_content.cp_content_id
)
Katello::Resources::Candlepin::Product.add_content(
owner['key'],
cp_product['id'],
katello_content.cp_content_id,
true # enabled=false only seems to occur for RHEL content
)
end
end
end
end
end
end
Loading