Skip to content

Commit

Permalink
Move the notifications to include more of the setup
Browse files Browse the repository at this point in the history
Things can go wrong while setting up the default objects and
setting up the provider.

We should wait until all of this work is done before creating the
notification that says that the role has been successfully enabled.

https://bugzilla.redhat.com/show_bug.cgi?id=1458019
  • Loading branch information
carbonin committed Nov 20, 2017
1 parent 5deab50 commit 6c6d66a
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("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

0 comments on commit 6c6d66a

Please sign in to comment.