From a51d60f2ba557926f982d7f6c735ed12e5deb5e9 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 5 Nov 2012 11:01:14 -0800 Subject: Move host aggregate operations to VirtAPI This patch moves the following virt driver host aggregate operations to the VirtAPI: aggregate_get_by_host() aggregate_metadata_get() aggregate_metadata_add() aggregate_metadata_delete() In the process, a bug was found in the xenapi/host.py code that raises an AggregateHostNotFound error in such a way that a KeyError is generated. This changes that behavior to raise a NotFound instead, since the former expects you to already know the aggregate_id, which we do not. This patch extends the XenAPI host_maintenance_mode test to exercise this error path, as well as the one where a host is not found within the returned aggregate. Related to bp/no-db-compute Change-Id: I006665bfb27774d2eeb713b79c188ca53f6fb00b --- nova/tests/test_xenapi.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 54f7948b6..30887b33b 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -898,7 +898,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): self.assertRaises(xenapi_fake.Failure, conn.reboot, instance, None, "SOFT") - def test_maintenance_mode(self): + def _test_maintenance_mode(self, find_host, find_aggregate): real_call_xenapi = self.conn._session.call_xenapi instance = self._create_instance(spawn=True) api_calls = {} @@ -912,9 +912,19 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): 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_aggregate_get(context, host, key): + if find_aggregate: + return [{'fake': 'aggregate'}] + else: + return [] + self.stubs.Set(self.conn.virtapi, 'aggregate_get_by_host', + fake_aggregate_get) + def fake_host_find(context, session, src, dst): - return 'bar' + if find_host: + return 'bar' + else: + raise exception.NoValidHost("I saw this one coming...") self.stubs.Set(host, '_host_find', fake_host_find) result = self.conn.host_maintenance_mode('bar', 'on_maintenance') @@ -929,6 +939,17 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): self.assertTrue(instance['vm_state'], vm_states.ACTIVE) self.assertTrue(instance['task_state'], task_states.MIGRATING) + def test_maintenance_mode(self): + self._test_maintenance_mode(True, True) + + def test_maintenance_mode_no_host(self): + self.assertRaises(exception.NoValidHost, + self._test_maintenance_mode, False, True) + + def test_maintenance_mode_no_aggregate(self): + self.assertRaises(exception.NotFound, + self._test_maintenance_mode, True, False) + def _create_instance(self, instance_id=1, spawn=True): """Creates and spawns a test instance.""" instance_values = { -- cgit