diff options
-rw-r--r-- | nova/tests/virt/xenapi/test_xenapi.py | 14 | ||||
-rw-r--r-- | nova/virt/xenapi/host.py | 9 |
2 files changed, 19 insertions, 4 deletions
diff --git a/nova/tests/virt/xenapi/test_xenapi.py b/nova/tests/virt/xenapi/test_xenapi.py index bc166655d..cb81583e5 100644 --- a/nova/tests/virt/xenapi/test_xenapi.py +++ b/nova/tests/virt/xenapi/test_xenapi.py @@ -38,6 +38,7 @@ from nova.openstack.common import jsonutils from nova.openstack.common import log as logging from nova import test from nova.tests.db import fakes as db_fakes +from nova.tests import fake_instance from nova.tests import fake_network from nova.tests import fake_processutils import nova.tests.image.fake as fake_image @@ -1173,6 +1174,19 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): self.assertRaises(exception.NotFound, self._test_maintenance_mode, True, False) + def test_uuid_find(self): + self.mox.StubOutWithMock(db, 'instance_get_all_by_host') + fake_inst = fake_instance.fake_db_instance(id=123) + fake_inst2 = fake_instance.fake_db_instance(id=456) + db.instance_get_all_by_host(self.context, fake_inst['host'], + columns_to_join=None + ).AndReturn([fake_inst, fake_inst2]) + self.mox.ReplayAll() + expected_name = CONF.instance_name_template % fake_inst['id'] + inst_uuid = host._uuid_find(self.context, fake_inst['host'], + expected_name) + self.assertEqual(inst_uuid, fake_inst['uuid']) + def test_session_virtapi(self): was = {'called': False} diff --git a/nova/virt/xenapi/host.py b/nova/virt/xenapi/host.py index 258e4d145..5fa2b55db 100644 --- a/nova/virt/xenapi/host.py +++ b/nova/virt/xenapi/host.py @@ -23,6 +23,7 @@ from nova.compute import task_states from nova.compute import vm_states from nova import context from nova import exception +from nova.objects import instance as instance_obj from nova.openstack.common import jsonutils from nova.openstack.common import log as logging from nova.virt.xenapi import pool_states @@ -63,7 +64,7 @@ class Host(object): uuid = vm_rec['other_config'].get('nova_uuid') if not uuid: name = vm_rec['name_label'] - uuid = _uuid_find(self._virtapi, ctxt, host, name) + uuid = _uuid_find(ctxt, host, name) if not uuid: msg = _('Instance %(name)s running on %(host)s' ' could not be found in the database:' @@ -207,11 +208,11 @@ def call_xenhost(session, method, arg_dict): return e.details[1] -def _uuid_find(virtapi, context, host, name_label): +def _uuid_find(context, host, name_label): """Return instance uuid by name_label.""" - for i in virtapi.instance_get_all_by_host(context, host): + for i in instance_obj.InstanceList.get_by_host(context, host): if i.name == name_label: - return i['uuid'] + return i.uuid return None |