diff --git a/app/models/miq_server/worker_management/systemd.rb b/app/models/miq_server/worker_management/systemd.rb index 963b3a647b2..0bafdf83580 100644 --- a/app/models/miq_server/worker_management/systemd.rb +++ b/app/models/miq_server/worker_management/systemd.rb @@ -27,11 +27,16 @@ def cleanup_failed_workers end def cleanup_failed_systemd_services - service_names = failed_miq_service_namees + service_names = failed_miq_service_names return if service_names.empty? _log.info("Disabling failed unit files: [#{service_names.join(", ")}]") systemd_stop_services(service_names) + + _log.info("Stopping worker records for failed units: [#{service_names.join(", ")}]") + MiqWorker.find_current_or_starting.where(:system_uid => service_names).each do |w| + w.update!(:status => MiqWorker::STATUS_STOPPED) + end end private @@ -104,7 +109,7 @@ def failed_miq_services miq_services.select { |service| service[:active_state] == "failed" } end - def failed_miq_service_namees + def failed_miq_service_names failed_miq_services.pluck(:name) end diff --git a/spec/models/miq_server/worker_management/systemd_spec.rb b/spec/models/miq_server/worker_management/systemd_spec.rb index 69e476ca743..02b3c40db2a 100644 --- a/spec/models/miq_server/worker_management/systemd_spec.rb +++ b/spec/models/miq_server/worker_management/systemd_spec.rb @@ -26,6 +26,7 @@ context "with failed services" do let(:service_name) { "manageiq-generic@68400a7e-1747-4f10-be2a-d0fc91b705ca.service" } let(:units) { [{:name => service_name, :description => "ManageIQ Generic Worker", :load_state => "loaded", :active_state => "failed", :sub_state => "plugged", :job_id => 0, :job_type => "", :job_object_path => "/"}] } + let!(:worker) { FactoryBot.create(:miq_generic_worker, :miq_server => server, :status => "creating", :system_uid => service_name) } it "calls DisableUnitFiles with the service name" do expect(systemd_manager).to receive(:StopUnit).with(service_name, "replace") @@ -34,6 +35,16 @@ server.worker_manager.cleanup_failed_systemd_services end + + it "marks any active workers as stopped" do + expect(systemd_manager).to receive(:StopUnit).with(service_name, "replace") + expect(systemd_manager).to receive(:ResetFailedUnit).with(service_name) + expect(systemd_manager).to receive(:DisableUnitFiles).with([service_name], false) + + server.worker_manager.cleanup_failed_systemd_services + + expect(worker.reload.status).to eq("stopped") + end end end