Skip to content

Commit

Permalink
Fix MiqRequestTask ResourceAction with a Workflow
Browse files Browse the repository at this point in the history
If a ServiceTemplate has a ResourceAction with a
configuration_script_payload as its entrypoint this was not being run by
MiqRequestTask#deliver_queue.
  • Loading branch information
agrare committed Aug 6, 2024
1 parent 354f6de commit 79a2629
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/miq_request_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ 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 = resource_action&.configuration_script_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)

options[:miq_task_id] = miq_task_id
options[:configuration_script_payload_id] = workflow.id
options[:configuration_script_payload_id] = workflow_id
options[:configuration_script_id] = MiqTask.find(miq_task_id).context_data[:workflow_instance_id]
save!
elsif self.class::AUTOMATE_DRIVES
Expand Down
31 changes: 31 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,37 @@ 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.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

0 comments on commit 79a2629

Please sign in to comment.