From 90cda3512ae509d548bf2b4343ce0d8b8b9bfb43 Mon Sep 17 00:00:00 2001 From: Bob Ball Date: Tue, 19 Mar 2013 14:12:29 +0000 Subject: xenapi: Retrieve VM uuid from xenstore. Fall back to retrieving the uuid from xenstore if /sys/hypervisor/uuid isn't accessible. Change-Id: I409079068d3102ff86a71431b29c1ce2e6fe8857 Fixes: bug #1157211 --- nova/tests/virt/xenapi/test_vm_utils.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/virt/xenapi/test_vm_utils.py b/nova/tests/virt/xenapi/test_vm_utils.py index f757a57ad..d42ed7629 100644 --- a/nova/tests/virt/xenapi/test_vm_utils.py +++ b/nova/tests/virt/xenapi/test_vm_utils.py @@ -85,3 +85,33 @@ class GenerateConfigDriveTestCase(test.TestCase): # And the actual call we're testing vm_utils.generate_configdrive('session', instance, 'vm_ref', 'userdevice') + + +class XenAPIGetUUID(test.TestCase): + def test_get_this_vm_uuid_new_kernel(self): + self.mox.StubOutWithMock(vm_utils, '_get_sys_hypervisor_uuid') + + vm_utils._get_sys_hypervisor_uuid().AndReturn( + '2f46f0f5-f14c-ef1b-1fac-9eeca0888a3f') + + self.mox.ReplayAll() + self.assertEquals('2f46f0f5-f14c-ef1b-1fac-9eeca0888a3f', + vm_utils.get_this_vm_uuid()) + self.mox.VerifyAll() + + def test_get_this_vm_uuid_old_kernel_reboot(self): + self.mox.StubOutWithMock(vm_utils, '_get_sys_hypervisor_uuid') + self.mox.StubOutWithMock(utils, 'execute') + + vm_utils._get_sys_hypervisor_uuid().AndRaise( + IOError(13, 'Permission denied')) + utils.execute('xenstore-read', 'domid', run_as_root=True).AndReturn( + ('27', '')) + utils.execute('xenstore-read', '/local/domain/27/vm', + run_as_root=True).AndReturn( + ('/vm/2f46f0f5-f14c-ef1b-1fac-9eeca0888a3f', '')) + + self.mox.ReplayAll() + self.assertEquals('2f46f0f5-f14c-ef1b-1fac-9eeca0888a3f', + vm_utils.get_this_vm_uuid()) + self.mox.VerifyAll() -- cgit