libvirt: remove hack for dom.vcpus() returning None

Nova long ago added a workaround for a bug in libvirt
python bindings 0.9.x which would return None instead
of raising an exception when querying vCPUs in some
cases:

https://bugs.launchpad.net/nova/+bug/1294509

Nova now requires libvirt >= 1.2.1, so will not ever
hit this problem anymore.

Change-Id: I81b07720cf8c7a178b42a048dbac695b1e3db804
This commit is contained in:
Daniel P. Berrange 2016-11-02 15:37:52 +00:00 committed by Stephen Finucane
parent 199d3d81ee
commit 9c0cb54866
3 changed files with 4 additions and 32 deletions

View File

@ -13421,32 +13421,6 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.assertEqual(5, drvr._get_vcpu_used())
mock_list.assert_called_with(only_guests=True, only_running=True)
@mock.patch.object(host.Host, "list_instance_domains")
def test_failing_vcpu_count_none(self, mock_list):
"""Domain will return zero if the current number of vcpus used
is None. This is in case of VM state starting up or shutting
down. None type returned is counted as zero.
"""
class DiagFakeDomain(object):
def __init__(self):
pass
def vcpus(self):
return None
def ID(self):
return 1
def name(self):
return "instance000001"
mock_list.return_value = [DiagFakeDomain()]
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
self.assertEqual(0, drvr._get_vcpu_used())
mock_list.assert_called_with(only_guests=True, only_running=True)
def test_get_instance_capabilities(self):
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)

View File

@ -5131,8 +5131,7 @@ class LibvirtDriver(driver.ComputeDriver):
for guest in self._host.list_guests():
try:
vcpus = guest.get_vcpus_info()
if vcpus is not None:
total += len(list(vcpus))
total += len(list(vcpus))
except libvirt.libvirtError as e:
LOG.warning(
_LW("couldn't obtain the vcpu count from domain id:"

View File

@ -257,10 +257,9 @@ class Guest(object):
:returns: guest.VCPUInfo
"""
vcpus = self._domain.vcpus()
if vcpus is not None:
for vcpu in vcpus[0]:
yield VCPUInfo(
id=vcpu[0], cpu=vcpu[3], state=vcpu[1], time=vcpu[2])
for vcpu in vcpus[0]:
yield VCPUInfo(
id=vcpu[0], cpu=vcpu[3], state=vcpu[1], time=vcpu[2])
def delete_configuration(self):
"""Undefines a domain from hypervisor."""