From 021202e80da7ce587a4d36c464c7b6835e5bface Mon Sep 17 00:00:00 2001 From: Boden R Date: Tue, 23 Sep 2014 12:55:54 -0400 Subject: [PATCH] Return vcpu pin set as set rather than list The current implementation of the libvirt driver makes mixed assumptions about the vcpu pin set returned from hardware.get_vcpu_pin_set(). Most places in the code assume its a set and perform set operations on the structure. However a few places assume it's a list. Given the mixed assumptions about the structure type, the existing code was trying to perform set operations on a list. This patch changes the get_vcpu_pin_set() method to return a set rather than a list and handles any edge cases where consumers need a list. It also updates any relevant unit tests accordingly. Change-Id: I66d5cbc0e2d370d9d2d2ab2bad2c5b348bedba6c Closes-Bug: 1372829 --- nova/tests/virt/test_hardware.py | 2 +- nova/virt/hardware.py | 4 ++-- nova/virt/libvirt/driver.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nova/tests/virt/test_hardware.py b/nova/tests/virt/test_hardware.py index 1295af9083eb..8767a8b1637f 100644 --- a/nova/tests/virt/test_hardware.py +++ b/nova/tests/virt/test_hardware.py @@ -57,7 +57,7 @@ class CpuSetTestCase(test.NoDBTestCase): def test_get_vcpu_pin_set(self): self.flags(vcpu_pin_set="1-3,5,^2") cpuset_ids = hw.get_vcpu_pin_set() - self.assertEqual([1, 3, 5], cpuset_ids) + self.assertEqual(set([1, 3, 5]), cpuset_ids) def test_parse_cpu_spec_none_returns_none(self): self.flags(vcpu_pin_set=None) diff --git a/nova/virt/hardware.py b/nova/virt/hardware.py index 273455186c9a..8f2b24f17977 100644 --- a/nova/virt/hardware.py +++ b/nova/virt/hardware.py @@ -39,7 +39,7 @@ LOG = logging.getLogger(__name__) def get_vcpu_pin_set(): """Parsing vcpu_pin_set config. - Returns a list of pcpu ids can be used by instances. + Returns a set of pcpu ids can be used by instances. """ if not CONF.vcpu_pin_set: return None @@ -48,7 +48,7 @@ def get_vcpu_pin_set(): if not cpuset_ids: raise exception.Invalid(_("No CPUs available after parsing %r") % CONF.vcpu_pin_set) - return sorted(cpuset_ids) + return cpuset_ids def parse_cpu_spec(spec): diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index e9212b6eaa44..8e49b189c36f 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -4538,7 +4538,7 @@ class LibvirtDriver(driver.ComputeDriver): return self._vcpu_total available_ids = hardware.get_vcpu_pin_set() - if available_ids[-1] >= total_pcpus: + if 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)