Skip to content

Commit

Permalink
Fixes #37600 - ignore missing content on RH repo deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
ianballou committed Jan 27, 2025
1 parent 2647f49 commit c5d545e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions app/lib/actions/candlepin/environment/set_content.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
module Actions
module Candlepin
module Environment
class SetContent < Candlepin::Abstract
class SetContent < Actions::Base
middleware.use ::Actions::Middleware::RemoteAction
middleware.use ::Actions::Middleware::CandlepinServicesCheck
middleware.use ::Actions::Middleware::KeepSessionId

def plan(content_view, environment, content_view_environment, new_content_id = nil)
plan_self(:content_view_id => content_view.id,
:environment_id => environment.id,
:cp_environment_id => content_view_environment.cp_id,
:new_content_id => new_content_id)
end

def finalize # rubocop:disable Metrics/AbcSize
def finalize # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
content_view = ::Katello::ContentView.find(input[:content_view_id])
environment = ::Katello::KTEnvironment.find(input[:environment_id])
content_ids = content_view.repos(environment).map(&:content_id).uniq.compact
Expand All @@ -32,15 +36,24 @@ def finalize # rubocop:disable Metrics/AbcSize
# Since its a dup id refresh the existing ids list (which hopefully will not have the duplicate content)
# and try again.
output[:add_ids] = content_ids - existing_ids
rescue RestClient::ResourceNotFound => e
# Set a higher limit for retries just in case the missing content is not being parsed from the error body correctly.
# If the content is not found after the retries, assume it is gone and continue.
raise e if ((retries += 1) == 1_000)
# Parse the missing content from the Candlepin response and remove it from the add_ids list.
missing_content = JSON.parse(e.response.body)['displayMessage'].split(' ')[-1].gsub(/"(.+?)"\./, '\1')
Rails.logger.debug "Content #{missing_content} not found in the environment. Removing it from the add_ids list."
output[:add_ids].delete(JSON.parse(e.response.body)['displayMessage'].split(' ')[-1].gsub(/"(.+?)"\./, '\1'))
end
end
retries = 0
until output[:delete_ids].empty?
begin
output[:delete_response] = ::Katello::Resources::Candlepin::Environment.delete_content(input[:cp_environment_id], output[:delete_ids])
break
rescue RestClient::ResourceNotFound => e
raise e if ((retries += 1) == max_retries)
rescue RestClient::ResourceNotFound
# If the content is not found after the retries, assume it is gone and continue.
break if ((retries += 1) == max_retries)
# Candlepin raises a 404 in case a content id is not found in this environment
# If thats the case lets just refresh the existing ids list (which hopefully will not have the 404'd content)
# and try again.
Expand Down

0 comments on commit c5d545e

Please sign in to comment.