Merge "libvirt: Do not cache number of CPUs of the hypervisor"

This commit is contained in:
Jenkins 2015-06-04 11:28:59 +00:00 committed by Gerrit Code Review
commit 9fc5c05632
2 changed files with 14 additions and 8 deletions

View File

@ -4493,6 +4493,18 @@ class LibvirtConnTestCase(test.NoDBTestCase):
vcpus = drvr._get_vcpu_total()
self.assertEqual(expected_vcpus, vcpus)
@mock.patch('nova.virt.libvirt.host.Host.get_cpu_count')
def test_get_host_vcpus_after_hotplug(self, get_cpu_count):
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
get_cpu_count.return_value = 2
expected_vcpus = 2
vcpus = drvr._get_vcpu_total()
self.assertEqual(expected_vcpus, vcpus)
get_cpu_count.return_value = 3
expected_vcpus = 3
vcpus = drvr._get_vcpu_total()
self.assertEqual(expected_vcpus, vcpus)
@mock.patch.object(host.Host, "has_min_version", return_value=True)
def test_quiesce(self, mock_has_min_version):
self.create_fake_libvirt_mock(lookupByName=self.fake_lookup)

View File

@ -403,7 +403,6 @@ class LibvirtDriver(driver.ComputeDriver):
self._fc_wwnns = None
self._fc_wwpns = None
self._caps = None
self._vcpu_total = 0
self.firewall_driver = firewall.load_driver(
DEFAULT_FIREWALL_DRIVER,
self.virtapi,
@ -4497,9 +4496,6 @@ class LibvirtDriver(driver.ComputeDriver):
:returns: the number of cpu core instances can be used.
"""
if self._vcpu_total != 0:
return self._vcpu_total
try:
total_pcpus = self._host.get_cpu_count()
except libvirt.libvirtError:
@ -4508,8 +4504,7 @@ class LibvirtDriver(driver.ComputeDriver):
return 0
if CONF.vcpu_pin_set is None:
self._vcpu_total = total_pcpus
return self._vcpu_total
return total_pcpus
available_ids = hardware.get_vcpu_pin_set()
# We get the list of online CPUs on the host and see if the requested
@ -4533,8 +4528,7 @@ class LibvirtDriver(driver.ComputeDriver):
elif sorted(available_ids)[-1] >= total_pcpus:
raise exception.Invalid(_("Invalid vcpu_pin_set config, "
"out of hypervisor cpu range."))
self._vcpu_total = len(available_ids)
return self._vcpu_total
return len(available_ids)
@staticmethod
def _get_local_gb_info():