diff --git a/osc_placement/resources/allocation_candidate.py b/osc_placement/resources/allocation_candidate.py index b4fd755..afe19a2 100644 --- a/osc_placement/resources/allocation_candidate.py +++ b/osc_placement/resources/allocation_candidate.py @@ -57,6 +57,7 @@ class ListAllocationCandidate(command.Lister, version.CheckerMixin): parser.add_argument( '--resource', metavar='=', + dest='resources', action='append', default=[], 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')) def take_action(self, parsed_args): - if not parsed_args.resource: + if not parsed_args.resources: raise exceptions.CommandError( '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 ' + '=') + http = self.app.client_manager.placement 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: # Fail if --limit but not high enough microversion. self.check_version(version.ge('1.16')) diff --git a/osc_placement/tests/functional/test_allocation_candidate.py b/osc_placement/tests/functional/test_allocation_candidate.py index ce64da2..c913846 100644 --- a/osc_placement/tests/functional/test_allocation_candidate.py +++ b/osc_placement/tests/functional/test_allocation_candidate.py @@ -27,6 +27,12 @@ class TestAllocationCandidate(base.BaseTestCase): 'At least one --resource must be specified', self.openstack, 'allocation candidate list') + def test_list_non_key_value_resource_specified_error(self): + self.assertCommandFailed( + 'Arguments to --resource must be of form ' + '=', + self.openstack, 'allocation candidate list --resource VCPU') + def test_list_empty(self): self.assertEqual([], self.allocation_candidate_list( resources=['MEMORY_MB=999999999']))