diff --git a/app/lib/actions/katello/orphan_cleanup/remove_orphaned_content_units.rb b/app/lib/actions/katello/orphan_cleanup/remove_orphaned_content_units.rb index 02504aa2c66..209999cebc4 100644 --- a/app/lib/actions/katello/orphan_cleanup/remove_orphaned_content_units.rb +++ b/app/lib/actions/katello/orphan_cleanup/remove_orphaned_content_units.rb @@ -2,24 +2,14 @@ module Actions module Katello module OrphanCleanup class RemoveOrphanedContentUnits < Actions::Base - def plan(options = {}) - plan_self(id: options[:repo_id], destroy_all: options[:destroy_all]) - end - def run - content_types_to_index = [] - if input[:destroy_all] - ::Katello::RepositoryTypeManager.enabled_repository_types.each_value do |repo_type| - content_types_to_index << repo_type.content_types_to_index - end - elsif input[:id] - repo = ::Katello::Repository.find(input[:id]) - content_types_to_index = repo.repository_type.content_types_to_index - else - fail "Pass either a repository to determine content type or destroy_all to destroy all orphaned content units" + models = [] + + ::Katello::RepositoryTypeManager.enabled_repository_types.each_value do |repo_type| + models << repo_type.content_types_to_index end - content_types_to_index.flatten.each do |type| - type.model_class.orphaned.destroy_all + models.flatten.each do |content_type| + content_type.model_class.orphaned.destroy_all end end diff --git a/app/lib/actions/katello/orphan_cleanup/remove_orphans.rb b/app/lib/actions/katello/orphan_cleanup/remove_orphans.rb index b63a5eb41f9..5db8ae44699 100644 --- a/app/lib/actions/katello/orphan_cleanup/remove_orphans.rb +++ b/app/lib/actions/katello/orphan_cleanup/remove_orphans.rb @@ -9,7 +9,7 @@ def plan(proxy) sequence do if proxy.pulp_primary? ::Katello::RootRepository.orphaned.destroy_all - plan_action(RemoveOrphanedContentUnits, destroy_all: true) + plan_action(RemoveOrphanedContentUnits) end if proxy.pulp3_enabled? plan_action( diff --git a/app/lib/actions/katello/repository/index_content.rb b/app/lib/actions/katello/repository/index_content.rb index c6b5f77e95d..0d6eb6f358a 100644 --- a/app/lib/actions/katello/repository/index_content.rb +++ b/app/lib/actions/katello/repository/index_content.rb @@ -31,10 +31,6 @@ def run output[:new_content][content_type.label] = new_count - initial_counts[content_type.label] end end - - def finalize - ForemanTasks.async_task(OrphanCleanup::RemoveOrphanedContentUnits, {repo_id: input[:id]}) - end end end end diff --git a/app/services/katello/pulp3/repository.rb b/app/services/katello/pulp3/repository.rb index 12246ae686e..d61ebf34175 100644 --- a/app/services/katello/pulp3/repository.rb +++ b/app/services/katello/pulp3/repository.rb @@ -497,7 +497,7 @@ def add_content(content_unit_href, remove_all_units = false) rescue api.client_module::ApiError => e if e.message.include? 'Could not find the following content units' raise ::Katello::Errors::Pulp3Error, "Content units that do not exist in Pulp were requested to be copied."\ - " Please run a complete sync on the following repository: #{repository_reference.root_repository.name}. Original error: #{e.message}" + " Please run `foreman-rake katello:delete_orphaned_content`. Original error: #{e.message}" else raise e end @@ -509,7 +509,7 @@ def add_content_for_repo(repository_href, content_unit_href) rescue api.client_module::ApiError => e if e.message.include? 'Could not find the following content units' raise ::Katello::Errors::Pulp3Error, "Content units that do not exist in Pulp were requested to be copied."\ - " Please run a complete sync on the following repository:"\ + " Please run `foreman-rake katello:delete_orphaned_content` to fix the following repository:"\ " #{::Katello::Pulp3::RepositoryReference.find_by(repository_href: repository_href).root_repository.name}. Original error: #{e.message}" else raise e diff --git a/app/services/katello/pulp3/repository/docker.rb b/app/services/katello/pulp3/repository/docker.rb index ce12a5ce802..70604a6b6c2 100644 --- a/app/services/katello/pulp3/repository/docker.rb +++ b/app/services/katello/pulp3/repository/docker.rb @@ -70,7 +70,7 @@ def add_content(content_unit_href) rescue api.client_module::ApiError => e if e.message.include? 'Could not find the following content units' raise ::Katello::Errors::Pulp3Error, "Content units that do not exist in Pulp were requested to be copied."\ - " Please run a complete sync on the following repository: #{repository_reference.root_repository.name}. Original error: #{e.message}" + " Please run `foreman-rake katello:delete_orphaned_content` to fix the following repository: #{repository_reference.root_repository.name}. Original error: #{e.message}" else raise e end diff --git a/test/actions/katello/orphan_cleanup/remove_orphaned_content_units_test.rb b/test/actions/katello/orphan_cleanup/remove_orphaned_content_units_test.rb index c7648d4c144..713dd480384 100644 --- a/test/actions/katello/orphan_cleanup/remove_orphaned_content_units_test.rb +++ b/test/actions/katello/orphan_cleanup/remove_orphaned_content_units_test.rb @@ -8,14 +8,7 @@ def setup def test_orphaned_content_task_destroys_orphans rpm = katello_rpms(:one) rpm.repository_rpms.destroy_all - ForemanTasks.sync_task(Actions::Katello::OrphanCleanup::RemoveOrphanedContentUnits, {repo_id: @rhel6.id}) - assert_raises(ActiveRecord::RecordNotFound) { rpm.reload } - end - - def test_orphaned_content_task_destroy_all - rpm = katello_rpms(:one) - rpm.repository_rpms.destroy_all - ForemanTasks.sync_task(Actions::Katello::OrphanCleanup::RemoveOrphanedContentUnits, {destroy_all: true}) + ForemanTasks.sync_task(Actions::Katello::OrphanCleanup::RemoveOrphanedContentUnits) assert_raises(ActiveRecord::RecordNotFound) { rpm.reload } end end diff --git a/test/models/repository_test.rb b/test/models/repository_test.rb index 23f1d9d1d4a..e07dd7f6d1b 100644 --- a/test/models/repository_test.rb +++ b/test/models/repository_test.rb @@ -710,15 +710,6 @@ def test_with_errata assert_includes Repository.with_errata([errata]), @rhel6 end - def test_orphaned_content_task_destroys_orphans - rpm = katello_rpms(:one) - ::Katello::ContentUnitIndexer.any_instance.stubs(:import_all).returns(true) - ::Katello::Repository.any_instance.stubs(:import_distribution_data).returns(true) - rpm.repository_rpms.destroy_all - ForemanTasks.sync_task(Actions::Katello::OrphanCleanup::RemoveOrphanedContentUnits, {repo_id: @rhel6.id}) - assert_raises(ActiveRecord::RecordNotFound) { rpm.reload } - end - def test_index_content_ordering repo_type = @rhel6.repository_type SmartProxy.stubs(:pulp_primary).returns(SmartProxy.pulp_primary)