Add choices for option '--policy'
When creating server group, the '--policy' option is required, but valid choice is 'affinity' or 'anti-affinity', adding multiple policies will produce an error. This patch add choices and default value for option '--policy', and remove the former help message. Change-Id: I312680af384363b3e9a7de9aa1f0946643e193e2 Closes-Bug: #1662771
This commit is contained in:
parent
083b115d09
commit
26a74d4596
@ -15,13 +15,13 @@ Create a new server group
|
||||
.. code-block:: bash
|
||||
|
||||
openstack server group create
|
||||
--policy <policy> [--policy <policy>] ...
|
||||
--policy <policy>
|
||||
<name>
|
||||
|
||||
.. option:: --policy <policy>
|
||||
|
||||
Add a policy to :ref:`\<name\> <server_group_create-name>`
|
||||
(repeat option to add multiple policies)
|
||||
('affinity' or 'anti-affinity', default to 'affinity')
|
||||
|
||||
.. _server_group_create-name:
|
||||
.. describe:: <name>
|
||||
|
@ -55,10 +55,11 @@ class CreateServerGroup(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'--policy',
|
||||
metavar='<policy>',
|
||||
action='append',
|
||||
required=True,
|
||||
choices=['affinity', 'anti-affinity'],
|
||||
default='affinity',
|
||||
help=_("Add a policy to <name> "
|
||||
"(repeat option to add multiple policies)")
|
||||
"('affinity' or 'anti-affinity', "
|
||||
"default to 'affinity')")
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -67,7 +68,7 @@ class CreateServerGroup(command.ShowOne):
|
||||
info = {}
|
||||
server_group = compute_client.server_groups.create(
|
||||
name=parsed_args.name,
|
||||
policies=parsed_args.policy)
|
||||
policies=[parsed_args.policy])
|
||||
info.update(server_group._info)
|
||||
|
||||
columns = _get_columns(info)
|
||||
|
@ -63,54 +63,23 @@ class TestServerGroupCreate(TestServerGroup):
|
||||
|
||||
def test_server_group_create(self):
|
||||
arglist = [
|
||||
'--policy', 'affinity',
|
||||
'--policy', 'anti-affinity',
|
||||
'affinity_group',
|
||||
]
|
||||
verifylist = [
|
||||
('policy', ['affinity']),
|
||||
('policy', 'anti-affinity'),
|
||||
('name', 'affinity_group'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.server_groups_mock.create.assert_called_once_with(
|
||||
name=parsed_args.name,
|
||||
policies=parsed_args.policy,
|
||||
policies=[parsed_args.policy],
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
def test_server_group_create_with_multiple_policies(self):
|
||||
arglist = [
|
||||
'--policy', 'affinity',
|
||||
'--policy', 'soft-affinity',
|
||||
'affinity_group',
|
||||
]
|
||||
verifylist = [
|
||||
('policy', ['affinity', 'soft-affinity']),
|
||||
('name', 'affinity_group'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.server_groups_mock.create.assert_called_once_with(
|
||||
name=parsed_args.name,
|
||||
policies=parsed_args.policy,
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
def test_server_group_create_no_policy(self):
|
||||
arglist = [
|
||||
'affinity_group',
|
||||
]
|
||||
verifylist = None
|
||||
self.assertRaises(tests_utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist)
|
||||
|
||||
|
||||
class TestServerGroupDelete(TestServerGroup):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user