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

Move the notifications to include more of the setup #16508

Merged
merged 1 commit into from
Nov 20, 2017
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: 2 additions & 4 deletions app/models/embedded_ansible_worker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ def prepare
end

def do_before_work_loop
raise_role_notification(:role_activate_start)
setup_ansible
update_embedded_ansible_provider
raise_role_notification(:role_activate_success)
rescue => err
_log.log_backtrace(err)
do_exit(err.message, 1)
Expand All @@ -28,13 +30,9 @@ def before_exit(*_)
end

def setup_ansible
raise_role_notification(:role_activate_start)

_log.info("Starting embedded ansible service ...")
embedded_ansible.start
_log.info("Finished starting embedded ansible service.")

raise_role_notification(:role_activate_success)
end

def update_embedded_ansible_provider
Expand Down
72 changes: 37 additions & 35 deletions spec/models/embedded_ansible_worker/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,43 @@
r
}

it "#do_before_work_loop exits on exceptions" do
expect(runner).to receive(:setup_ansible)
expect(runner).to receive(:update_embedded_ansible_provider).and_raise(StandardError)
expect(runner).to receive(:do_exit)
runner.do_before_work_loop
context "#do_before_work_loop" do
let(:start_notification_id) { NotificationType.find_by(:name => "role_activate_start").id }
let(:success_notification_id) { NotificationType.find_by(:name => "role_activate_success").id }

before do
ServerRole.seed
NotificationType.seed
end

it "creates a notification to inform the user that the service has started" do
expect(runner).to receive(:setup_ansible)
expect(runner).to receive(:update_embedded_ansible_provider)

runner.do_before_work_loop

note = Notification.find_by(:notification_type_id => success_notification_id)
expect(note.options[:role_name]).to eq("Embedded Ansible")
expect(note.options.keys).to include(:server_name)
end

it "creates a notification to inform the user that the role has been assigned" do
expect(runner).to receive(:setup_ansible)
expect(runner).to receive(:update_embedded_ansible_provider)

runner.do_before_work_loop

note = Notification.find_by(:notification_type_id => start_notification_id)
expect(note.options[:role_name]).to eq("Embedded Ansible")
expect(note.options.keys).to include(:server_name)
end

it "exits on exceptions" do
expect(runner).to receive(:setup_ansible)
expect(runner).to receive(:update_embedded_ansible_provider).and_raise(StandardError)
expect(runner).to receive(:do_exit)
runner.do_before_work_loop
end
end

context "#update_embedded_ansible_provider" do
Expand Down Expand Up @@ -96,35 +128,5 @@
end
end
end

context "#setup_ansible" do
let(:start_notification_id) { NotificationType.find_by(:name => "role_activate_start").id }
let(:success_notification_id) { NotificationType.find_by(:name => "role_activate_success").id }

before do
ServerRole.seed
NotificationType.seed
end

it "creates a notification to inform the user that the service has started" do
expect(embedded_ansible_instance).to receive(:start)

runner.setup_ansible

note = Notification.find_by(:notification_type_id => success_notification_id)
expect(note.options[:role_name]).to eq("Embedded Ansible")
expect(note.options.keys).to include(:server_name)
end

it "creates a notification to inform the user that the role has been assigned" do
expect(embedded_ansible_instance).to receive(:start)

runner.setup_ansible

note = Notification.find_by(:notification_type_id => start_notification_id)
expect(note.options[:role_name]).to eq("Embedded Ansible")
expect(note.options.keys).to include(:server_name)
end
end
end
end