diff --git a/app/models/automation_request.rb b/app/models/automation_request.rb index 3df9ad9cf27b..8ee31dad49e5 100644 --- a/app/models/automation_request.rb +++ b/app/models/automation_request.rb @@ -29,7 +29,7 @@ def self.create_from_ws(version, user, uri_parts, parameters, requester) options[:schedule_type] = parameters['schedule_time'].present? ? "schedule" : "immediately" options[:schedule_time] = parameters['schedule_time'].to_i.days.from_now if parameters['schedule_time'] - object_parameters = parse_out_objects(parameters) + object_parameters, parameters = parse_out_objects(parameters) attrs = MiqRequestWorkflow.parse_ws_string(parameters) attrs.merge!(object_parameters) @@ -42,18 +42,17 @@ def self.create_from_ws(version, user, uri_parts, parameters, requester) end def self.create_from_scheduled_task(user, uri_parts, parameters) - [:namespace, :class_name].each { |key| uri_parts.delete(key) if uri_parts.key?(key) } - approval = {'auto_approve' => true} - uri_parts.stringify_keys! - parameters.stringify_keys! - create_from_ws("1.1", user, uri_parts, parameters, approval) + uri_parts = uri_parts.stringify_keys + parameters = parameters.stringify_keys + %w[namespace class_name].each { |key| uri_parts.delete(key) } + create_from_ws("1.1", user, uri_parts, parameters, 'auto_approve' => true) end def self.parse_out_objects(parameters) + parameters = parameters.dup object_hash = parameters.select { |key, _v| key.to_s.include?(MiqAeEngine::MiqAeObject::CLASS_SEPARATOR) } - object_hash.each do |key, _v| - parameters.delete(key) - end + object_hash.keys.each { |k| parameters.extract!(k) } + return object_hash, parameters end def self.zone(options) diff --git a/spec/models/automation_request_spec.rb b/spec/models/automation_request_spec.rb index ea7f8ca12f2d..28e744e11a01 100644 --- a/spec/models/automation_request_spec.rb +++ b/spec/models/automation_request_spec.rb @@ -26,9 +26,9 @@ non_object_parameters = {'var2' => @ae_var2.to_s, 'var3' => @ae_var3.to_s} object_hash = AutomationRequest.parse_out_objects(object_parameters) non_object_hash = AutomationRequest.parse_out_objects(non_object_parameters) - expect(object_hash).to eq 'VmOrTemplate::vm' => 10 - expect(non_object_hash).to be_a Hash - expect(non_object_hash).to be_empty + expect(object_hash).to eq [{'VmOrTemplate::vm' => 10}, non_object_parameters] + expect(non_object_hash).to be_a Array + expect(non_object_hash).to eq [{}, non_object_parameters] end end @@ -65,6 +65,7 @@ @object_parameters = {'VmOrTemplate::vm' => 10, 'var2' => @ae_var2.to_s, 'var3' => @ae_var3.to_s} ar = AutomationRequest.create_from_ws(@version, admin, @uri_parts, @object_parameters, {}) expect(ar.options[:attrs]).to include("VmOrTemplate::vm" => 10, :var2 => @ae_var2.to_s) + expect(@object_parameters).to include("VmOrTemplate::vm" => 10) end it "does not allow overriding userid who is NOT in the database" do diff --git a/spec/models/miq_schedule_spec.rb b/spec/models/miq_schedule_spec.rb index 6fa2459fc893..31b462d8b4cf 100644 --- a/spec/models/miq_schedule_spec.rb +++ b/spec/models/miq_schedule_spec.rb @@ -566,6 +566,7 @@ context "valid action_automation_request" do let(:admin) { FactoryBot.create(:user_miq_request_approver) } + let(:ems) { FactoryBot.create(:ext_management_system) } let(:automate_sched) do MiqSchedule.create(:name => "test_method", :resource_type => "AutomationRequest", :userid => admin.userid, :enabled => true, @@ -575,7 +576,8 @@ :filter => {:uri_parts => {:namespace => 'ss', :instance => 'vv', :message => 'mm'}, - :parameters => {"param" => "8"}}) + :parameters => {"param" => "8", + "ExtManagementSystem::ext_management_system" => ems.id}}) end it "should create a request from a scheduled task" do @@ -587,6 +589,7 @@ FactoryBot.create(:user_admin, :userid => 'admin') automate_sched.action_automation_request(AutomationRequest, '') expect(AutomationRequest.where(:description => "Automation Task", :userid => admin.userid).count).to eq(1) + expect(automate_sched.filter[:parameters].keys).to include("ExtManagementSystem::ext_management_system") end end