Skip to content

Commit

Permalink
Merge pull request #16508 from carbonin/move_ansible_role_notifications
Browse files Browse the repository at this point in the history
Move the notifications to include more of the setup
(cherry picked from commit b5c8317)

https://bugzilla.redhat.com/show_bug.cgi?id=1517817
  • Loading branch information
gtanzillo authored and simaishi committed Nov 27, 2017
1 parent a2209d2 commit ef917d2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
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("calling EmbeddedAnsible.start")
EmbeddedAnsible.start
_log.info("calling EmbeddedAnsible.start finished")

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 @@ -15,11 +15,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 @@ -91,35 +123,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(EmbeddedAnsible).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(EmbeddedAnsible).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

0 comments on commit ef917d2

Please sign in to comment.