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

Fix MiqRequestTask ResourceAction with a Workflow #23123

Merged
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: 1 addition & 3 deletions app/models/miq_provision_request_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ def execute
private

def service_options(parent_svc, service_task, template_service_resource)
parent_service_task = get_parent_task(service_task)

{
:miq_force_unique_name => [true, 1],
:service_guid => parent_svc.guid,
:service_resource_id => template_service_resource.id,
:service_template_request => false,
:configuration_script_payload_id => parent_service_task&.resource_action&.configuration_script_payload&.id
:configuration_script_payload_id => service_task.options&.dig(:parent_configuration_script_payload_id)
}
end

Expand Down
3 changes: 2 additions & 1 deletion app/models/miq_request_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def deliver_queue(req_type = request_type, zone = nil)

_log.info("Queuing #{request_class::TASK_DESCRIPTION}: [#{description}]...")

workflow = ConfigurationScriptPayload.find(options[:configuration_script_payload_id]) if options[:configuration_script_payload_id]
workflow_id = options[:configuration_script_payload_id]
workflow = ConfigurationScriptPayload.find(workflow_id) if workflow_id
if workflow
miq_task_id = workflow.run(:inputs => workflow_inputs, :userid => get_user.userid, :zone => zone, :object => self)

Expand Down
19 changes: 19 additions & 0 deletions app/models/service_template_provision_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ def requested_task_idx

def customize_request_task_attributes(req_task_attrs, idx)
req_task_attrs['options'][:pass] = idx

configuration_script_id = resource_action&.configuration_script_id
return if configuration_script_id.nil?

# If the service_template that we are provisioning is a "generic" provision
# type then we want to execute the request task with embedded_workflows if
# the resource_action has a configuration_script_id
if source.prov_type == "generic"
req_task_attrs['options'][:configuration_script_payload_id] = configuration_script_id
else
req_task_attrs['options'][:parent_configuration_script_payload_id] = configuration_script_id
end
end

def resource_action
resource_action_id = options.dig(:workflow_settings, :resource_action_id)
return if resource_action_id.nil?

ResourceAction.find(resource_action_id)
kbrock marked this conversation as resolved.
Show resolved Hide resolved
end

def originating_controller
Expand Down
37 changes: 37 additions & 0 deletions spec/models/service_template_provision_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,43 @@ def service_resource_id(index, scaling_max)
end

context "with configuration_script_payload" do
it "creates a configuration_script instance" do
zone = FactoryBot.create(:zone, :name => "special")
automation_manager = FactoryBot.create(:ems_workflows_automation, :zone => zone)
payload = FactoryBot.create(:embedded_workflow, :manager => automation_manager)
@task_0.source = FactoryBot.create(
:service_template_generic,
:name => "Provision",
:resource_actions => [
FactoryBot.create(:resource_action, :action => "Provision", :configuration_script_payload => payload)
]
)

@task_0.update(
:options => {
:configuration_script_payload_id => payload.id
}
)

@task_0.deliver_queue

expect(@task_0.reload.options.keys).to include(:miq_task_id, :configuration_script_id, :configuration_script_payload_id)

configuration_script = ConfigurationScript.find(@task_0.options[:configuration_script_id])

expect(configuration_script).to have_attributes(:manager => automation_manager, :run_by_userid => @admin.userid, :status => "pending")
expect(MiqQueue.first).to have_attributes(
:instance_id => configuration_script.id,
:class_name => configuration_script.type,
:method_name => "run",
:queue_name => "automate",
:role => "automate",
:args => [hash_including(:object_type => "ServiceTemplateProvisionTask", :object_id => @task_0.id)]
)
end
end

context "with a configuration_script_payload in options" do
it "creates a configuration_script instance" do
zone = FactoryBot.create(:zone, :name => "special")
automation_manager = FactoryBot.create(:ems_workflows_automation, :zone => zone)
Expand Down