diff --git a/nova/exception.py b/nova/exception.py index 234d502b9f6a..3669eacc7a3e 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -1966,12 +1966,22 @@ class CPUPinningNotSupported(Invalid): class CPUPinningInvalid(Invalid): - msg_fmt = _("Cannot pin/unpin cpus %(requested)s from the following " - "pinned set %(pinned)s") + msg_fmt = _("CPU set to pin %(requested)s must be a subset of " + "free CPU set %(free)s") + + +class CPUUnpinningInvalid(Invalid): + msg_fmt = _("CPU set to unpin %(requested)s must be a subset of " + "pinned CPU set %(pinned)s") class CPUPinningUnknown(Invalid): - msg_fmt = _("CPU set to pin/unpin %(requested)s must be a subset of " + msg_fmt = _("CPU set to pin %(requested)s must be a subset of " + "known CPU set %(cpuset)s") + + +class CPUUnpinningUnknown(Invalid): + msg_fmt = _("CPU set to unpin %(requested)s must be a subset of " "known CPU set %(cpuset)s") diff --git a/nova/objects/numa.py b/nova/objects/numa.py index 86ca18faa32d..15703e656522 100644 --- a/nova/objects/numa.py +++ b/nova/objects/numa.py @@ -82,16 +82,17 @@ class NUMACell(base.NovaObject): cpuset=list(self.pinned_cpus)) if self.pinned_cpus & cpus: raise exception.CPUPinningInvalid(requested=list(cpus), - pinned=list(self.pinned_cpus)) + free=list(self.cpuset - + 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)) + raise exception.CPUUnpinningUnknown(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)) + raise exception.CPUUnpinningInvalid(requested=list(cpus), + pinned=list(self.pinned_cpus)) self.pinned_cpus -= cpus def pin_cpus_with_siblings(self, cpus): diff --git a/nova/tests/unit/objects/test_numa.py b/nova/tests/unit/objects/test_numa.py index 61b7f4ec02bf..1e1bf76e7148 100644 --- a/nova/tests/unit/objects/test_numa.py +++ b/nova/tests/unit/objects/test_numa.py @@ -93,9 +93,9 @@ class _TestNUMA(object): numacell.pin_cpus, set([1, 55])) self.assertRaises(exception.CPUPinningInvalid, numacell.pin_cpus, set([1, 4])) - self.assertRaises(exception.CPUPinningUnknown, + self.assertRaises(exception.CPUUnpinningUnknown, numacell.unpin_cpus, set([1, 55])) - self.assertRaises(exception.CPUPinningInvalid, + self.assertRaises(exception.CPUUnpinningInvalid, numacell.unpin_cpus, set([1, 4])) numacell.unpin_cpus(set([1, 2, 3])) self.assertEqual(set([1, 2, 3, 4]), numacell.free_cpus) @@ -111,13 +111,13 @@ class _TestNUMA(object): self.assertEqual(set(), numacell.free_cpus) numacell.unpin_cpus_with_siblings(set([1])) self.assertEqual(set([1, 3]), numacell.free_cpus) - self.assertRaises(exception.CPUPinningInvalid, + self.assertRaises(exception.CPUUnpinningInvalid, numacell.unpin_cpus_with_siblings, set([3])) self.assertRaises(exception.CPUPinningInvalid, numacell.pin_cpus_with_siblings, set([4])) - self.assertRaises(exception.CPUPinningInvalid, + self.assertRaises(exception.CPUUnpinningInvalid, numacell.unpin_cpus_with_siblings, set([3, 4])) self.assertEqual(set([1, 3]), numacell.free_cpus)