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

Let ansible worker gracefully stop #15643

Merged
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
6 changes: 3 additions & 3 deletions app/models/embedded_ansible_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ class EmbeddedAnsibleWorker < MiqWorker
require_nested :Runner
include_concern 'ObjectManagement'

# Don't allow multiple ansible monitor workers to run at once
self.include_stopping_workers_on_synchronize = true

self.required_roles = ['embedded_ansible']

def start_runner
Expand Down Expand Up @@ -48,9 +51,6 @@ def find_worker_thread_object
end
end

alias terminate kill
alias stop kill

def status_update
# don't monitor the memory/cpu usage of this process yet
# If we don't have a pid of a process we want to monitor,super will catch an Errno::ESRCH and abort the worker
Expand Down
40 changes: 19 additions & 21 deletions spec/models/embedded_ansible_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,25 @@
end
end

%w(kill stop terminate).each do |stop_method|
describe "##{stop_method}" do
it "exits the monitoring thread and destroys the worker row" do
thread_double = double
expect(thread_double).to receive(:exit)
allow(subject).to receive(:find_worker_thread_object).and_return(thread_double)
subject.public_send(stop_method)
expect { subject.reload }.to raise_error(ActiveRecord::RecordNotFound)
end

it "destroys the worker row but refuses to kill the main thread" do
allow(subject).to receive(:find_worker_thread_object).and_return(Thread.main)
subject.public_send(stop_method)
expect { subject.reload }.to raise_error(ActiveRecord::RecordNotFound)
end

it "destroys the worker row if the monitor thread is not found" do
allow(subject).to receive(:find_worker_thread_object).and_return(nil)
subject.public_send(stop_method)
expect { subject.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
describe "#kill" do
it "exits the monitoring thread and destroys the worker row" do
thread_double = double
expect(thread_double).to receive(:exit)
allow(subject).to receive(:find_worker_thread_object).and_return(thread_double)
subject.kill
expect { subject.reload }.to raise_error(ActiveRecord::RecordNotFound)
end

it "destroys the worker row but refuses to kill the main thread" do
allow(subject).to receive(:find_worker_thread_object).and_return(Thread.main)
subject.kill
expect { subject.reload }.to raise_error(ActiveRecord::RecordNotFound)
end

it "destroys the worker row if the monitor thread is not found" do
allow(subject).to receive(:find_worker_thread_object).and_return(nil)
subject.kill
expect { subject.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end
Expand Down