From 08759b853a2611144a2d3f0e9216d6801fc23ef2 Mon Sep 17 00:00:00 2001 From: Inessa Vasilevskaya Date: Mon, 25 Apr 2016 12:22:14 +0000 Subject: [PATCH] Fixes BadRequest when no --pool-prefix given --pool-prefix is made required on subnetpool creation. Closes-bug: #1536479 Change-Id: I3d183e45e9b96bc08011c36f45ec2b7a9c01b627 --- doc/source/command-objects/subnet-pool.rst | 12 ++++++------ openstackclient/network/v2/subnet_pool.py | 5 +++-- .../tests/network/v2/test_subnet_pool.py | 15 ++++++++++++++- .../notes/bug-1536479-d1f03ed2177d06ed.yaml | 5 +++++ 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/bug-1536479-d1f03ed2177d06ed.yaml diff --git a/doc/source/command-objects/subnet-pool.rst b/doc/source/command-objects/subnet-pool.rst index 867153efa4..523f78c2f5 100644 --- a/doc/source/command-objects/subnet-pool.rst +++ b/doc/source/command-objects/subnet-pool.rst @@ -13,7 +13,6 @@ Create subnet pool .. code:: bash os subnet pool create - [--pool-prefix [...]] [--default-prefix-length ] [--min-prefix-length ] [--max-prefix-length ] @@ -21,13 +20,9 @@ Create subnet pool [--address-scope ] [--default | --no-default] [--share | --no-share] + --pool-prefix [...] -.. option:: --pool-prefix - - Set subnet pool prefixes (in CIDR notation) - (repeat option to set multiple prefixes) - .. option:: --default-prefix-length Set subnet pool default prefix length @@ -70,6 +65,11 @@ Create subnet pool Set this subnet pool as not shared +.. describe:: --pool-prefix + + Set subnet pool prefixes (in CIDR notation) + (repeat option to set multiple prefixes) + .. _subnet_pool_create-name: .. describe:: diff --git a/openstackclient/network/v2/subnet_pool.py b/openstackclient/network/v2/subnet_pool.py index 688dd2ca7c..435db2e116 100644 --- a/openstackclient/network/v2/subnet_pool.py +++ b/openstackclient/network/v2/subnet_pool.py @@ -78,12 +78,13 @@ def _get_attrs(client_manager, parsed_args): return attrs -def _add_prefix_options(parser): +def _add_prefix_options(parser, for_create=False): parser.add_argument( '--pool-prefix', metavar='', dest='prefixes', action='append', + required=for_create, help=_("Set subnet pool prefixes (in CIDR notation) " "(repeat option to set multiple prefixes)") ) @@ -131,7 +132,7 @@ class CreateSubnetPool(command.ShowOne): metavar='', help=_("Name of the new subnet pool") ) - _add_prefix_options(parser) + _add_prefix_options(parser, for_create=True) parser.add_argument( '--project', metavar='', diff --git a/openstackclient/tests/network/v2/test_subnet_pool.py b/openstackclient/tests/network/v2/test_subnet_pool.py index 369a8b1125..b40390a143 100644 --- a/openstackclient/tests/network/v2/test_subnet_pool.py +++ b/openstackclient/tests/network/v2/test_subnet_pool.py @@ -113,6 +113,17 @@ class TestCreateSubnetPool(TestSubnetPool): self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, arglist, verifylist) + def test_create_no_pool_prefix(self): + """Make sure --pool-prefix is a required argument""" + arglist = [ + self._subnet_pool.name, + ] + verifylist = [ + ('name', self._subnet_pool.name), + ] + self.assertRaises(tests_utils.ParserException, self.check_parser, + self.cmd, arglist, verifylist) + def test_create_default_options(self): arglist = [ '--pool-prefix', '10.0.10.0/24', @@ -138,6 +149,7 @@ class TestCreateSubnetPool(TestSubnetPool): '--default-prefix-length', self._subnet_pool.default_prefixlen, '--max-prefix-length', self._subnet_pool.max_prefixlen, '--min-prefix-length', self._subnet_pool.min_prefixlen, + '--pool-prefix', '10.0.10.0/24', self._subnet_pool.name, ] verifylist = [ @@ -145,6 +157,7 @@ class TestCreateSubnetPool(TestSubnetPool): ('max_prefix_length', self._subnet_pool.max_prefixlen), ('min_prefix_length', self._subnet_pool.min_prefixlen), ('name', self._subnet_pool.name), + ('prefixes', ['10.0.10.0/24']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -154,7 +167,7 @@ class TestCreateSubnetPool(TestSubnetPool): 'default_prefixlen': self._subnet_pool.default_prefixlen, 'max_prefixlen': self._subnet_pool.max_prefixlen, 'min_prefixlen': self._subnet_pool.min_prefixlen, - 'prefixes': [], + 'prefixes': ['10.0.10.0/24'], 'name': self._subnet_pool.name, }) self.assertEqual(self.columns, columns) diff --git a/releasenotes/notes/bug-1536479-d1f03ed2177d06ed.yaml b/releasenotes/notes/bug-1536479-d1f03ed2177d06ed.yaml new file mode 100644 index 0000000000..b9932ad43b --- /dev/null +++ b/releasenotes/notes/bug-1536479-d1f03ed2177d06ed.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + ``--pool-prefix`` option made required for ``subnet pool create`` + [Bug `1536479 `_]