summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-03-25 17:36:36 +0000
committerGerrit Code Review <review@openstack.org>2013-03-25 17:36:36 +0000
commit2b8bd97325d304e230daedd1e9636869f82272a8 (patch)
tree5e988a147bae6c74002d99b215cb8536f6baf279 /nova
parent58cc26c4dc6af8d10e623fb915f4c6232bc07cd7 (diff)
parent90cda3512ae509d548bf2b4343ce0d8b8b9bfb43 (diff)
downloadnova-2b8bd97325d304e230daedd1e9636869f82272a8.tar.gz
nova-2b8bd97325d304e230daedd1e9636869f82272a8.tar.xz
nova-2b8bd97325d304e230daedd1e9636869f82272a8.zip
Merge "xenapi: Retrieve VM uuid from xenstore."
Diffstat (limited to 'nova')
-rw-r--r--nova/tests/virt/xenapi/test_vm_utils.py30
-rw-r--r--nova/virt/xenapi/vm_utils.py16
2 files changed, 45 insertions, 1 deletions
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()
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index 26bd9d268..99e7712c8 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -1918,11 +1918,25 @@ def vdi_attached_here(session, vdi_ref, read_only=False):
LOG.debug(_('Destroying VBD for VDI %s done.'), vdi_ref)
-def get_this_vm_uuid():
+def _get_sys_hypervisor_uuid():
with file('/sys/hypervisor/uuid') as f:
return f.readline().strip()
+def get_this_vm_uuid():
+ try:
+ return _get_sys_hypervisor_uuid()
+ except IOError:
+ # Some guest kernels (without 5c13f8067745efc15f6ad0158b58d57c44104c25)
+ # cannot read from uuid after a reboot. Fall back to trying xenstore.
+ # See https://bugs.launchpad.net/ubuntu/+source/xen-api/+bug/1081182
+ domid, _ = utils.execute('xenstore-read', 'domid', run_as_root=True)
+ vm_key, _ = utils.execute('xenstore-read',
+ '/local/domain/%s/vm' % domid.strip(),
+ run_as_root=True)
+ return vm_key.strip()[4:]
+
+
def _get_this_vm_ref(session):
return session.call_xenapi("VM.get_by_uuid", get_this_vm_uuid())