diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-11-05 22:07:58 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-11-05 22:07:58 +0000 |
| commit | 33c4e6bd0b735d2dfb7ca032fcd834639e23cb2e (patch) | |
| tree | 16d7bc2ed8a1d9a035635ace870ab66fb7574588 /nova | |
| parent | 880b491838856581a8d4ff69b4dbc17d778e7fba (diff) | |
| parent | e1ef0e69d2a146fb55a0e2b85c223a5a0973f8bc (diff) | |
| download | nova-33c4e6bd0b735d2dfb7ca032fcd834639e23cb2e.tar.gz nova-33c4e6bd0b735d2dfb7ca032fcd834639e23cb2e.tar.xz nova-33c4e6bd0b735d2dfb7ca032fcd834639e23cb2e.zip | |
Merge "Add xenapi host_maintenance_mode() test"
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/tests/test_xenapi.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 404c183a0..88e981bad 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -27,6 +27,8 @@ import re from nova.compute import api as compute_api from nova.compute import instance_types from nova.compute import power_state +from nova.compute import task_states +from nova.compute import vm_states from nova import context from nova import db from nova import exception @@ -896,6 +898,37 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): self.assertRaises(xenapi_fake.Failure, conn.reboot, instance, None, "SOFT") + def test_maintenance_mode(self): + real_call_xenapi = self.conn._session.call_xenapi + instance = self._create_instance(spawn=True) + api_calls = {} + + # Record all the xenapi calls, and return a fake list of hosts + # for the host.get_all call + def fake_call_xenapi(method, *args): + api_calls[method] = args + if method == 'host.get_all': + return ['foo', 'bar', 'baz'] + return real_call_xenapi(method, *args) + self.stubs.Set(self.conn._session, 'call_xenapi', fake_call_xenapi) + + # Always find the 'bar' destination host + def fake_host_find(context, session, src, dst): + return 'bar' + self.stubs.Set(host, '_host_find', fake_host_find) + + result = self.conn.host_maintenance_mode('bar', 'on_maintenance') + self.assertEqual(result, 'on_maintenance') + + # We expect the VM.pool_migrate call to have been called to + # migrate our instance to the 'bar' host + expected = (instance['uuid'], 'bar', {}) + self.assertTrue(api_calls.get('VM.pool_migrate'), expected) + + instance = db.instance_get_by_uuid(self.context, instance['uuid']) + self.assertTrue(instance['vm_state'], vm_states.ACTIVE) + self.assertTrue(instance['task_state'], task_states.MIGRATING) + def _create_instance(self, instance_id=1, spawn=True): """Creates and spawns a test instance.""" instance_values = { |
