Skip to content

Commit e41cd68

Browse files
committed
Refs #38856 - fail CCV publish if already scheduled
1 parent 6648380 commit e41cd68

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

app/models/katello/content_view.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ def check_ready_to_publish!(importing: false, syncable: false)
662662
check_composite_action_allowed!(organization.library)
663663
check_docker_repository_names!([organization.library])
664664
check_orphaned_content_facets!(environments: self.environments)
665+
check_scheduled_publish!
665666
end
666667

667668
true
@@ -677,6 +678,14 @@ def check_repositories_blocking_publish!
677678
end
678679
end
679680

681+
def check_scheduled_publish!
682+
return unless composite?
683+
684+
if ::Katello::ContentViewManager.scheduled_composite_publish?(self)
685+
fail ::Katello::Errors::ConflictException, _("A publish is already scheduled for this content view. Please wait for the scheduled publish to complete.")
686+
end
687+
end
688+
680689
def check_docker_repository_names!(environments)
681690
environments.each do |environment|
682691
repositories = []

test/factories/foreman_task.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
result { 'success' }
88
sequence(:started_at) { |n| "2016-#{(n / 30) + 1}-#{(n % 30) + 1} 11:15:00" }
99
after(:build) do |task|
10-
task.ended_at = task.started_at.change(:sec => 32)
10+
task.ended_at = task.started_at.change(:sec => 32) if task.started_at
1111
end
1212

1313
trait :running do
@@ -21,6 +21,13 @@
2121
result { 'error' }
2222
ended_at { nil }
2323
end
24+
25+
trait :scheduled do
26+
state { 'scheduled' }
27+
result { 'pending' }
28+
started_at { nil }
29+
ended_at { nil }
30+
end
2431
end
2532

2633
factory :dynflow_task, :parent => :foreman_task, :class => ForemanTasks::Task::DynflowTask do

test/models/content_view_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,5 +853,25 @@ def test_ignore_generated
853853
ignore_generated_include_library = Katello::ContentView.ignore_generated(include_library_generated: true).count
854854
assert_equal (ignore_generated - ignore_generated_include_library), 2
855855
end
856+
857+
def test_check_scheduled_publish_raises_when_scheduled_publish_exists
858+
composite_cv = katello_content_views(:composite_view)
859+
860+
# Create a scheduled publish task for the composite CV
861+
task = FactoryBot.create(:dynflow_task, :scheduled,
862+
label: 'Actions::Katello::ContentView::Publish',
863+
external_id: 'test-scheduled-publish-check-123')
864+
865+
# Mock the delayed plan to return our composite CV as first arg
866+
delayed_plan = mock('delayed_plan')
867+
delayed_plan.stubs(:args).returns([composite_cv])
868+
ForemanTasks.dynflow.world.persistence.stubs(:load_delayed_plan).with(task.external_id).returns(delayed_plan)
869+
870+
error = assert_raises(Katello::Errors::ConflictException) do
871+
composite_cv.check_scheduled_publish!
872+
end
873+
874+
assert_match(/publish is already scheduled/, error.message)
875+
end
856876
end
857877
end

0 commit comments

Comments
 (0)