Skip to content

Commit

Permalink
Allows xenapi 'lookup' to look for rescue mode VMs
Browse files Browse the repository at this point in the history
When you lookup a VM by name, you can specify if you want it to check if
it has a rescue mode instance running.

If it finds the rescue mode instance, it'll return that one instead
of the original name.

This is useful for operations that should work on the rescue mode vm if
it's there, or the normal one, if it's not.

Work towards bug: 1170237
Change-Id: I41b31e59631b78a62faadb9970b6b824929e7061
  • Loading branch information
matiu2 authored and openstack-gerrit committed Apr 20, 2013
1 parent 4ff5d3d commit 4c887ed
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
27 changes: 27 additions & 0 deletions nova/tests/virt/xenapi/test_vm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,33 @@ def test_too_many(self):
vm_utils.lookup,
self.session, self.name_label)

def test_rescue_none(self):
self.session.call_xenapi(
"VM.get_by_name_label", self.name_label + '-rescue').AndReturn([])
self._do_mock(['x'])
result = vm_utils.lookup(self.session, self.name_label,
check_rescue=True)
self.assertEqual('x', result)

def test_rescue_found(self):
self.session.call_xenapi(
"VM.get_by_name_label",
self.name_label + '-rescue').AndReturn(['y'])
self.mox.ReplayAll()
result = vm_utils.lookup(self.session, self.name_label,
check_rescue=True)
self.assertEqual('y', result)

def test_rescue_too_many(self):
self.session.call_xenapi(
"VM.get_by_name_label",
self.name_label + '-rescue').AndReturn(['a', 'b', 'c'])
self.mox.ReplayAll()
self.assertRaises(exception.InstanceExists,
vm_utils.lookup,
self.session, self.name_label,
check_rescue=True)


class GenerateConfigDriveTestCase(test.TestCase):
def test_no_admin_pass(self):
Expand Down
11 changes: 9 additions & 2 deletions nova/virt/xenapi/vm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,8 +1394,15 @@ def lookup_vm_vdis(session, vm_ref):
return vdi_refs


def lookup(session, name_label):
"""Look the instance up and return it if available."""
def lookup(session, name_label, check_rescue=False):
"""Look the instance up and return it if available.
:param check_rescue: if True will return the 'name'-rescue vm if it
exists, instead of just 'name'
"""
if check_rescue:
result = lookup(session, name_label + '-rescue', False)
if result:
return result
vm_refs = session.call_xenapi("VM.get_by_name_label", name_label)
n = len(vm_refs)
if n == 0:
Expand Down

0 comments on commit 4c887ed

Please sign in to comment.