Skip to content

Commit

Permalink
Fixes #37600 - Add params to skip Candlepin content on repository remove
Browse files Browse the repository at this point in the history
  • Loading branch information
chris1984 committed Jul 17, 2024
1 parent 0e430ab commit e118736
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/controllers/katello/api/v2/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,16 @@ def update

api :DELETE, "/repositories/:id", N_("Destroy a custom repository")
param :id, :number, :required => true
param :skip_candlepin_environment_update, :bool, :required => false, :desc => N_('Skip updating the candlepin environment section in the destroy task.')
param :skip_candlepin_remove_content, :bool, :required => false, :desc => N_('Skip remove content in candlepin section in the destroy task.')
param :remove_from_content_view_versions, :bool, :required => false, :desc => N_("Force delete the repository by removing it from all content view versions")
param :delete_empty_repo_filters, :bool, :required => false, :desc => N_("Delete content view filters that have this repository as the last associated repository. Defaults to true. If false, such filters will now apply to all repositories in the content view.")
def destroy
sync_task(::Actions::Katello::Repository::Destroy, @repository,
remove_from_content_view_versions: ::Foreman::Cast.to_bool(params.fetch(:remove_from_content_view_versions, false)),
delete_empty_repo_filters: ::Foreman::Cast.to_bool(params.fetch(:delete_empty_repo_filters, true))
delete_empty_repo_filters: ::Foreman::Cast.to_bool(params.fetch(:delete_empty_repo_filters, true)),
skip_environment_update: ::Foreman::Cast.to_bool(params.fetch(:skip_candlepin_environment_update, false)),
destroy_content: ::Foreman::Cast.to_bool(params.fetch(:skip_candlepin_remove_content, true))
)
respond_for_destroy
end
Expand Down
4 changes: 3 additions & 1 deletion app/lib/actions/candlepin/environment/set_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def finalize # rubocop:disable Metrics/AbcSize
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)
if ((retries += 1) == max_retries)
Rails.logger.warn("Skipping deleting content with ID #{e} because it was not found")
end
# 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
20 changes: 20 additions & 0 deletions test/controllers/api/v2/repositories_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,26 @@ def test_destroy_remove_from_content_view_versions
assert_response :success
end

def test_skip_candlepin_environment_update
assert_sync_task(::Actions::Katello::Repository::Destroy) do |repo|
repo.id == @repository.id
end

delete :destroy, params: { :id => @repository.id, :skip_candlepin_environment_update => true }

assert_response :success
end

def test_skip_candlepin_remove_content
assert_sync_task(::Actions::Katello::Repository::Destroy) do |repo|
repo.id == @repository.id
end

delete :destroy, params: { :id => @repository.id, :skip_candlepin_remove_content => true }

assert_response :success
end

def test_destroy_protected
allowed_perms = [@destroy_permission]
denied_perms = [@read_permission, @create_permission, @update_permission]
Expand Down

0 comments on commit e118736

Please sign in to comment.