Skip to content

Commit

Permalink
Set service's lifecycle_state by miq_request_task's state.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfu committed Aug 26, 2019
1 parent 34f7b65 commit b1cd8b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/models/mixins/lifecycle_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion app/models/service_template_provision_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 top_task_for_service?
end

private

def top_task_for_service?
source_type == "ServiceTemplate"
end

def valid_states
super + ["provisioned"]
end
Expand Down
10 changes: 4 additions & 6 deletions spec/models/service_template_provision_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b1cd8b2

Please sign in to comment.