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
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user