Skip to content

Commit

Permalink
Merge pull request #19782 from fdupont-redhat/v2v_allow_failure_to_ge…
Browse files Browse the repository at this point in the history
…t_conversion_state

[V2V] Allow get_conversion_state to fail
  • Loading branch information
chessbyte authored Jan 30, 2020
2 parents 23d7b1f + b5bd488 commit f9bd524
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/models/service_template_transformation_plan_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,17 @@ def get_conversion_state
updates[:virtv2v_finished_on] = Time.now.utc.strftime('%Y-%m-%d %H:%M:%S')
if virtv2v_state['failed']
updates[:virtv2v_status] = 'failed'
raise "Disks transformation failed."
else
updates[:virtv2v_status] = 'succeeded'
updated_disks.each { |d| d[:percent] = 100 }
end
end
updates[:virtv2v_disks] = updated_disks
update_options(:get_conversion_state_failures => 0)
rescue
failures = options[:get_conversion_state_failures] || 0
update_options(:get_conversion_state_failures => failures + 1)
raise "Failed to get conversion state 5 times in a row" if options[:get_conversion_state_failures] > 5
ensure
_log.info("InfraConversionJob get_conversion_state to update_options: #{updates}")
update_options(updates)
Expand Down
18 changes: 16 additions & 2 deletions spec/models/service_template_transformation_plan_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,21 @@
allow(Time).to receive(:now).and_return(time_now)
end

it "raises when conversion is failed" do
it "rescues when conversion_host.get_conversion_state fails less than 5 times" do
task_1.update_options(:get_conversion_state_failures => 2)
allow(conversion_host).to receive(:get_conversion_state).with(task.options[:virtv2v_wrapper]['state_file']).and_raise("Fake error")
task_1.get_conversion_state
expect(task_1.options[:get_conversion_state_failures]).to eq(3)
end

it "rescues when conversion_host.get_conversion_state fails more than 5 times" do
task_1.update_options(:get_conversion_state_failures => 5)
allow(conversion_host).to receive(:get_conversion_state).with(task.options[:virtv2v_wrapper]['state_file']).and_raise("Fake error")
expect { task_1.get_conversion_state }.to raise_error("Fake error")
expect(task_1.options[:get_conversion_state_failures]).to eq(6)
end

it "updates progress when conversion is failed" do
allow(conversion_host).to receive(:get_conversion_state).with(task.options[:virtv2v_wrapper]['state_file']).and_return(
"failed" => true,
"finished" => true,
Expand All @@ -408,7 +422,7 @@
"type" => "error"
}
)
expect { task_1.get_conversion_state }.to raise_error("Disks transformation failed.")
task_1.get_conversion_state
expect(task_1.options[:virtv2v_status]).to eq('failed')
expect(task_1.options[:virtv2v_finished_on]).to eq(time_now.strftime('%Y-%m-%d %H:%M:%S'))
expect(task_1.options[:virtv2v_message]).to eq('virt-v2v failed somehow')
Expand Down

0 comments on commit f9bd524

Please sign in to comment.