Skip to content

Commit

Permalink
Merge pull request #18541 from djberg96/conversion_host_task_context_…
Browse files Browse the repository at this point in the history
…data

[V2V] Set context data for the task associated with conversion host creation

(cherry picked from commit 65617fa)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1702278
  • Loading branch information
agrare authored and simaishi committed Apr 25, 2019
1 parent 564d170 commit 7ee3e9b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
31 changes: 27 additions & 4 deletions app/models/conversion_host/configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,22 @@ def queue_configuration(op, instance_id, resource, params, auth_user = nil)
:zone => resource.ext_management_system.my_zone,
:args => [params, auth_user]
}
MiqTask.generic_action_with_callback(task_opts, queue_opts)

task_id = MiqTask.generic_action_with_callback(task_opts, queue_opts)

# Set the context_data after the fact because the above call only accepts
# certain options while ignoring the rest. We also don't want to store
# any ssh key information. Useful for a retry option in the UI, and
# informational purposes in general.
#
MiqTask.find(task_id).tap do |task|
params = params&.except(:task_id, :miq_task_id)
hash = {:request_params => params&.reject { |key, _value| key.to_s.end_with?('private_key') }}
task.context_data = hash
task.save
end

task_id
end

def enable_queue(params, auth_user = nil)
Expand All @@ -42,12 +57,13 @@ def enable(params, auth_user = nil)
_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) # The miq_queue.activate_miq_task will stick in a :miq_task_id
miq_task_id = params.delete(:miq_task_id) # The miq_queue.activate_miq_task will stick in a :miq_task_id

vmware_vddk_package_url = params.delete(:vmware_vddk_package_url)
params[:vddk_transport_supported] = !vmware_vddk_package_url.nil?
params[:vddk_transport_supported] = vmware_vddk_package_url.present?

vmware_ssh_private_key = params.delete(:vmware_ssh_private_key)
params[:ssh_transport_supported] = !vmware_ssh_private_key.nil?
params[:ssh_transport_supported] = vmware_ssh_private_key.present?

ssh_key = params.delete(:conversion_host_ssh_private_key)

Expand All @@ -63,6 +79,13 @@ def enable(params, auth_user = nil)

conversion_host.enable_conversion_host_role(vmware_vddk_package_url, vmware_ssh_private_key)
conversion_host.save!

if miq_task_id
MiqTask.find(miq_task_id).tap do |task|
task.context_data.to_h[:conversion_host_id] = conversion_host.id
task.save
end
end
end
rescue StandardError => error
raise
Expand Down
11 changes: 10 additions & 1 deletion spec/models/conversion_host/configurations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@

it "to queue with a task" do
task_id = described_class.enable_queue(params)
expect(MiqTask.find(task_id)).to have_attributes(:name => expected_task_action)
expected_context_data = {:request_params => params.except(:resource)}

expect(MiqTask.find(task_id)).to have_attributes(:name => expected_task_action, :context_data => expected_context_data)
expect(MiqQueue.first).to have_attributes(
:args => [params.merge(:task_id => task_id).except(:resource), nil],
:class_name => described_class.name,
Expand All @@ -129,6 +131,13 @@
:zone => vm.ext_management_system.my_zone
)
end

it "rejects ssh key information as context data" do
task_id = described_class.enable_queue(params.merge(:conversion_host_ssh_private_key => 'xxx', :vmware_ssh_private_key => 'yyy'))
expected_context_data = {:request_params => params.except(:resource)}

expect(MiqTask.find(task_id)).to have_attributes(:name => expected_task_action, :context_data => expected_context_data)
end
end

context "#disable_queue" do
Expand Down

0 comments on commit 7ee3e9b

Please sign in to comment.