Skip to content

Commit

Permalink
Fixes #37139 - Block repo actions during associated CV publish task
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 committed Feb 6, 2024
1 parent 9f47fbb commit 2899e12
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/lib/actions/katello/repository/remove_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions app/lib/actions/katello/repository/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?))
Expand Down
1 change: 1 addition & 0 deletions app/lib/actions/katello/repository/upload_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions app/models/katello/content_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion app/models/katello/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down

0 comments on commit 2899e12

Please sign in to comment.