Skip to content

Commit

Permalink
Merge pull request #14867 from carbonin/add_notification_for_embedded…
Browse files Browse the repository at this point in the history
…_ansible_role_start

Add a notification for when the embedded ansible role is activated
(cherry picked from commit 7d91d8b)

https://bugzilla.redhat.com/show_bug.cgi?id=1458356
  • Loading branch information
jrafanie authored and simaishi committed Jun 2, 2017
1 parent fb7a59c commit 70df9b7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
8 changes: 5 additions & 3 deletions app/models/embedded_ansible_worker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ 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
raise_role_notification(:role_activate_success)
end

def update_embedded_ansible_provider
Expand Down Expand Up @@ -67,11 +69,11 @@ def message_sync_config(*_args); end

private

def raise_role_notification
def raise_role_notification(notification_type)
notification_options = {
:role_name => ServerRole.find_by(:name => worker.class.required_roles.first).description,
:server_name => MiqServer.my_server.name
}
Notification.create(:type => :role_activate_success, :options => notification_options)
Notification.create(:type => notification_type, :options => notification_options)
end
end
5 changes: 5 additions & 0 deletions db/fixtures/notification_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
:expires_in: 24.hours
:level: :info
:audience: superadmin
- :name: role_activate_start
:message: 'The role %{role_name} has started activation on server %{server_name}'
:expires_in: 24.hours
:level: :info
:audience: superadmin
- :name: tower_op_success
:message: 'The operation %{op_name} %{op_arg} on %{tower} completed successfully.'
:expires_in: 24.hours
Expand Down
17 changes: 15 additions & 2 deletions spec/models/embedded_ansible_worker/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
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
Expand All @@ -76,8 +79,18 @@

runner.setup_ansible

note = Notification.first
expect(note.notification_type.name).to eq("role_activate_success")
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(:configured?).and_return(true)
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
Expand Down

0 comments on commit 70df9b7

Please sign in to comment.