Merge "Remove mox from tests/unit/compute/test_compute_xen.py"
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
"""Tests for expectations of behaviour from the Xen driver."""
|
"""Tests for expectations of behaviour from the Xen driver."""
|
||||||
|
|
||||||
|
import mock
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
|
|
||||||
from nova.compute import power_state
|
from nova.compute import power_state
|
||||||
@@ -47,20 +48,27 @@ class ComputeXenTestCase(stubs.XenAPITestBaseNoDB):
|
|||||||
objects.InstanceList(), [db_instance], None)
|
objects.InstanceList(), [db_instance], None)
|
||||||
instance = instance_list[0]
|
instance = instance_list[0]
|
||||||
|
|
||||||
self.mox.StubOutWithMock(objects.InstanceList, 'get_by_host')
|
@mock.patch.object(vm_utils, 'lookup')
|
||||||
self.mox.StubOutWithMock(self.compute.driver, 'get_num_instances')
|
@mock.patch.object(objects.InstanceList, 'get_by_host')
|
||||||
self.mox.StubOutWithMock(vm_utils, 'lookup')
|
@mock.patch.object(self.compute.driver, 'get_num_instances')
|
||||||
self.mox.StubOutWithMock(self.compute, '_sync_instance_power_state')
|
@mock.patch.object(self.compute, '_sync_instance_power_state')
|
||||||
|
def do_test(mock_compute_sync_powerstate,
|
||||||
|
mock_compute_get_num_instances,
|
||||||
|
mock_instance_list_get_by_host,
|
||||||
|
mock_vm_utils_lookup):
|
||||||
|
mock_instance_list_get_by_host.return_value = instance_list
|
||||||
|
mock_compute_get_num_instances.return_value = 1
|
||||||
|
mock_vm_utils_lookup.return_value = None
|
||||||
|
|
||||||
objects.InstanceList.get_by_host(ctxt,
|
self.compute._sync_power_states(ctxt)
|
||||||
self.compute.host, expected_attrs=[],
|
|
||||||
use_slave=True).AndReturn(instance_list)
|
|
||||||
self.compute.driver.get_num_instances().AndReturn(1)
|
|
||||||
vm_utils.lookup(self.compute.driver._session, instance['name'],
|
|
||||||
False).AndReturn(None)
|
|
||||||
self.compute._sync_instance_power_state(ctxt, instance,
|
|
||||||
power_state.NOSTATE)
|
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
mock_instance_list_get_by_host.assert_called_once_with(
|
||||||
|
ctxt, self.compute.host, expected_attrs=[], use_slave=True)
|
||||||
|
mock_compute_get_num_instances.assert_called_once_with()
|
||||||
|
mock_compute_sync_powerstate.assert_called_once_with(
|
||||||
|
ctxt, instance, power_state.NOSTATE, use_slave=True)
|
||||||
|
mock_vm_utils_lookup.assert_called_once_with(
|
||||||
|
self.compute.driver._session, instance['name'],
|
||||||
|
False)
|
||||||
|
|
||||||
self.compute._sync_power_states(ctxt)
|
do_test()
|
||||||
|
|||||||
Reference in New Issue
Block a user