diff --git a/app/models/service_template_transformation_plan_task.rb b/app/models/service_template_transformation_plan_task.rb index bd1328102e7..3d7d55d59a5 100644 --- a/app/models/service_template_transformation_plan_task.rb +++ b/app/models/service_template_transformation_plan_task.rb @@ -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) diff --git a/spec/models/service_template_transformation_plan_task_spec.rb b/spec/models/service_template_transformation_plan_task_spec.rb index 83180c58f31..aec0985353c 100644 --- a/spec/models/service_template_transformation_plan_task_spec.rb +++ b/spec/models/service_template_transformation_plan_task_spec.rb @@ -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, @@ -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')