Address review comments from allocations patch
This addresses some review comments from change I699fd01d6dbd1c9c5186d1b86499ae2bae94286a: 1. Improve the help text wording for "allocation set" to let people know it's an overwrite/replacement of the existing allocations so they need to include old and new allocations if they don't want to lose the old ones when adding any new ones. 2. A couple of enhancements in the allocation unit tests. Part of blueprint placement-osc-plugin Change-Id: I4abebc709564d8afcbbe18e8d406f2c898d7ea8b
This commit is contained in:
parent
4a0aa464fd
commit
ecef8f4255
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue