From 41ddfc808cc31fec6d11a1691dfcf19beca43c97 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 14 Jan 2025 12:01:41 -0500 Subject: [PATCH] SAT-30393 - Skip recurring logic tasks if on prem is enabled --- .../async/generate_all_reports_job.rb | 7 +++++++ lib/foreman_rh_cloud/engine.rb | 4 ++++ lib/insights_cloud/async/insights_scheduled_sync.rb | 7 +++++++ lib/inventory_sync/async/inventory_scheduled_sync.rb | 7 +++++++ test/jobs/inventory_scheduled_sync_test.rb | 12 ++++++++++++ 5 files changed, 37 insertions(+) diff --git a/lib/foreman_inventory_upload/async/generate_all_reports_job.rb b/lib/foreman_inventory_upload/async/generate_all_reports_job.rb index ba71fb93..40d6864d 100644 --- a/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +++ b/lib/foreman_inventory_upload/async/generate_all_reports_job.rb @@ -5,6 +5,13 @@ class GenerateAllReportsJob < ::Actions::EntryAction include ForemanInventoryUpload::Async::DelayedStart def plan + if ForemanRhCloud.with_local_advisor_engine? + logger.debug( + 'The scheduled process is disabled due to the "with_local_advisor_engine" + SETTING being set to true.' + ) + return + end unless Setting[:allow_auto_inventory_upload] logger.debug( 'The scheduled process is disabled due to the "allow_auto_inventory_upload" diff --git a/lib/foreman_rh_cloud/engine.rb b/lib/foreman_rh_cloud/engine.rb index 69d3a57a..6fa228be 100644 --- a/lib/foreman_rh_cloud/engine.rb +++ b/lib/foreman_rh_cloud/engine.rb @@ -193,4 +193,8 @@ def self.register_scheduled_task(task_class, cronline) end end end + + def self.with_local_advisor_engine? + SETTINGS.dig(:foreman_rh_cloud, :use_local_advisor_engine) || false + end end diff --git a/lib/insights_cloud/async/insights_scheduled_sync.rb b/lib/insights_cloud/async/insights_scheduled_sync.rb index c90f5b80..45216a6f 100644 --- a/lib/insights_cloud/async/insights_scheduled_sync.rb +++ b/lib/insights_cloud/async/insights_scheduled_sync.rb @@ -5,6 +5,13 @@ class InsightsScheduledSync < ::Actions::EntryAction include ForemanInventoryUpload::Async::DelayedStart def plan + if ForemanRhCloud.with_local_advisor_engine? + logger.debug( + 'The scheduled process is disabled due to the "with_local_advisor_engine" + SETTING being set to true.' + ) + return + end unless Setting[:allow_auto_insights_sync] logger.debug( 'The scheduled process is disabled due to the "allow_auto_insights_sync" diff --git a/lib/inventory_sync/async/inventory_scheduled_sync.rb b/lib/inventory_sync/async/inventory_scheduled_sync.rb index f0c25d86..17c81a75 100644 --- a/lib/inventory_sync/async/inventory_scheduled_sync.rb +++ b/lib/inventory_sync/async/inventory_scheduled_sync.rb @@ -5,6 +5,13 @@ class InventoryScheduledSync < ::Actions::EntryAction include ForemanInventoryUpload::Async::DelayedStart def plan + if ForemanRhCloud.with_local_advisor_engine? + logger.debug( + 'The scheduled process is disabled due to the "with_local_advisor_engine" + SETTING being set to true.' + ) + return + end unless Setting[:allow_auto_inventory_upload] logger.debug( 'The scheduled process is disabled due to the "allow_auto_inventory_upload" diff --git a/test/jobs/inventory_scheduled_sync_test.rb b/test/jobs/inventory_scheduled_sync_test.rb index 73e09488..336ad0c9 100644 --- a/test/jobs/inventory_scheduled_sync_test.rb +++ b/test/jobs/inventory_scheduled_sync_test.rb @@ -5,6 +5,7 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase include ForemanTasks::TestHelpers::WithInThreadExecutor test 'Schedules an execution if auto upload is enabled' do + ForemanRhCloud.with_local_advisor_engine? = false Setting[:allow_auto_inventory_upload] = true Setting[:allow_auto_insights_mismatch_delete] = true @@ -16,6 +17,7 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase test 'Skips execution if auto upload is disabled' do Setting[:allow_auto_inventory_upload] = false + ForemanRhCloud.with_local_advisor_engine? = false InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).never @@ -25,10 +27,20 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase test 'Skips mismatch deletion if the setting is disabled' do Setting[:allow_auto_inventory_upload] = true Setting[:allow_auto_insights_mismatch_delete] = false + ForemanRhCloud.with_local_advisor_engine? = false InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).times(Organization.unscoped.count) InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_remove_insights_hosts).never ForemanTasks.sync_task(InventorySync::Async::InventoryScheduledSync) end + + test 'Skips execution if local advisor engine is enabled' do + Setting[:allow_auto_inventory_upload] = false + ForemanRhCloud.with_local_advisor_engine? = true + + InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).never + + ForemanTasks.sync_task(InventorySync::Async::InventoryScheduledSync) + end end