diff --git a/app/models/mixins/lifecycle_mixin.rb b/app/models/mixins/lifecycle_mixin.rb index 9dff6953f9d..155d6848738 100644 --- a/app/models/mixins/lifecycle_mixin.rb +++ b/app/models/mixins/lifecycle_mixin.rb @@ -6,9 +6,9 @@ module LifecycleMixin STATE_PROVISIONING = 'provisioning'.freeze def update_lifecycle_state - case miq_request.request_state + case miq_request_task.state when "finished" - lifecycle_state = miq_request.status == 'Ok' ? STATE_PROVISIONED : STATE_ERROR_PROVISIONING + lifecycle_state = miq_request_task.status == 'Ok' ? STATE_PROVISIONED : STATE_ERROR_PROVISIONING update(:lifecycle_state => lifecycle_state) else update(:lifecycle_state => STATE_PROVISIONING) diff --git a/app/models/service_template_provision_task.rb b/app/models/service_template_provision_task.rb index 79ddf7cf2e5..f2e173216b0 100644 --- a/app/models/service_template_provision_task.rb +++ b/app/models/service_template_provision_task.rb @@ -214,11 +214,15 @@ def task_finished return if service.nil? service.raise_provisioned_event - service.update_lifecycle_state if miq_request_task.nil? + service.update_lifecycle_state if service_template_source? end private + def service_template_source? + source_type == "ServiceTemplate" + end + def valid_states super + ["provisioned"] end diff --git a/spec/models/service_template_provision_task_spec.rb b/spec/models/service_template_provision_task_spec.rb index d0a23634d8f..69d98d73471 100644 --- a/spec/models/service_template_provision_task_spec.rb +++ b/spec/models/service_template_provision_task_spec.rb @@ -268,17 +268,15 @@ def service_resource_id(index, scaling_max) it 'set service lifecycle_state to provisioned' do expect(MiqEvent).to receive(:raise_evm_event).with(@service, :service_provisioned) - @task_0.destination = @service - @request.miq_request_tasks.except(@task_0).each { |t| t.update(:state => "finished") } - @task_0.update_and_notify_parent(:state => "finished", :status => "Ok", :message => "Test Message") + @task_3.update(:destination => @service, :source_type => "ServiceTemplate", :state => "finished", :status => "Ok") + @task_3.task_finished expect(@service.provisioned?).to be true end it 'set service lifecycle_state to error_provisioned' do expect(MiqEvent).to receive(:raise_evm_event).with(@service, :service_provisioned) - @task_0.destination = @service - @request.miq_request_tasks.except(@task_0).each { |t| t.update(:state => "finished") } - @task_0.update_and_notify_parent(:state => "finished", :status => "Error", :message => "Test Message") + @task_3.update(:destination => @service, :source_type => "ServiceTemplate", :state => "finished", :status => "Error") + @task_3.task_finished expect(@service.provision_failed?).to be true end end