Fix validation for command arguments

In the "Update Aggregate" API,
if both an availability zone and a name are not specified,
a 400 error is returned.

It should be checked in the novaclient side (nova command).
So add the validation for it at the 'nova aggregate-update' command.

Change-Id: If50579ef3572a10b67e6da32e3258917901e9d9d
Closes-Bug: #1696891
This commit is contained in:
Takashi NATSUME 2018-04-03 09:15:48 +09:00
parent d4df771868
commit 026388630e
2 changed files with 12 additions and 0 deletions

View File

@ -2243,6 +2243,13 @@ class ShellTest(utils.TestCase):
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
self.assert_called('GET', '/os-aggregates/1', pos=-1)
def test_aggregate_update_without_availability_zone_and_name(self):
ex = self.assertRaises(exceptions.CommandError, self.run_command,
'aggregate-update test')
self.assertIn("Either '--name <name>' or '--availability-zone "
"<availability-zone>' must be specified.",
six.text_type(ex))
def test_aggregate_set_metadata_add_by_id(self):
out, err = self.run_command('aggregate-set-metadata 3 foo=bar')
body = {"set_metadata": {"metadata": {"foo": "bar"}}}

View File

@ -3175,6 +3175,11 @@ def do_aggregate_update(cs, args):
if args.availability_zone:
updates["availability_zone"] = args.availability_zone
if not updates:
raise exceptions.CommandError(_(
"Either '--name <name>' or '--availability-zone "
"<availability-zone>' must be specified."))
aggregate = cs.aggregates.update(aggregate.id, updates)
print(_("Aggregate %s has been successfully updated.") % aggregate.id)
_print_aggregate_details(cs, aggregate)