Skip to content

Commit

Permalink
Merge pull request #18336 from djberg96/conversion_host_params
Browse files Browse the repository at this point in the history
Modify the enable ConversionHost::Configurations#enable method to handle arguments more robustly

(cherry picked from commit 933ff48)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1702023
  • Loading branch information
kbrock authored and simaishi committed Apr 22, 2019
1 parent 3f30559 commit a40a021
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions app/models/conversion_host/configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@ def queue_configuration(op, instance_id, resource, params, auth_user = nil)
end

def enable_queue(params, auth_user = nil)
params = params.symbolize_keys
resource_type = params[:resource_type]
resource_id = params[:resource_id]
resource = resource_type.constantize.find(resource_id)

resource = resource_type.to_s.downcase.classify.constantize.find(resource_id)

queue_configuration('enable', nil, resource, [params], auth_user)
end

def enable(params)
params = params.symbolize_keys
_log.info("Enabling a conversion_host with parameters: #{params}")
params.delete(:task_id) # in case this is being called through *_queue which will stick in a :task_id
params.delete(:miq_task_id) # miq_queue.activate_miq_task will stick in a :miq_task_id

vddk_url = params.delete("param_v2v_vddk_package_url")
params.delete(:task_id) # In case this is being called through *_queue which will stick in a :task_id
params.delete(:miq_task_id) # The miq_queue.activate_miq_task will stick in a :miq_task_id

vddk_url = params.delete(:param_v2v_vddk_package_url)
resource_id = params[:resource_id]
resource_type = params[:resource_type]
resource = resource_type.constantize.find(resource_id)

# Effectively ignore case since we cannot guarantee it from the REST API
resource = resource_type.to_s.downcase.classify.constantize.find(resource_id)

conversion_host = new(params.merge(:resource => resource))
conversion_host.enable_conversion_host_role(vddk_url)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/conversion_host/configurations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
task_id = described_class.enable_queue(params)
expect(MiqTask.find(task_id)).to have_attributes(:name => expected_task_action)
expect(MiqQueue.first).to have_attributes(
:args => [params],
:args => [params.merge(:task_id => task_id)],
:class_name => described_class.name,
:method_name => "enable",
:priority => MiqQueue::NORMAL_PRIORITY,
Expand Down

0 comments on commit a40a021

Please sign in to comment.