Enforce key-value'ness for 'allocation candidate list --resource'
Change-Id: I884db8d66f54f7580d8dc4c5f95c99ec76fc864d Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Closes-Bug: #1798823
This commit is contained in:
parent
918c20e2ba
commit
014acf10be
|
@ -57,6 +57,7 @@ class ListAllocationCandidate(command.Lister, version.CheckerMixin):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--resource',
|
'--resource',
|
||||||
metavar='<resource_class>=<value>',
|
metavar='<resource_class>=<value>',
|
||||||
|
dest='resources',
|
||||||
action='append',
|
action='append',
|
||||||
default=[],
|
default=[],
|
||||||
help='String indicating an amount of resource of a specified '
|
help='String indicating an amount of resource of a specified '
|
||||||
|
@ -90,14 +91,20 @@ class ListAllocationCandidate(command.Lister, version.CheckerMixin):
|
||||||
|
|
||||||
@version.check(version.ge('1.10'))
|
@version.check(version.ge('1.10'))
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
if not parsed_args.resource:
|
if not parsed_args.resources:
|
||||||
raise exceptions.CommandError(
|
raise exceptions.CommandError(
|
||||||
'At least one --resource must be specified.')
|
'At least one --resource must be specified.')
|
||||||
|
|
||||||
|
for resource in parsed_args.resources:
|
||||||
|
if not len(resource.split('=')) == 2:
|
||||||
|
raise exceptions.CommandError(
|
||||||
|
'Arguments to --resource must be of form '
|
||||||
|
'<resource_class>=<value>')
|
||||||
|
|
||||||
http = self.app.client_manager.placement
|
http = self.app.client_manager.placement
|
||||||
|
|
||||||
params = {'resources': ','.join(
|
params = {'resources': ','.join(
|
||||||
resource.replace('=', ':') for resource in parsed_args.resource)}
|
resource.replace('=', ':') for resource in parsed_args.resources)}
|
||||||
if 'limit' in parsed_args and parsed_args.limit:
|
if 'limit' in parsed_args and parsed_args.limit:
|
||||||
# Fail if --limit but not high enough microversion.
|
# Fail if --limit but not high enough microversion.
|
||||||
self.check_version(version.ge('1.16'))
|
self.check_version(version.ge('1.16'))
|
||||||
|
|
|
@ -27,6 +27,12 @@ class TestAllocationCandidate(base.BaseTestCase):
|
||||||
'At least one --resource must be specified',
|
'At least one --resource must be specified',
|
||||||
self.openstack, 'allocation candidate list')
|
self.openstack, 'allocation candidate list')
|
||||||
|
|
||||||
|
def test_list_non_key_value_resource_specified_error(self):
|
||||||
|
self.assertCommandFailed(
|
||||||
|
'Arguments to --resource must be of form '
|
||||||
|
'<resource_class>=<value>',
|
||||||
|
self.openstack, 'allocation candidate list --resource VCPU')
|
||||||
|
|
||||||
def test_list_empty(self):
|
def test_list_empty(self):
|
||||||
self.assertEqual([], self.allocation_candidate_list(
|
self.assertEqual([], self.allocation_candidate_list(
|
||||||
resources=['MEMORY_MB=999999999']))
|
resources=['MEMORY_MB=999999999']))
|
||||||
|
|
Loading…
Reference in New Issue