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

Automate Provisioned Notifications - Use Automate notifications instead of event notifications. #12424

Merged
merged 1 commit into from
Nov 19, 2016

Conversation

tinaafitz
Copy link
Member

@tinaafitz tinaafitz commented Nov 3, 2016

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:

  • Events are raised when the service/vm is provisioned, not when the provisioning state machine has completed. This could result in a "provisioned successfully" notification on a failed provision if a post provision step were to fail.
  • The service provisioned event is raised multiple times which causes duplicate service provisioned notifications.
  • The timing also causes the notifications to be out of sync.

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:
screen shot 2016-11-03 at 4 44 41 pm

after:
screen shot 2016-11-03 at 4 46 27 pm

@tinaafitz
Copy link
Member Author

@mkanoor Please review.

@miq-bot
Copy link
Member

miq-bot commented Nov 3, 2016

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@tinaafitz tinaafitz changed the title Remove vm_provisioned and service_provisioned events. [WIP] Remove vm_provisioned and service_provisioned events. Nov 3, 2016
@chessbyte chessbyte added the wip label Nov 4, 2016
@tinaafitz tinaafitz changed the title [WIP] Remove vm_provisioned and service_provisioned events. Renamed vm_provisioned and service_provisioned notification types to prevent event generated notifications and added notifications to common task finished Automate method. Nov 7, 2016
@tinaafitz tinaafitz changed the title Renamed vm_provisioned and service_provisioned notification types to prevent event generated notifications and added notifications to common task finished Automate method. Automate Provisioned Notifications - Use Automate notifications instead of event notifications. Nov 7, 2016
@tinaafitz
Copy link
Member Author

@billfitzgerald0120 Please review.

@tinaafitz
Copy link
Member Author

@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)
Copy link
Contributor

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?

Copy link
Member Author

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 tinaafitz closed this Nov 8, 2016
@tinaafitz tinaafitz reopened this Nov 8, 2016
@billfitzgerald0120
Copy link
Contributor

@tinaafitz
I tested this and got the new notifications.
Looks Good 👍

@@ -1,6 +1,8 @@
describe "task_finished_status" do
include Spec::Support::AutomationHelper

before { NotificationType.seed }
Copy link
Member

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) }
Copy link
Member

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"
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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.

@chessbyte chessbyte removed the wip label Nov 17, 2016
prevent them from being used for events.
Add notification in task_finished common method.

https://bugzilla.redhat.com/show_bug.cgi?id=1389312
@tinaafitz
Copy link
Member Author

@gmcculloug Changes made.

@miq-bot
Copy link
Member

miq-bot commented Nov 18, 2016

Checked commit tinaafitz@89ddb9c with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
4 files checked, 1 offense detected

db/fixtures/ae_datastore/ManageIQ/System/CommonMethods/StateMachineMethods.class/methods/task_finished.rb

@gmcculloug gmcculloug merged commit 638f4d7 into ManageIQ:master Nov 19, 2016
@gmcculloug gmcculloug added this to the Sprint 50 Ending Dec 5, 2016 milestone Nov 19, 2016
@chessbyte
Copy link
Member

@chessbyte
Copy link
Member

chessbyte commented Nov 20, 2016

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

@simaishi
Copy link
Contributor

@gmcculloug
Copy link
Member

Refactored tests in PR #12368 will resolve merge conflicts.

chessbyte pushed a commit that referenced this pull request Nov 21, 2016
Automate Provisioned Notifications - Use Automate notifications instead of event notifications.
(cherry picked from commit 638f4d7)

https://bugzilla.redhat.com/show_bug.cgi?id=1397076
@chessbyte
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants