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

Set service's lifecycle_state based on miq_request_task's state. #19205

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 service_template_source?
end

private

def service_template_source?
source_type == "ServiceTemplate"
Copy link
Contributor

Choose a reason for hiding this comment

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

@lfu Just for information what is the source_type for other other child services wouldn't they be ServiceTemplate too.

Copy link
Member Author

Choose a reason for hiding this comment

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

As stated in the description, the child service could have MiqRequest or ServiceTempalte for source_type.

Copy link
Member

Choose a reason for hiding this comment

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

To be clear the reference to MiqRequest is the MiqProvisionRequestTemplate sub-class.

I found the name confusing as I kept thinking it was trying to reference the top task (the one for the service bundle), but it is really just trying to identify if the source of the task is a ServiceTemplate.

Maybe a better name would be: service_template_source?

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