diff --git a/app/controllers/katello/api/v2/repositories_controller.rb b/app/controllers/katello/api/v2/repositories_controller.rb index c3e70a314e1..5da5bf3369f 100644 --- a/app/controllers/katello/api/v2/repositories_controller.rb +++ b/app/controllers/katello/api/v2/repositories_controller.rb @@ -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 diff --git a/app/lib/actions/candlepin/environment/set_content.rb b/app/lib/actions/candlepin/environment/set_content.rb index 1b3f794c196..1742ff82ed1 100644 --- a/app/lib/actions/candlepin/environment/set_content.rb +++ b/app/lib/actions/candlepin/environment/set_content.rb @@ -39,8 +39,9 @@ def finalize # rubocop:disable Metrics/AbcSize 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) + if ((retries += 1) == max_retries) + Rails.logger.warn("Skipping deleting content with ID #{output[:delete_response]} 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. diff --git a/test/controllers/api/v2/repositories_controller_test.rb b/test/controllers/api/v2/repositories_controller_test.rb index 0ac2133bf68..d391bdd67f4 100644 --- a/test/controllers/api/v2/repositories_controller_test.rb +++ b/test/controllers/api/v2/repositories_controller_test.rb @@ -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]