Skip to content

Commit

Permalink
Merge pull request #18506 from fdupont-redhat/v2v_download_wrapper_log
Browse files Browse the repository at this point in the history
[V2V] Allow downloading wrapper log file

(cherry picked from commit 5307629)

https://bugzilla.redhat.com/show_bug.cgi?id=1686045
  • Loading branch information
agrare authored and simaishi committed Mar 6, 2019
1 parent 0d3d5aa commit 10259fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
19 changes: 12 additions & 7 deletions app/models/service_template_transformation_plan_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,20 @@ def destination_security_group
SecurityGroup.find_by(:id => vm_resource.options["osp_security_group_id"])
end

def transformation_log
def valid_transformation_log_types
%w(v2v wrapper)
end

def transformation_log(log_type = 'v2v')
if conversion_host.nil?
msg = "Conversion host was not found. Download of transformation log aborted."
_log.error(msg)
raise MiqException::Error, msg
end

logfile = options.fetch_path(:virtv2v_wrapper, "v2v_log")
logfile = options.fetch_path(:virtv2v_wrapper, "#{log_type}_log")
if logfile.blank?
msg = "The location of transformation log was not set. Download of transformation log aborted."
msg = "The location of #{log_type} log was not set. Download of #{log_type} log aborted."
_log.error(msg)
raise MiqException::Error, msg
end
Expand All @@ -140,20 +144,21 @@ def transformation_log

# Intend to be called by UI to display transformation log. The log is stored in MiqTask#task_results
# Since the task_results may contain a large block of data, it is desired to remove the task upon receiving the data
def transformation_log_queue(userid = nil)
def transformation_log_queue(userid = nil, log_type = 'v2v')
raise "Transformation log type '#{log_type}' not supported" unless valid_transformation_log_types.include?(log_type)
userid ||= User.current_userid || 'system'
if conversion_host.nil?
msg = "Conversion host was not found. Cannot queue the download of transformation log."
msg = "Conversion host was not found. Cannot queue the download of #{log_type} log."
return create_error_status_task(userid, msg).id
end

_log.info("Queuing the download of transformation log for #{description} with ID [#{id}]")
_log.info("Queuing the download of #{log_type} log for #{description} with ID [#{id}]")
options = {:userid => userid, :action => 'transformation_log'}
queue_options = {:class_name => self.class,
:method_name => 'transformation_log',
:instance_id => id,
:priority => MiqQueue::HIGH_PRIORITY,
:args => [],
:args => [log_type],
:zone => conversion_host.resource.my_zone}
MiqTask.generic_action_with_callback(options, queue_options)
end
Expand Down
11 changes: 8 additions & 3 deletions spec/models/service_template_transformation_plan_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
end
end

it 'raises when log type is invalid' do
msg = "Transformation log type 'invalid' not supported"
expect { task.transformation_log_queue('user', 'invalid') }.to raise_error(msg)
end

it 'gets the transformation log from conversion host' do
expect(task).to receive(:transformation_log).and_return('transformation migration log content')
taskid = task.transformation_log_queue('user')
Expand All @@ -142,7 +147,7 @@
it 'returns an error message' do
taskid = task.transformation_log_queue('user')
expect(MiqTask.find(taskid)).to have_attributes(
:message => "Conversion host was not found. Cannot queue the download of transformation log.",
:message => "Conversion host was not found. Cannot queue the download of v2v log.",
:status => 'Error'
)
end
Expand All @@ -158,13 +163,13 @@

it 'requires transformation log location in options' do
task.options.store_path(:virtv2v_wrapper, "v2v_log", "")
expect { task.transformation_log }.to raise_error(MiqException::Error)
expect { task.transformation_log("v2v") }.to raise_error(MiqException::Error)
end

it 'gets the transformation log content' do
msg = 'my transformation migration log'
allow(conversion_host).to receive(:get_conversion_log).with(task.options[:virtv2v_wrapper]['v2v_log']).and_return(msg)
expect(task.transformation_log).to eq(msg)
expect(task.transformation_log("v2v")).to eq(msg)
end
end

Expand Down

0 comments on commit 10259fb

Please sign in to comment.