Add check for no domains in libvirt driver.

A check is needed to see if there are any domains before calling
the listDomainsID() method. This check is needed to add support
for OpenVZ which will throw an exception from this method if there
are no domains. The 'virsh' source code does this check, too.

This change circumvents this libvirt bug:
   https://bugzilla.redhat.com/show_bug.cgi?id=836647

Change-Id: Ia71d996722a1b531e720e91c1fa68f561ad4d58d
This commit is contained in:
David Shrewsbury
2012-06-29 12:18:50 -04:00
parent b40088e0b7
commit 8768e33263
2 changed files with 6 additions and 0 deletions

View File

@@ -478,6 +478,9 @@ class Connection(object):
node_cores,
node_threads]
def numOfDomains(self):
return len(self._running_vms)
def listDomainsID(self):
return self._running_vms.keys()

View File

@@ -759,6 +759,7 @@ class LibvirtConnTestCase(test.TestCase):
def test_list_instances(self):
self.mox.StubOutWithMock(libvirt_driver.LibvirtDriver, '_conn')
libvirt_driver.LibvirtDriver._conn.lookupByID = self.fake_lookup
libvirt_driver.LibvirtDriver._conn.numOfDomains = lambda: 2
libvirt_driver.LibvirtDriver._conn.listDomainsID = lambda: [0, 1]
self.mox.ReplayAll()
@@ -810,6 +811,7 @@ class LibvirtConnTestCase(test.TestCase):
return FakeVirtDomain(xml[id])
self.mox.StubOutWithMock(libvirt_driver.LibvirtDriver, '_conn')
libvirt_driver.LibvirtDriver._conn.numOfDomains = lambda: 4
libvirt_driver.LibvirtDriver._conn.listDomainsID = lambda: range(4)
libvirt_driver.LibvirtDriver._conn.lookupByID = fake_lookup
@@ -869,6 +871,7 @@ class LibvirtConnTestCase(test.TestCase):
return FakeVirtDomain(xml[1])
self.mox.StubOutWithMock(libvirt_driver.LibvirtDriver, '_conn')
libvirt_driver.LibvirtDriver._conn.numOfDomains = lambda: 4
libvirt_driver.LibvirtDriver._conn.listDomainsID = lambda: range(4)
libvirt_driver.LibvirtDriver._conn.lookupByID = fake_lookup
libvirt_driver.LibvirtDriver._conn.lookupByName = fake_lookup_name