'policy' should be required in server_group_create

The 'policies' param is a required param in nova api now.
So, we also need to change it in cli.

After the modification, the 'policy' param will be required now,
and the old '--policy' style will still be available.

Change-Id: I97921eef0f635c8d50a04bbdaf3ef4f1bfaa3e9d
Closes-Bug: #1323909
This commit is contained in:
wingwj 2014-05-29 15:31:27 +08:00
parent 47774a2edc
commit 376fd9f5bb
2 changed files with 31 additions and 4 deletions

View File

@ -2027,6 +2027,13 @@ class ShellTest(utils.TestCase):
self.run_command('keypair-delete test')
self.assert_called('DELETE', '/os-keypairs/test')
def test_create_server_group(self):
self.run_command('server-group-create wjsg affinity')
self.assert_called('POST', '/os-server-groups',
{'server_group':
{'name': 'wjsg',
'policies': ['affinity']}})
def test_delete_multi_server_groups(self):
self.run_command('server-group-delete 12345 56789')
self.assert_called('DELETE', '/os-server-groups/56789')

View File

@ -3572,13 +3572,33 @@ def do_server_group_list(cs, args):
@utils.arg('name', metavar='<name>', help='Server group name.')
@utils.arg('--policy', metavar='<policy>', action='append',
dest='policies', default=[], type=str,
help='Policies for the server groups')
# NOTE(wingwj): The '--policy' way is still reserved here for preserving
# the backwards compatibility of CLI, even if a user won't get this usage
# in '--help' description. It will be deprecated after an suitable deprecation
# period(probably 2 coordinated releases or so).
#
# Moreover, we imagine that a given user will use only positional parameters or
# only the "--policy" option. So we don't need to properly handle
# the possibility that they might mix them here. That usage is unsupported.
# The related discussion can be found in
# https://review.openstack.org/#/c/96382/2/.
@utils.arg('policy',
metavar='<policy>',
default=argparse.SUPPRESS,
nargs='*',
help='Policies for the server groups '
'("affinity" or "anti-affinity")')
@utils.arg('--policy',
default=[],
action='append',
help=argparse.SUPPRESS)
def do_server_group_create(cs, args):
"""Create a new server group with the specified details."""
if not args.policy:
raise exceptions.CommandError(_("at least one policy must be "
"specified"))
kwargs = {'name': args.name,
'policies': args.policies}
'policies': args.policy}
server_group = cs.server_groups.create(**kwargs)
_print_server_group_details([server_group])