From e1ef0e69d2a146fb55a0e2b85c223a5a0973f8bc Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 1 Nov 2012 10:32:17 -0700 Subject: Add xenapi host_maintenance_mode() test This bit of code is currently untested (except for the most basic stubbed-out case). Change-Id: I7193152480ed678c89be7b7dda5edf034f5dad2e --- nova/tests/test_xenapi.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index bd1bcd4f1..b4295b49d 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 @@ -895,6 +897,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 = { -- cgit