Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1584475

Summary: [RFE] a script to automatically correct products
Product: Red Hat Satellite Reporter: matt jia <mjia>
Component: OtherAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED NOTABUG QA Contact: Katello QA List <katello-qa-list>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.3.1CC: inecas, mmccune
Target Milestone: Unspecified   
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-06-01 15:22:48 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description matt jia 2018-05-31 02:26:18 UTC
We often see this error:

2018-05-30 03:17:06 71ef6e3c [app] [E] RestClient::Gone: Katello::Resources::Candlepin::Consumer: 410 Gone {"displayMessage":"Unit 1ab7b861-bf5c-447d-8527-71b936314c76 has been deleted","requestUuid":"40a90ae6-e92c-4387-a7a7-05a43fc63f11","deletedId":"1ab7b861-bf5c-447d-8527-71b936314c76"} (GET /candlepin/consumers/1ab7b861-bf5c-447d-8527-71b936314c76)
 | Body: {"displayMessage":"Unit 1ab7b861-bf5c-447d-8527-71b936314c76 has been deleted","requestUuid":"40a90ae6-e92c-4387-a7a7-05a43fc63f11","deletedId":"1ab7b861-bf5c-447d-8527-71b936314c76"}
 | /opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/abstract_response.rb:74:in `return!'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/request.rb:495:in `process_result'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/request.rb:421:in `block in transmit'

It is because katello and candlepin somehow got misaligned. To fix this issue, people need to delete the host in foreman-rake console. In some cases, it is quite risky to ask customers to perform this. Ideally, there should be a script like foreman-rake katello:correct_repositories to correct products in a safe manner:

foreman-rake katello:correct_products

Comment 1 Mike McCune 2018-06-01 15:22:48 UTC
This is handled in foreman-rake katello:clean_backend_objects

Comment 2 Mike McCune 2018-06-01 15:23:21 UTC
# foreman-rake katello:clean_backend_objects
The following changes will not actually be performed.  Rerun with COMMIT=true to apply the changes
0 orphaned consumer id(s) found in candlepin.
0 orphaned consumer id(s) found in pulp.

Comment 3 matt jia 2018-06-04 02:17:30 UTC
Hi Mike,

It seems like katello:clean_backend_objects only cleans up hosts and other stuff like orphaned consumers, but not orphaned products in foreman. By looking at

/home/mjia/katello/app/models/katello/glue/provider.rb L160-163

        product_to_remove_ids = (product_in_katello_ids - products_in_candlepin_ids).uniq
        product_to_remove_ids.each do |cp_id|
          product = Product.find_by_cp_id(cp_id, self.organization)
          Rails.logger.warn "Orphaned Product id #{product.id} found while refreshing/importing manifest."
        end
        end

Why a warning message is logged instead of deleting the orphaned product?