Merge "Prevent (un)pinning unknown CPUs"
This commit is contained in:
commit
26fcd5d7c4
@ -1854,6 +1854,11 @@ class CPUPinningInvalid(Invalid):
|
||||
"pinned set %(pinned)s")
|
||||
|
||||
|
||||
class CPUPinningUnknown(Invalid):
|
||||
msg_fmt = _("CPU set to pin/unpin %(requested)s must be a subset of "
|
||||
"known CPU set %(cpuset)s")
|
||||
|
||||
|
||||
class ImageCPUPinningForbidden(Forbidden):
|
||||
msg_fmt = _("Image property 'hw_cpu_policy' is not permitted to override "
|
||||
"CPU pinning policy set against the flavor")
|
||||
|
@ -82,12 +82,18 @@ class NUMACell(base.NovaObject,
|
||||
return self.memory - self.memory_usage
|
||||
|
||||
def pin_cpus(self, cpus):
|
||||
if cpus - self.cpuset:
|
||||
raise exception.CPUPinningUnknown(requested=list(cpus),
|
||||
cpuset=list(self.pinned_cpus))
|
||||
if self.pinned_cpus & cpus:
|
||||
raise exception.CPUPinningInvalid(requested=list(cpus),
|
||||
pinned=list(self.pinned_cpus))
|
||||
self.pinned_cpus |= cpus
|
||||
|
||||
def unpin_cpus(self, cpus):
|
||||
if cpus - self.cpuset:
|
||||
raise exception.CPUPinningUnknown(requested=list(cpus),
|
||||
cpuset=list(self.pinned_cpus))
|
||||
if (self.pinned_cpus & cpus) != cpus:
|
||||
raise exception.CPUPinningInvalid(requested=list(cpus),
|
||||
pinned=list(self.pinned_cpus))
|
||||
|
@ -89,10 +89,12 @@ class _TestNUMA(object):
|
||||
mempages=[])
|
||||
numacell.pin_cpus(set([2, 3]))
|
||||
self.assertEqual(set([4]), numacell.free_cpus)
|
||||
self.assertRaises(exception.CPUPinningUnknown,
|
||||
numacell.pin_cpus, set([1, 55]))
|
||||
self.assertRaises(exception.CPUPinningInvalid,
|
||||
numacell.pin_cpus, set([1, 4]))
|
||||
self.assertRaises(exception.CPUPinningInvalid,
|
||||
numacell.pin_cpus, set([1, 6]))
|
||||
self.assertRaises(exception.CPUPinningUnknown,
|
||||
numacell.unpin_cpus, set([1, 55]))
|
||||
self.assertRaises(exception.CPUPinningInvalid,
|
||||
numacell.unpin_cpus, set([1, 4]))
|
||||
numacell.unpin_cpus(set([1, 2, 3]))
|
||||
|
@ -1560,10 +1560,10 @@ class HelperMethodsTestCase(test.NoDBTestCase):
|
||||
cells=[
|
||||
objects.InstanceNUMACell(
|
||||
id=0, cpuset=set([0, 1]), memory=256, pagesize=2048,
|
||||
cpu_pinning={1: 3, 0: 4}),
|
||||
cpu_pinning={0: 1, 0: 1}),
|
||||
objects.InstanceNUMACell(
|
||||
id=1, cpuset=set([2]), memory=256, pagesize=2048,
|
||||
cpu_pinning={2: 5}),
|
||||
cpu_pinning={2: 3}),
|
||||
])
|
||||
self.context = context.RequestContext('fake-user',
|
||||
'fake-project')
|
||||
|
Loading…
Reference in New Issue
Block a user