-
Notifications
You must be signed in to change notification settings - Fork 896
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
Automate Provisioned Notifications - Use Automate notifications instead of event notifications. #12424
Automate Provisioned Notifications - Use Automate notifications instead of event notifications. #12424
Conversation
@mkanoor Please review. |
<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush. |
4ed1b06
to
81fc58d
Compare
81fc58d
to
49a4e4b
Compare
@billfitzgerald0120 Please review. |
@gmcculloug @mkanoor Modified notification to use predefined type and subject. Please review. |
when 'miq_provision' | ||
final_message += "VM [#{@task.get_option(:vm_target_name)}] " | ||
final_message += "IP [#{@task.vm.ipaddresses.first}] " if @task.vm && !@task.vm.ipaddresses.blank? | ||
final_message += "Provisioned Successfully" | ||
$evm.create_notification(:type => :automate_vm_provisioned, :subject => @task.vm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tinaafitz when provisioning a service with multiple vms will there be multiple notifications be created by this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkanoor Yes, there will be one notification for every VM provisioned in a service.
@tinaafitz |
@@ -1,6 +1,8 @@ | |||
describe "task_finished_status" do | |||
include Spec::Support::AutomationHelper | |||
|
|||
before { NotificationType.seed } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the factory to create a NotificationType
instance and move the call into the single test that needs it instead of doing a full seeding.
@@ -9,11 +11,16 @@ def build_resolve_path | |||
"#{instance}?#{namespace}&#{klass}&#{method}" | |||
end | |||
|
|||
def notification_exists(type) | |||
Notification.all.detect { |n| n.notification_type_id = NotificationType.find_by_name(type) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method can be removed.
end | ||
|
||
it "miq_provision method succeeds" do | ||
type = "automate_vm_provisioned" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create the Factory here using the type
value as the NotificationType
name.
notification_type = FactoryGirl.create(:notification_type, :name =>"automate_vm_provisioned")
@args = "status=fred&ae_result=ok&MiqProvision::miq_provision=#{provision.id}&" \ | ||
"MiqServer::miq_server=#{miq_server.id}&vmdb_object_type=miq_provision&" \ | ||
"object=miq_provision&message=not used" | ||
expect(notification_exists(type)).to be_nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be a check that Notification.count
is 0?
expect(miq_provision_request.reload.message).to eq(msg) | ||
expect(notification_exists(type)).not_to be_nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use expect(Notification.find_by(:notification_type => notification_type)).not_to be_nil
This completely remove the need for the notification_exists
method.
@@ -4,7 +4,7 @@ | |||
:expires_in: 7.days | |||
:level: :success | |||
:audience: tenant | |||
- :name: service_provisioned | |||
- :name: automate_service_provisioned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gtanzillo @isimluk Note: These are being renamed so they do not generate notifications from the events. We need more control over when to rise the notification.
prevent them from being used for events. Add notification in task_finished common method. https://bugzilla.redhat.com/show_bug.cgi?id=1389312
49a4e4b
to
89ddb9c
Compare
@gmcculloug Changes made. |
Checked commit tinaafitz@89ddb9c with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1 db/fixtures/ae_datastore/ManageIQ/System/CommonMethods/StateMachineMethods.class/methods/task_finished.rb
|
@simaishi Need Euwe BZ for https://bugzilla.redhat.com/show_bug.cgi?id=1389312 |
Euwe Backport conflict: $ git cherry-pick -e -x -m 1 638f4d7
error: could not apply 638f4d7... Merge pull request #12424 from tinaafitz/notification_provisioned
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
$ git status
On branch euwe
Your branch is up-to-date with 'upstream/euwe'.
You are currently cherry-picking commit 638f4d7.
(fix conflicts and run "git cherry-pick --continue")
(use "git cherry-pick --abort" to cancel the cherry-pick operation)
Changes to be committed:
modified: db/fixtures/ae_datastore/ManageIQ/System/CommonMethods/StateMachineMethods.class/__methods__/task_finished.rb
modified: db/fixtures/notification_types.yml
modified: spec/automation/unit/method_validation/task_finished_spec.rb
modified: spec/models/notification_spec.rb
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: spec/lib/miq_automation_engine/miq_ae_service_spec.rb
$ git diff diff --cc spec/lib/miq_automation_engine/miq_ae_service_spec.rb
index 1a3b93d,e4ea8e2..0000000
--- a/spec/lib/miq_automation_engine/miq_ae_service_spec.rb
+++ b/spec/lib/miq_automation_engine/miq_ae_service_spec.rb
@@@ -169,9 -173,7 +169,13 @@@ module MiqAeServiceSpe
end
it "invalid subject" do
++<<<<<<< HEAD
+ allow(workspace).to receive(:persist_state_hash).and_return({})
+ allow(workspace).to receive(:ae_user).and_return(user)
+ expect { miq_ae_service.create_notification!(:type => :vm_provisioned, :subject => 'fred') }
++=======
+ expect { miq_ae_service.create_notification!(:type => :vm_retired, :subject => 'fred') }
++>>>>>>> 638f4d7... Merge pull request #12424 from tinaafitz/notification_provisioned
.to raise_error(ArgumentError, "Subject must be a valid Active Record object")
end
@@@ -211,9 -206,7 +215,13 @@@
end
it "invalid subject" do
++<<<<<<< HEAD
+ allow(workspace).to receive(:persist_state_hash).and_return({})
+ allow(workspace).to receive(:ae_user).and_return(user)
+ expect { miq_ae_service.create_notification(:type => :vm_provisioned, :subject => 'fred') }
++=======
+ expect { miq_ae_service.create_notification(:type => :vm_retired, :subject => 'fred') }
++>>>>>>> 638f4d7... Merge pull request #12424 from tinaafitz/notification_provisioned
.not_to raise_error
end
|
Refactored tests in PR #12368 will resolve merge conflicts. |
Automate Provisioned Notifications - Use Automate notifications instead of event notifications. (cherry picked from commit 638f4d7) https://bugzilla.redhat.com/show_bug.cgi?id=1397076
Euwe Backport details: $ git log -1
commit c636534e682a2690e0aed4ad777ec30aa4f1c14a
Author: Greg McCullough <gmccullo@redhat.com>
Date: Sat Nov 19 08:57:08 2016 -0500
Merge pull request #12424 from tinaafitz/notification_provisioned
Automate Provisioned Notifications - Use Automate notifications instead of event notifications.
(cherry picked from commit 638f4d79956b8b80b540146f203d716e8df5955b)
https://bugzilla.redhat.com/show_bug.cgi?id=1397076 |
Renamed provisioned notification_types and add notification in task_finished common method.
Notifications are automatically generated for several events, including the vm_provisioned and service_provisioned events.
The event provisioned notifications have a few issues:
Renamed the notification_types for event generated notifications and added the provisioned successfully notification to the common task_finished method.
https://bugzilla.redhat.com/show_bug.cgi?id=1389312
before:
after: