Prevent (un)pinning unknown CPUs
There's already a check to ensure pinned CPUs are unpinned and vice versa, but none to ensure the CPUs are in the known set. Add one. Closes-Bug: #1483613 Change-Id: Ie3c55912fbbd0e2e7b6dd48ca3c110c2d92fc987
This commit is contained in:
parent
183cd88cb2
commit
bcb3d54635
@ -1836,6 +1836,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]))
|
||||
|
@ -1536,10 +1536,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