Skip to content

Commit

Permalink
Merge pull request #479 from fdupont-redhat/v2v_allow_retries_on_tran…
Browse files Browse the repository at this point in the history
…sformation_check

[V2V] Allow a retry to let virt-v2v start
  • Loading branch information
mkanoor committed Dec 4, 2018
2 parents fe08129 + 27bfa74 commit 7e6c26d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ def main
@handle.set_state_var(:ae_state_progress, 'message' => 'Disks transformation succeeded.', 'percent' => 100)
end
rescue => e
@handle.set_state_var(:ae_state_progress, 'message' => e.message)
raise
if @handle.root['ae_state_retries'] > 1
@handle.set_state_var(:ae_state_progress, 'message' => e.message)
raise
else
set_retry
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
allow(svc_model_task).to receive(:get_option).with(:virtv2v_status).and_return('active')
described_class.new(ae_service).main
expect(ae_service.get_state_var(:ae_state_progress)).to eq('message' => 'Disks transformation is initializing.', 'percent' => 1.0)
expect(ae_service.root['ae_result']).to eq('retry')
end
end

Expand All @@ -63,11 +64,13 @@
allow(svc_model_task).to receive(:get_option).with(:virtv2v_status).and_return('active')
described_class.new(ae_service).main
expect(ae_service.get_state_var(:ae_state_progress)).to eq('message' => 'Converting disk 2 / 2 [43.75%].', 'percent' => 43.75)
expect(ae_service.root['ae_result']).to eq('retry')
end
end

context "conversion has failed" do
it "raises with a message stating conversion has failed" do
ae_service.root['ae_state_retries'] = 2
allow(svc_model_task).to receive(:get_conversion_state).and_return(true)
allow(svc_model_task).to receive(:get_option).with(:virtv2v_status).and_return('failed')
errormsg = 'Disks transformation failed.'
Expand All @@ -85,11 +88,22 @@
end
end

it "raises if get_conversion_state fails" do
errormsg = 'Unexpected error'
allow(svc_model_task).to receive(:get_conversion_state).and_raise(errormsg)
expect { described_class.new(ae_service).main }.to raise_error(errormsg)
expect(ae_service.get_state_var(:ae_state_progress)).to eq('message' => errormsg)
context "get_conversion_state fails" do
it "sets retry if ae_state_retries is less than or equal to 1" do
errormsg = 'Unexpected error'
allow(svc_model_task).to receive(:get_conversion_state).and_raise(errormsg)
ae_service.root['ae_state_retries'] = 1
described_class.new(ae_service).main
expect(ae_service.root['ae_result']).to eq('retry')
end

it "raises if ae_state_retries is greater than 2" do
errormsg = 'Unexpected error'
allow(svc_model_task).to receive(:get_conversion_state).and_raise(errormsg)
ae_service.root['ae_state_retries'] = 2
expect { described_class.new(ae_service).main }.to raise_error(errormsg)
expect(ae_service.get_state_var(:ae_state_progress)).to eq('message' => errormsg)
end
end
end
end

0 comments on commit 7e6c26d

Please sign in to comment.