Merge "Prevent (un)pinning unknown CPUs"

This commit is contained in:
Jenkins 2015-08-11 15:17:19 +00:00 committed by Gerrit Code Review
commit 26fcd5d7c4
4 changed files with 17 additions and 4 deletions

View File

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

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

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