Skip to content

Commit

Permalink
Fix inconsistent dialog input for Workflows
Browse files Browse the repository at this point in the history
Workflows run for a dynamic dialog have their dialog_values nested
under a top-level `{:dialog => {}} ` key, workflows run as a Service
Template Entrypoint should have the same format.
  • Loading branch information
agrare committed Aug 7, 2024
1 parent c1c063b commit c17fe3b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/miq_request_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def valid_states
end

def workflow_inputs
dialog_values
{:dialog => dialog_values}
end

def dialog_values
Expand Down
55 changes: 55 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,61 @@ 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", :context => hash_including("Execution" => hash_including("Input" => {"dialog" => {}})))
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

context "with dialog_values" do
let(:dialog_values) { {:foo => "bar"} }
before { @task_0.options[:dialog] = dialog_values }

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

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

expect(configuration_script.context).to include("Execution" => hash_including("Input" => {"dialog" => dialog_values}))
end
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 c17fe3b

Please sign in to comment.