diff --git a/osc_placement/resources/allocation.py b/osc_placement/resources/allocation.py index 9eae152..cc63cd9 100644 --- a/osc_placement/resources/allocation.py +++ b/osc_placement/resources/allocation.py @@ -44,7 +44,12 @@ def parse_allocations(allocation_strings): class SetAllocation(command.Lister): - """Set resource allocation(s) for a given consumer""" + """Replaces the set of resource allocation(s) for a given consumer + + Note that this is a full replacement of the existing allocations. If you + want to retain the existing allocations and add a new resource class + allocation, you must specify all resource class allocations, old and new. + """ def get_parser(self, prog_name): parser = super(SetAllocation, self).get_parser(prog_name) diff --git a/osc_placement/tests/unit/test_allocation.py b/osc_placement/tests/unit/test_allocation.py index ab9a061..7b083f5 100644 --- a/osc_placement/tests/unit/test_allocation.py +++ b/osc_placement/tests/unit/test_allocation.py @@ -10,14 +10,16 @@ # License for the specific language governing permissions and limitations # under the License. -import unittest import uuid from osc_lib import exceptions +from oslotest import base +import six + from osc_placement.resources import allocation -class TestAllocation(unittest.TestCase): +class TestAllocation(base.BaseTestCase): def test_parse_allocations(self): rp1 = str(uuid.uuid4()) rp2 = str(uuid.uuid4()) @@ -28,7 +30,8 @@ class TestAllocation(unittest.TestCase): rp1: {'VCPU': 4, 'MEMORY_MB': 16324}, rp2: {'VCPU': 4, 'DISK_GB': 4096}, } - self.assertEqual(expected, allocation.parse_allocations(allocations)) + self.assertDictEqual( + expected, allocation.parse_allocations(allocations)) def test_merge_allocations(self): rp1 = str(uuid.uuid4()) @@ -44,10 +47,13 @@ class TestAllocation(unittest.TestCase): allocations = [ 'rp={},VCPU=4,MEMORY_MB=16324'.format(rp1), 'rp={},VCPU=8,DISK_GB=4096'.format(rp1)] - self.assertRaises( + ex = self.assertRaises( exceptions.CommandError, allocation.parse_allocations, allocations) + self.assertEqual( + 'Conflict detected for resource provider %s resource class VCPU' % + rp1, six.text_type(ex)) - def test_fail_if_incorect_format(self): + def test_fail_if_incorrect_format(self): allocations = ['incorrect_format'] self.assertRaisesRegexp( ValueError,