Commit fcf88559 by Bach Dániel

Merge branch 'migrate-fixes' into 'master'

migrate fixes

🆗 tests
🆗 #156
🆗 #155
parents a0a784e7 8316409d
......@@ -202,6 +202,10 @@ class MigrateOperation(InstanceOperation):
name = _("migrate")
description = _("Live migrate running VM to another node.")
def rollback(self, activity):
with activity.sub_activity('rollback_net'):
self.instance.deploy_net()
def _operation(self, activity, to_node=None, timeout=120):
if not to_node:
with activity.sub_activity('scheduling') as sa:
......@@ -212,8 +216,13 @@ class MigrateOperation(InstanceOperation):
with activity.sub_activity('shutdown_net'):
self.instance.shutdown_net()
try:
with activity.sub_activity('migrate_vm'):
self.instance.migrate_vm(to_node=to_node, timeout=timeout)
except Exception as e:
if hasattr(e, 'libvirtError'):
self.rollback(activity)
raise
# Refresh node information
self.instance.node = to_node
......
......@@ -129,6 +129,25 @@ class InstanceTestCase(TestCase):
migr.apply_async.assert_called()
self.assertNotIn(call.sub_activity(u'scheduling'), act.mock_calls)
def test_migrate_with_error(self):
inst = Mock(destroyed_at=None, spec=Instance)
inst.interface_set.all.return_value = []
inst.node = MagicMock(spec=Node)
e = Exception('abc')
setattr(e, 'libvirtError', '')
inst.migrate_vm.side_effect = e
migrate_op = MigrateOperation(inst)
with patch('vm.models.instance.vm_tasks.migrate') as migr:
act = MagicMock()
with patch.object(MigrateOperation, 'create_activity',
return_value=act):
self.assertRaises(Exception, migrate_op, system=True)
migr.apply_async.assert_called()
self.assertIn(call.sub_activity(u'scheduling'), act.mock_calls)
self.assertIn(call.sub_activity(u'rollback_net'), act.mock_calls)
inst.select_node.assert_called()
def test_status_icon(self):
inst = MagicMock(spec=Instance)
inst.status = 'dummy-value'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment