Skip to content

Commit

Permalink
Update system sync_starting/stopping for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Aug 1, 2024
1 parent 775166c commit 3b7a0c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
8 changes: 6 additions & 2 deletions app/models/miq_server/worker_management/systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,29 @@ def sync_from_system

def sync_starting_workers
sync_from_system
MiqWorker.find_all_starting.reject(&:rails_worker?).each do |worker|
starting = MiqWorker.find_all_starting
starting.reject(&:rails_worker?).each do |worker|
systemd_worker = miq_services_by_unit[worker[:system_uid]]
next if systemd_worker.nil?

if systemd_worker[:load_state] == "loaded" && systemd_worker[:active_state] == "active" && systemd_worker[:sub_state] == "running"
worker.update!(:status => MiqWorker::STATUS_STARTED)
end
end
starting.reload
end

def sync_stopping_workers
sync_from_system
MiqWorker.find_all_stopping.reject(&:rails_worker?).each do |worker|
stopping = MiqWorker.find_all_stopping
stopping.reject(&:rails_worker?).each do |worker|
# If the worker record is "stopping" and the systemd unit is gone then the
# worker has successfully exited.
next if miq_services_by_unit[worker[:system_uid]].present?

worker.update!(:status => MiqWorker::STATUS_STOPPED)
end
stopping.reload
end

def cleanup_failed_workers
Expand Down
18 changes: 9 additions & 9 deletions spec/models/miq_server/worker_management/systemd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
it "doesn't update the worker record" do
expect(worker).not_to receive(:update!)

server.worker_manager.sync_starting_workers
expect(server.worker_manager.sync_starting_workers).to be_empty
end
end

Expand All @@ -77,7 +77,7 @@
it "doesn't update the worker record" do
expect(worker).not_to receive(:update!)

server.worker_manager.sync_starting_workers
expect(server.worker_manager.sync_starting_workers).to include(worker)
end
end

Expand All @@ -88,7 +88,7 @@
it "doesn't update the worker record" do
expect(worker).not_to receive(:update!)

server.worker_manager.sync_starting_workers
expect(server.worker_manager.sync_starting_workers).to include(worker)
end
end

Expand All @@ -106,7 +106,7 @@
end

it "doesn't update the worker record" do
server.worker_manager.sync_starting_workers
expect(server.worker_manager.sync_starting_workers).to include(worker)

expect(worker.reload.status).to eq(MiqWorker::STATUS_STARTING)
end
Expand All @@ -125,7 +125,7 @@
end

it "sets the worker record to started" do
server.worker_manager.sync_starting_workers
expect(server.worker_manager.sync_starting_workers).to be_empty

expect(worker.reload.status).to eq(MiqWorker::STATUS_STARTED)
end
Expand All @@ -144,7 +144,7 @@
it "doesn't update the worker record" do
expect(worker).not_to receive(:update!)

server.worker_manager.sync_stopping_workers
expect(server.worker_manager.sync_stopping_workers).to be_empty
end
end

Expand All @@ -159,7 +159,7 @@
it "doesn't update the worker record" do
expect(worker).not_to receive(:update!)

server.worker_manager.sync_stopping_workers
expect(server.worker_manager.sync_stopping_workers).to include(worker)
end
end

Expand All @@ -181,13 +181,13 @@
it "doesn't update the worker record" do
expect(worker).not_to receive(:update!)

server.worker_manager.sync_stopping_workers
expect(server.worker_manager.sync_stopping_workers).to include(worker)
end
end

context "with a systemd unit that has exited" do
it "sets the worker record to stopped" do
server.worker_manager.sync_stopping_workers
expect(server.worker_manager.sync_stopping_workers).to be_empty

expect(worker.reload.status).to eq(MiqWorker::STATUS_STOPPED)
end
Expand Down

0 comments on commit 3b7a0c9

Please sign in to comment.