Skip to content

Commit

Permalink
Merge pull request #12424 from tinaafitz/notification_provisioned
Browse files Browse the repository at this point in the history
Automate Provisioned Notifications - Use Automate notifications instead of event notifications.
(cherry picked from commit 638f4d7)

https://bugzilla.redhat.com/show_bug.cgi?id=1397076
  • Loading branch information
gmcculloug authored and chessbyte committed Nov 21, 2016
1 parent c1e7b32 commit c636534
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
Expand Up @@ -9,10 +9,12 @@
case $evm.root['vmdb_object_type']
when 'service_template_provision_task'
final_message += "Service [#{@task.destination.name}] Provisioned Successfully"
$evm.create_notification(:type => :automate_service_provisioned, :subject => @task.destination) if @task.miq_request_task.nil?
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)
else
final_message += $evm.inputs['message']
end
Expand Down
4 changes: 2 additions & 2 deletions db/fixtures/notification_types.yml
Expand Up @@ -4,7 +4,7 @@
:expires_in: 7.days
:level: :success
:audience: tenant
- :name: service_provisioned
- :name: automate_service_provisioned
:message: Service %{subject} has been provisioned.
:expires_in: 7.days
:level: :success
Expand All @@ -14,7 +14,7 @@
:expires_in: 7.days
:level: :success
:audience: tenant
- :name: vm_provisioned
- :name: automate_vm_provisioned
:message: Virtual Machine %{subject} has been provisioned.
:expires_in: 7.days
:level: :success
Expand Down
10 changes: 8 additions & 2 deletions spec/automation/unit/method_validation/task_finished_spec.rb
Expand Up @@ -14,6 +14,7 @@ def build_resolve_path
let(:miq_server) { EvmSpecHelper.local_miq_server }
let(:ems) { FactoryGirl.create(:ems_vmware_with_authentication) }
let(:vm_template) { FactoryGirl.create(:template_vmware, :ext_management_system => ems) }
let(:vm) { FactoryGirl.create(:vm_vmware, :ext_management_system => ems) }
let(:options) { {:src_vm_id => [vm_template.id, vm_template.name], :pass => 1} }
let(:miq_provision_request) do
FactoryGirl.create(:miq_provision_request,
Expand All @@ -27,19 +28,24 @@ def build_resolve_path
FactoryGirl.create(:miq_provision_vmware, :provision_type => 'template',
:state => 'pending', :status => 'Ok',
:miq_request => miq_provision_request,
:options => options, :userid => user.userid)
:options => options, :userid => user.userid, :vm => vm)
end

it "miq_provision method succeeds" do
type = :automate_vm_provisioned
FactoryGirl.create(:notification_type, :name => type)

msg = "[#{miq_server.name}] VM [] Provisioned Successfully"
@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.count).to eq(0)
add_call_method
ws
expect(provision.reload.status).to eq('Ok')
expect(provision.state).to eq('finished')
msg = "[#{miq_server.name}] VM [] Provisioned Successfully"
expect(miq_provision_request.reload.message).to eq(msg)
expect(Notification.find_by(:notification_type_id => NotificationType.find_by_name(type).id)).not_to be_nil
end

it "task_finished method input message" do
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/miq_automation_engine/miq_ae_service_spec.rb
Expand Up @@ -172,7 +172,7 @@ module MiqAeServiceSpec
end

it "invalid subject" do
expect { miq_ae_service.create_notification!(:type => :vm_provisioned, :subject => 'fred') }
expect { miq_ae_service.create_notification!(:type => :vm_retired, :subject => 'fred') }
.to raise_error(ArgumentError, "Subject must be a valid Active Record object")
end

Expand Down Expand Up @@ -205,7 +205,7 @@ module MiqAeServiceSpec
end

it "invalid subject" do
expect { miq_ae_service.create_notification(:type => :vm_provisioned, :subject => 'fred') }
expect { miq_ae_service.create_notification(:type => :vm_retired, :subject => 'fred') }
.not_to raise_error
end

Expand Down
2 changes: 1 addition & 1 deletion spec/models/notification_spec.rb
Expand Up @@ -6,7 +6,7 @@
describe '.emit' do
context 'successful' do
let(:vm) { FactoryGirl.create(:vm, :tenant => tenant) }
let(:notification_type) { :vm_provisioned }
let(:notification_type) { :vm_retired }

subject { Notification.create(:type => notification_type, :subject => vm) }

Expand Down

0 comments on commit c636534

Please sign in to comment.