Merge "Address review comments from allocations patch"

This commit is contained in:
Zuul 2018-01-24 19:26:40 +00:00 committed by Gerrit Code Review
commit a9dfbd8dc4
2 changed files with 17 additions and 6 deletions

View File

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

View File

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