From 2899e124c8556f762f806a8d1e06c5506a88b313 Mon Sep 17 00:00:00 2001 From: Samir Jha Date: Mon, 5 Feb 2024 14:56:47 +0000 Subject: [PATCH] Fixes #37139 - Block repo actions during associated CV publish task --- app/lib/actions/katello/repository/remove_content.rb | 1 + app/lib/actions/katello/repository/sync.rb | 1 + app/lib/actions/katello/repository/upload_files.rb | 1 + app/models/katello/content_view.rb | 11 +++++++++++ app/models/katello/repository.rb | 11 ++++++++++- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/lib/actions/katello/repository/remove_content.rb b/app/lib/actions/katello/repository/remove_content.rb index a926c8e1cc7..bb70ebe5d67 100644 --- a/app/lib/actions/katello/repository/remove_content.rb +++ b/app/lib/actions/katello/repository/remove_content.rb @@ -5,6 +5,7 @@ class RemoveContent < Actions::EntryAction include Dynflow::Action::WithSubPlans def plan(repository, content_units, options = {}) + repository.check_ready_to_act! sync_capsule = options.fetch(:sync_capsule, true) if repository.redhat? fail _("Cannot remove content from a non-custom repository") diff --git a/app/lib/actions/katello/repository/sync.rb b/app/lib/actions/katello/repository/sync.rb index c5686b2af82..5fe16079a0e 100644 --- a/app/lib/actions/katello/repository/sync.rb +++ b/app/lib/actions/katello/repository/sync.rb @@ -20,6 +20,7 @@ class Sync < Actions::EntryAction # of Katello and we just need to finish the rest of the orchestration def plan(repo, options = {}) action_subject(repo) + repo.check_ready_to_act! validate_contents = options.fetch(:validate_contents, false) skip_metadata_check = options.fetch(:skip_metadata_check, false) || (validate_contents && (repo.yum? || repo.deb?)) diff --git a/app/lib/actions/katello/repository/upload_files.rb b/app/lib/actions/katello/repository/upload_files.rb index a9edf1309c9..0f988d742ed 100644 --- a/app/lib/actions/katello/repository/upload_files.rb +++ b/app/lib/actions/katello/repository/upload_files.rb @@ -8,6 +8,7 @@ module Repository class UploadFiles < Actions::EntryAction def plan(repository, files, content_type = nil, options = {}) action_subject(repository) + repository.check_ready_to_act! repository.clear_smart_proxy_sync_histories tmp_files = prepare_tmp_files(files) diff --git a/app/models/katello/content_view.rb b/app/models/katello/content_view.rb index fa131147760..a068655a4f5 100644 --- a/app/models/katello/content_view.rb +++ b/app/models/katello/content_view.rb @@ -903,6 +903,17 @@ def remove_repository(repository) end end + def blocking_tasks + blocking_task_labels = [ + ::Actions::Katello::ContentView::Publish.name + ] + ForemanTasks::Task::DynflowTask.where(:label => blocking_task_labels) + .where.not(state: 'stopped') + .for_resource(self) + .order(:started_at) + .last + end + private def import_only_immutable diff --git a/app/models/katello/repository.rb b/app/models/katello/repository.rb index f8240368d9c..0a1c27469b2 100644 --- a/app/models/katello/repository.rb +++ b/app/models/katello/repository.rb @@ -644,7 +644,8 @@ def latest_dynflow_sync def blocking_tasks blocking_task_labels = [ ::Actions::Katello::Repository::Sync.name, - ::Actions::Katello::Repository::UploadFiles.name + ::Actions::Katello::Repository::UploadFiles.name, + ::Actions::Katello::Repository::RemoveContent.name ] ForemanTasks::Task::DynflowTask.where(:label => blocking_task_labels) .where.not(state: 'stopped') @@ -653,6 +654,14 @@ def blocking_tasks .last end + def check_ready_to_act! + cv_with_blocking_tasks = content_views.select { |cv| cv.blocking_tasks } + + if cv_with_blocking_tasks.any? + fail _("This repository has pending tasks in associated content views. Please wait for the tasks to complete before proceeding.") + end + end + # returns other instances of this repo with the same library # equivalent of repo def environmental_instances(view)