Skip to content

Commit

Permalink
Cleanup constantize of worker_class_names
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Sep 30, 2021
1 parent 60be0be commit 86ac151
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
21 changes: 7 additions & 14 deletions app/models/miq_server/worker_management/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,14 @@ def worker_not_responding(w)
end

def sync_workers
result = {}
MiqWorkerType.worker_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

result[c.name] = c.sync_workers
result[c.name][:adds].each { |pid| worker_add(pid) unless pid.nil? }
rescue => error
_log.error("Failed to sync_workers for class: #{class_name}")
_log.log_backtrace(error)
next
end
MiqWorkerType.worker_class_names.map(&:constantize).each_with_object({}) do |klass, result|
result[klass.name] = klass.sync_workers
result[klass.name][:adds].each { |pid| worker_add(pid) unless pid.nil? }
rescue => error
_log.error("Failed to sync_workers for class: #{klass.name}: #{error}")
_log.log_backtrace(error)
next
end
result
end

def sync_from_system
Expand Down
13 changes: 0 additions & 13 deletions spec/models/miq_server/worker_management/monitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,6 @@
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(MiqWorkerType).to receive(:worker_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(MiqWorkerType).to receive(:worker_class_names).and_return(%w(MiqGenericWorker MiqPriorityWorker))
allow(MiqGenericWorker).to receive(:sync_workers).and_raise
Expand Down

0 comments on commit 86ac151

Please sign in to comment.