Commit a89d41d2 by Őry Máté

vm: fix tests

parent b0e7d502
......@@ -29,7 +29,8 @@ from ..models import (
)
from ..models.instance import find_unused_port, ActivityInProgressError
from ..operations import (
DeployOperation, DestroyOperation, FlushOperation, MigrateOperation,
RemoteOperationMixin, DeployOperation, DestroyOperation, FlushOperation,
MigrateOperation,
)
......@@ -105,7 +106,8 @@ class InstanceTestCase(TestCase):
inst.node = MagicMock(spec=Node)
inst.status = 'RUNNING'
migrate_op = MigrateOperation(inst)
with patch('vm.models.instance.vm_tasks.migrate') as migr:
with patch('vm.operations.vm_tasks.migrate') as migr, \
patch.object(RemoteOperationMixin, "_operation"):
act = MagicMock()
with patch.object(MigrateOperation, 'create_activity',
return_value=act):
......@@ -122,7 +124,8 @@ class InstanceTestCase(TestCase):
inst.node = MagicMock(spec=Node)
inst.status = 'RUNNING'
migrate_op = MigrateOperation(inst)
with patch('vm.models.instance.vm_tasks.migrate') as migr:
with patch('vm.operations.vm_tasks.migrate') as migr, \
patch.object(RemoteOperationMixin, "_operation"):
inst.select_node.side_effect = AssertionError
act = MagicMock()
with patch.object(MigrateOperation, 'create_activity',
......@@ -139,20 +142,21 @@ class InstanceTestCase(TestCase):
inst.status = 'RUNNING'
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:
migrate_op.rollback = Mock()
with patch('vm.operations.vm_tasks.migrate') as migr, \
patch.object(RemoteOperationMixin, '_operation') as remop:
act = MagicMock()
remop.side_effect = e
with patch.object(MigrateOperation, 'create_activity',
return_value=act):
self.assertRaises(Exception, migrate_op, system=True)
remop.assert_called()
migr.apply_async.assert_called()
self.assertIn(call.sub_activity(
u'scheduling', readable_name=u'schedule'), act.mock_calls)
self.assertIn(call.sub_activity(
u'rollback_net', readable_name=u'redeploy network (rollback)'),
act.mock_calls)
migrate_op.rollback.assert_called()
inst.select_node.assert_called()
def test_status_icon(self):
......
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