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 #37600 - ignore missing content on RH repo deletion #11291

Merged
Merged
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
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
chris1984 marked this conversation as resolved.
Show resolved Hide resolved
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)
chris1984 marked this conversation as resolved.
Show resolved Hide resolved
# 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(missing_content)
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