From 51f100fb7f02e29e525fb4c254381e71b92d68fd Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Mon, 18 Mar 2019 17:22:23 +0100 Subject: [PATCH] Expose virt-v2v-wrapper error message in options hash --- ...rvice_template_transformation_plan_task.rb | 1 + ..._template_transformation_plan_task_spec.rb | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/models/service_template_transformation_plan_task.rb b/app/models/service_template_transformation_plan_task.rb index 35e346a0af8..aa5bd26c4a7 100644 --- a/app/models/service_template_transformation_plan_task.rb +++ b/app/models/service_template_transformation_plan_task.rb @@ -209,6 +209,7 @@ def get_conversion_state updates = {} virtv2v_state = conversion_host.get_conversion_state(options[:virtv2v_wrapper]['state_file']) updated_disks = virtv2v_disks + updates[:virtv2v_message] = virtv2v_state['last_message']['message'] if virtv2v_state['last_message'].present? if virtv2v_state['finished'].nil? updated_disks.each do |disk| matching_disks = virtv2v_state['disks'].select { |d| d['path'] == disk[:path] } diff --git a/spec/models/service_template_transformation_plan_task_spec.rb b/spec/models/service_template_transformation_plan_task_spec.rb index 4572d092e4b..1c9da02dab9 100644 --- a/spec/models/service_template_transformation_plan_task_spec.rb +++ b/spec/models/service_template_transformation_plan_task_spec.rb @@ -387,21 +387,26 @@ it "raises 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, - "started" => true, - "disks" => [ + "failed" => true, + "finished" => true, + "started" => true, + "disks" => [ { "path" => src_disk_1.filename, "progress" => 23.0 }, { "path" => src_disk_1.filename, "progress" => 0.0 } ], - "pid" => 5855, - "return_code" => 1, - "disk_count" => 2 + "pid" => 5855, + "return_code" => 1, + "disk_count" => 2, + "last_message" => { + "message" => "virt-v2v failed somehow", + "type" => "error" + } } ) expect { task_1.get_conversion_state }.to raise_error("Disks transformation failed.") expect(task_1.options[:virtv2v_status]).to eq('failed') - epxect(task_1.options[:virtv2v_finished_on]).to eq(time_now.strftime('%Y-%m-%d %H:%M:%S')) + 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') end it "updates disks progress" do @@ -449,6 +454,7 @@ ) expect(task_1.options[:virtv2v_status]).to eq('finished') epxect(task_1.options[:virtv2v_finished_on]).to eq(time) + expect(task_1.options[:virtv2v_message]).to be_nil end end