Skip to content

Commit 1bc2fec

Browse files
committed
Fixes #36716 - Add task to fix candlepin DB
1 parent 8ab0088 commit 1bc2fec

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace :katello do
2+
desc "Fix missing repository content in candlepin"
3+
task :fix_candlepin_content => ["environment", "check_ping"] do
4+
logger = Logger.new(STDOUT)
5+
User.current = User.anonymous_api_admin
6+
7+
Katello::Resources::Candlepin::Owner.all.each do |owner|
8+
logger.debug("Checking Products in Organization #{owner['name']}(#{owner['key']})")
9+
org = Organization.find_by(label: owner['key'])
10+
11+
# find_missing associations
12+
Katello::Resources::Candlepin::Product.all(owner['key']).each do |cp_product|
13+
katello_product = Katello::Product.find_by_cp_id(cp_product['id'], org)
14+
logger.debug("Checking '#{cp_product['name']}'")
15+
content_count_in_cp = cp_product['productContent'].length
16+
content_count_in_katello = katello_product.contents.count
17+
logger.debug("Product has #{content_count_in_cp} content entries in Candlepin and #{content_count_in_katello} in Katello")
18+
if content_count_in_cp != content_count_in_katello
19+
logger.info("Product '#{cp_product['name']}' has #{content_count_in_cp} content entries in Candlepin but #{content_count_in_katello} in Katello")
20+
21+
existing_content_ids = cp_product['productContent'].
22+
map{ |e| e['content']['id'] }.uniq
23+
missing_content = katello_product.contents.where.not(cp_content_id: existing_content_ids)
24+
25+
missing_content.each do |katello_content|
26+
logger.warn("Product #{katello_product.name.inspect} is missing Content #{katello_content.name.inspect}")
27+
Katello::Resources::Candlepin::Product.remove_content(
28+
owner['key'],
29+
cp_product['id'],
30+
katello_content.cp_content_id,
31+
)
32+
Katello::Resources::Candlepin::Product.add_content(
33+
owner['key'],
34+
cp_product['id'],
35+
katello_content.cp_content_id,
36+
true # enabled=false only seems to occur for RHEL content
37+
)
38+
end
39+
end
40+
end
41+
end
42+
end
43+
end

0 commit comments

Comments
 (0)