Skip to content

Commit

Permalink
ConfigurationScriptPaylod.run returns an miq_task_id
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Sep 29, 2023
1 parent 9e4b2e3 commit c2d5fe7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 27 deletions.
7 changes: 5 additions & 2 deletions app/models/miq_request_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
83 changes: 58 additions & 25 deletions spec/models/service_template_provision_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c2d5fe7

Please sign in to comment.