Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark workers associated with failed systemd units as stopped #23182

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/models/miq_server/worker_management/systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions spec/models/miq_server/worker_management/systemd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
context "with failed services" do
let(:service_name) { "[email protected]" }
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")
Expand All @@ -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

Expand Down