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

Fix VM Migrate complete email when To field is nil. #177

Merged
merged 1 commit into from
Sep 20, 2017

Conversation

billfitzgerald0120
Copy link
Contributor

Made change to not send email when the To field is nil.
Added log message that email will not be sent.

https://bugzilla.redhat.com/show_bug.cgi?id=1486461

@billfitzgerald0120
Copy link
Contributor Author

@miq-bot add_label bug, fine/yes

@billfitzgerald0120
Copy link
Contributor Author

@miq-bot assign @gmcculloug

@billfitzgerald0120
Copy link
Contributor Author

@tinaafitz Please Review

@gmcculloug
Copy link
Member

@tinaafitz Changes are easier to review by ignoring whitespace: https://github.com/ManageIQ/manageiq-content/pull/177/files?w=1

@@ -27,25 +27,30 @@
$evm.log("info", "VM Owner: #{owner.inspect}")

# to_email_address from owner.email then from model if nil
to = owner.email || $evm.object['to_email_address']
to = owner.email unless owner.nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@billfitzgerald0120 Keep the original format and use try to handle the nil owner object.

to = owner.try(:email) || $evm.object['to_email_address']

@billfitzgerald0120
Copy link
Contributor Author

@gmcculloug made changes as requested

@@ -11,11 +11,21 @@
expect(GenericMailer).to receive(:deliver).with(:automation_notification,
hash_including(:to => user.email,
:from => "evmadmin@example.com"
)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@billfitzgerald0120 The change in whitespace here is revealing the rubocop warnings around alignment. Please update the closing parentheses, like you did in the new test below, to remove the warnings.

)
attrs = ["MiqServer::miq_server=#{miq_server.id}"]
attrs << "MiqRequestTask::vm_migrate_task=#{miq_request_task.id}"
attrs << "vm_migrate_task_id=#{miq_request_task.id}"
MiqAeEngine.instantiate("/Infrastructure/VM/Migrate/Email/VmMigrateTask_Complete?event=vm_migrated&#{attrs.join('&')}", user)
end

it 'sends email to nil' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test name is misleading as you are expecting the logic to not send an email in this case. Please reword.

@billfitzgerald0120
Copy link
Contributor Author

@gmcculloug Made changes as requested, please review

@gmcculloug
Copy link
Member

@billfitzgerald0120 @tinaafitz Looks like we have this exposure in a number of email methods. Do we handle this anywhere else? Would it make more sense to send the email to someone like an administrator in this case instead of just skipping the email when someone migrates a VM?

@billfitzgerald0120
Copy link
Contributor Author

@gmcculloug @tinaafitz We handle this in Infrastructure and Cloud MiqProvision_Complete method.
Sending it to an administrator sounds better that skipping.

@@ -27,25 +27,29 @@
$evm.log("info", "VM Owner: #{owner.inspect}")

# to_email_address from owner.email then from model if nil
to = owner.email || $evm.object['to_email_address']
to = owner.try(:email) || $evm.object['to_email_address']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@billfitzgerald0120 - I like the try here - so it's probably fine - but your fix works without it. The addition of your check for if to.nil? seems to be the real fix. I'm questioning the need for the try apart from readability.

@billfitzgerald0120
Copy link
Contributor Author

@tinaafitz I added the requester_email as the second choice for the 'to' email value.

@billfitzgerald0120
Copy link
Contributor Author

@tinaafitz Please Review

@gmcculloug
Copy link
Member

@tinaafitz Does the method need to change for this or can this be fixed in the schema? I recall we briefly discussed this.

@billfitzgerald0120 Can you describe the condition in which this happens since the schema includes a default email address? When would the to email address be empty?

@billfitzgerald0120
Copy link
Contributor Author

@gmcculloug @tinaafitz The problem was the owner.email was failing. I added the .try which fixed the problem. I added the requester.email as the second option. We talked about making sure that we send an email to someone and not just abort the email. The schema should always have a value but the requester is probably a better option. It's possible the schema has the default values for to_email_address instead of the actual requester.

-to = owner.email || $evm.object['to_email_address']
+to = owner.try(:email) || requester.email || $evm.object['to_email_address']

@billfitzgerald0120
Copy link
Contributor Author

@tinaafitz Please review

Made change to not send email when the To field is nil.
Added log message that email will not be sent.

https://bugzilla.redhat.com/show_bug.cgi?id=1486461
@miq-bot
Copy link
Member

miq-bot commented Sep 20, 2017

Checked commit billfitzgerald0120@655f095 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 👍

@gmcculloug gmcculloug merged commit 07fe288 into ManageIQ:master Sep 20, 2017
@gmcculloug gmcculloug added this to the Sprint 70 Ending Oct 2, 2017 milestone Sep 20, 2017
simaishi pushed a commit that referenced this pull request Nov 10, 2017
Fix VM Migrate complete email when To field is nil.
(cherry picked from commit 07fe288)

https://bugzilla.redhat.com/show_bug.cgi?id=1496937
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit a78b743cd0f2f857bace5192141d2f8b5e8864bd
Author: Greg McCullough <gmccullo@redhat.com>
Date:   Wed Sep 20 10:39:16 2017 -0400

    Merge pull request #177 from billfitzgerald0120/vmmigrate_email_fix
    
    Fix VM Migrate complete email when To field is nil.
    (cherry picked from commit 07fe288e98886d1c9bb98cf392a876c59b287413)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1496937

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.

None yet

5 participants