Skip to content

Commit

Permalink
Merge pull request ManageIQ#16705 from bzwei/migrate_with_error
Browse files Browse the repository at this point in the history
Rescue migration error and update status
(cherry picked from commit 805e023)

https://bugzilla.redhat.com/show_bug.cgi?id=1478518
  • Loading branch information
gmcculloug authored and d-m-u committed Jun 6, 2018
1 parent 82b843c commit 67dee1e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/models/vm_migrate_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,16 @@ def do_request
end

_log.warn "Calling VM #{vc_method} for #{vm.id}:#{vm.name}"
if vc_method == :migrate
vm.migrate(host, respool)
else
vm.relocate(host, respool, datastore, nil, disk_transform)

begin
if vc_method == :migrate
vm.migrate(host, respool)
else
vm.relocate(host, respool, datastore, nil, disk_transform)
end
rescue => err
update_and_notify_parent(:state => 'finished', :status => 'error', :message => "Failed. Reason[#{err.message}]")
return
end

if AUTOMATE_DRIVES
Expand Down
18 changes: 18 additions & 0 deletions spec/models/vm_migrate_task_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
describe VmMigrateTask do
describe '.do_request' do
let(:vm) { Vm.new }
before { subject.vm = vm }

it 'migrates the vm and updates the status' do
expect(vm).to receive(:migrate)
expect(subject).to receive(:update_and_notify_parent).with(hash_including(:state => 'migrated'))
subject.do_request
end

it 'catches migrate error and update the status' do
expect(vm).to receive(:migrate).and_raise("Bad things happened")
expect(subject).to receive(:update_and_notify_parent).with(hash_including(:state => 'finished', :status => 'error', :message => 'Failed. Reason[Bad things happened]'))
subject.do_request
end
end
end

0 comments on commit 67dee1e

Please sign in to comment.