Skip to content

Commit

Permalink
Merge pull request #177 from billfitzgerald0120/vmmigrate_email_fix
Browse files Browse the repository at this point in the history
Fix VM Migrate complete email when To field is nil.
(cherry picked from commit 07fe288)

https://bugzilla.redhat.com/show_bug.cgi?id=1496937
  • Loading branch information
gmcculloug authored and simaishi committed Nov 10, 2017
1 parent bb2a9f7 commit a78b743
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Expand Up @@ -26,8 +26,9 @@
owner = $evm.vmdb('user', evm_owner_id) unless evm_owner_id.nil?
$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']
requester = miq_task.miq_request.requester

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

# Get from_email_address from model unless specified below
from = nil
Expand All @@ -42,7 +43,7 @@
body = "Hello, "

# VM Migration Email Body
body += "<br><br>Your request to migrate virtual machine #{vm.name} was approved and completed on #{Time.now.strftime('%A, %B %d, %Y at %I:%M%p')}. "
body += "<br><br>Your request to migrate virtual machine #{vm.name} was approved and completed on #{Time.zone.now.strftime('%A, %B %d, %Y at %I:%M%p')}. "
body += "<br><br>If you are not already logged in, you can access and manage your virtual machine here <a href='https://#{miq_server.ipaddress}/vm/show/#{vm['id']}'>https://#{miq_server.ipaddress}/vm/show/#{vm['id']}</a>"
body += "<br><br> Thank you,"
body += "<br> #{signature}"
Expand Down
Expand Up @@ -10,9 +10,17 @@
it 'sends email' do
expect(GenericMailer).to receive(:deliver).with(:automation_notification,
hash_including(:to => user.email,
:from => "evmadmin@example.com"
)
)
:from => "evmadmin@example.com"))
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 'expect email not to be sent' do
expect(GenericMailer).not_to receive(:deliver).with(:automation_notification,
hash_including(:to => nil,
:from => "evmadmin@example.com"))
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}"
Expand Down

0 comments on commit a78b743

Please sign in to comment.