From c2d5fe78c82d541ffe9b227d9fbfba0518d99720 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Fri, 29 Sep 2023 11:57:27 -0400 Subject: [PATCH] ConfigurationScriptPaylod.run returns an miq_task_id --- app/models/miq_request_task.rb | 7 +- .../service_template_provision_task_spec.rb | 83 +++++++++++++------ 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/app/models/miq_request_task.rb b/app/models/miq_request_task.rb index 74f5c4cac9f..77101bff5ce 100644 --- a/app/models/miq_request_task.rb +++ b/app/models/miq_request_task.rb @@ -140,9 +140,12 @@ def deliver_queue(req_type = request_type, zone = nil) _log.info("Queuing #{request_class::TASK_DESCRIPTION}: [#{description}]...") if resource_action&.configuration_script_payload - configuration_script = resource_action.configuration_script_payload.run(:inputs => dialog_values, :userid => get_user.userid, :zone => zone, :object => self) + miq_task_id = resource_action.configuration_script_payload.run(:inputs => dialog_values, :userid => get_user.userid, :zone => zone, :object => self) + + options[:miq_task_id] = miq_task_id options[:configuration_script_payload_id] = resource_action.configuration_script_payload.id - options[:configuration_script_id] = configuration_script.id + options[:configuration_script_id] = MiqTask.find(miq_task_id).context_data[:workflow_instance_id] + save! elsif self.class::AUTOMATE_DRIVES deliver_to_automate(req_type, zone) else diff --git a/spec/models/service_template_provision_task_spec.rb b/spec/models/service_template_provision_task_spec.rb index 7e06c420d83..e6d2225b6ae 100644 --- a/spec/models/service_template_provision_task_spec.rb +++ b/spec/models/service_template_provision_task_spec.rb @@ -87,31 +87,64 @@ def service_resource_id(index, scaling_max) allow(@request).to receive(:approved?).and_return(true) end - it "delivers to the queue" do - zone = FactoryBot.create(:zone, :name => "special") - orchestration_manager = FactoryBot.create(:ext_management_system, :zone => zone) - @task_0.source = FactoryBot.create(:service_template_orchestration, :orchestration_manager => orchestration_manager) - automate_args = { - :object_type => 'ServiceTemplateProvisionTask', - :object_id => @task_0.id, - :namespace => 'Service/Provisioning/StateMachines', - :class_name => 'ServiceProvision_Template', - :instance_name => 'clone_to_service', - :automate_message => 'create', - :attrs => {'request' => 'clone_to_service', 'Service::Service' => @service.id}, - :user_id => @admin.id, - :miq_group_id => @admin.current_group_id, - :tenant_id => @admin.current_tenant.id, - } - expect(MiqQueue).to receive(:put).with( - :class_name => 'MiqAeEngine', - :method_name => 'deliver', - :args => [automate_args], - :role => 'automate', - :zone => 'special', - :tracking_label => tracking_label - ) - @task_0.deliver_queue + context "with AUTOMATE_DRIVES" do + it "delivers to the queue" do + zone = FactoryBot.create(:zone, :name => "special") + orchestration_manager = FactoryBot.create(:ext_management_system, :zone => zone) + @task_0.source = FactoryBot.create(:service_template_orchestration, :orchestration_manager => orchestration_manager, :resource_actions => [FactoryBot.create(:resource_action, :action => "Provision")]) + automate_args = { + :object_type => 'ServiceTemplateProvisionTask', + :object_id => @task_0.id, + :namespace => 'Service/Provisioning/StateMachines', + :class_name => 'ServiceProvision_Template', + :instance_name => 'clone_to_service', + :automate_message => 'create', + :attrs => {'request' => 'clone_to_service', 'Service::Service' => @service.id}, + :user_id => @admin.id, + :miq_group_id => @admin.current_group_id, + :tenant_id => @admin.current_tenant.id, + } + expect(MiqQueue).to receive(:put).with( + :class_name => 'MiqAeEngine', + :method_name => 'deliver', + :args => [automate_args], + :role => 'automate', + :zone => 'special', + :tracking_label => tracking_label + ) + @task_0.deliver_queue + end + 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 it "sets queue item to zone specified in dialog" do