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:
Alexis Lee 2015-07-29 14:26:43 +01:00 committed by Alexis Lee
parent 183cd88cb2
commit bcb3d54635
4 changed files with 17 additions and 4 deletions

View File

@ -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")

View File

@ -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))

View File

@ -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]))

View File

@ -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')