diff --git a/app/models/miq_server/worker_management/monitor.rb b/app/models/miq_server/worker_management/monitor.rb index c13bc816dea..14bdf236ad1 100644 --- a/app/models/miq_server/worker_management/monitor.rb +++ b/app/models/miq_server/worker_management/monitor.rb @@ -50,6 +50,8 @@ def sync_workers self.class.monitor_class_names.each do |class_name| begin c = class_name.constantize + raise NameError, "Constant problem: expected: #{class_name}, constantized: #{c.name}" unless c.name == class_name + c.ensure_systemd_files if c.systemd_worker? result[c.name] = c.sync_workers result[c.name][:adds].each { |pid| worker_add(pid) unless pid.nil? } diff --git a/spec/models/miq_server/worker_management/monitor_spec.rb b/spec/models/miq_server/worker_management/monitor_spec.rb index 09565987532..e09cd0e2368 100644 --- a/spec/models/miq_server/worker_management/monitor_spec.rb +++ b/spec/models/miq_server/worker_management/monitor_spec.rb @@ -33,6 +33,20 @@ context "#sync_workers" do let(:server) { EvmSpecHelper.local_miq_server } + + it "ensures only expected worker classes are constantized" do + # Autoload abstract base class for the event catcher + ManageIQ::Providers::BaseManager::EventCatcher + + # We'll try to constantize a non-existing EventCatcher class in an existing namespace, + # which incorrectly resolves to the base manager event catcher. + allow(MiqServer).to receive(:monitor_class_names).and_return(%w[ManageIQ::Providers::Foreman::ProvisioningManager::EventCatcher MiqGenericWorker]) + + expect(ManageIQ::Providers::BaseManager::EventCatcher).not_to receive(:sync_workers) + expect(MiqGenericWorker).to receive(:sync_workers).and_return(:adds => [111]) + expect(server.sync_workers).to eq("MiqGenericWorker"=>{:adds=>[111]}) + end + it "rescues exceptions and moves on" do allow(MiqServer).to receive(:monitor_class_names).and_return(%w(MiqGenericWorker MiqPriorityWorker)) allow(MiqGenericWorker).to receive(:sync_workers).and_raise