diff --git a/doc/source/command-objects/server-group.rst b/doc/source/command-objects/server-group.rst index 77c6431c1e..9769635073 100644 --- a/doc/source/command-objects/server-group.rst +++ b/doc/source/command-objects/server-group.rst @@ -15,13 +15,13 @@ Create a new server group .. code-block:: bash openstack server group create - --policy [--policy ] ... + --policy .. option:: --policy Add a policy to :ref:`\ ` - (repeat option to add multiple policies) + ('affinity' or 'anti-affinity', default to 'affinity') .. _server_group_create-name: .. describe:: diff --git a/openstackclient/compute/v2/server_group.py b/openstackclient/compute/v2/server_group.py index 6bcfc6aef7..c6e2161f60 100644 --- a/openstackclient/compute/v2/server_group.py +++ b/openstackclient/compute/v2/server_group.py @@ -55,10 +55,11 @@ class CreateServerGroup(command.ShowOne): parser.add_argument( '--policy', metavar='', - action='append', - required=True, + choices=['affinity', 'anti-affinity'], + default='affinity', help=_("Add a policy to " - "(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) diff --git a/openstackclient/tests/unit/compute/v2/test_server_group.py b/openstackclient/tests/unit/compute/v2/test_server_group.py index d474f41d80..088497da30 100644 --- a/openstackclient/tests/unit/compute/v2/test_server_group.py +++ b/openstackclient/tests/unit/compute/v2/test_server_group.py @@ -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):