diff --git a/app/models/miq_schedule_worker/jobs.rb b/app/models/miq_schedule_worker/jobs.rb index 5bf73111e62e..710eceda5db1 100644 --- a/app/models/miq_schedule_worker/jobs.rb +++ b/app/models/miq_schedule_worker/jobs.rb @@ -43,7 +43,12 @@ def session_check_session_timeout end def job_check_for_evm_snapshots(job_not_found_delay) - queue_work_on_each_zone(:class_name => "Job", :method_name => "check_for_evm_snapshots", :args => [job_not_found_delay]) + queue_work_on_each_zone_with_active_role( + "smartstate", + :class_name => "Job", + :method_name => "check_for_evm_snapshots", + :args => [job_not_found_delay] + ) end def vm_scan_dispatcher_dispatch @@ -207,4 +212,10 @@ def queue_work(options) def queue_work_on_each_zone(options) Zone.in_my_region.each { |z| queue_work(options.merge(:zone => z.name)) } end + + def queue_work_on_each_zone_with_active_role(role_name, options) + Zone.in_my_region + .select { |z| z.role_active?(role_name) } + .each { |z| queue_work(options.merge(:zone => z.name)) } + end end diff --git a/spec/models/miq_schedule_worker/jobs_spec.rb b/spec/models/miq_schedule_worker/jobs_spec.rb index a957416ce0ac..fc1956a53765 100644 --- a/spec/models/miq_schedule_worker/jobs_spec.rb +++ b/spec/models/miq_schedule_worker/jobs_spec.rb @@ -108,5 +108,27 @@ expect(MiqQueue.where(:method_name => "log_config").first).to have_attributes(:queue_name => "miq_server", :server_guid => guid, :zone => zone.name, :priority => MiqQueue::MEDIUM_PRIORITY) end end + + describe "#job_check_for_evm_snapshots" do + context "with no zones having an active smartstate role" do + it "doesn't queue any work" do + described_class.new.job_check_for_evm_snapshots(1.hour) + expect(MiqQueue.count).to be_zero + end + end + + context "with a zone having an active smartstate role" do + let(:role) { ServerRole.find_by(:name => "smartstate") || FactoryBot.create(:server_role, :name => 'smartstate', :max_concurrent => 0) } + before do + server.assign_role(role).update(:active => true) + end + + it "doesn't queue any work" do + described_class.new.job_check_for_evm_snapshots(1.hour) + expect(MiqQueue.count).to eq(1) + expect(MiqQueue.where(:class_name => "Job", :method_name => "check_for_evm_snapshots").first).to have_attributes(:queue_name => "generic", :zone => zone.name, :priority => MiqQueue::MEDIUM_PRIORITY) + end + end + end end end