Fixes BadRequest when no --pool-prefix given

--pool-prefix is made required on subnetpool creation.
Closes-bug: #1536479

Change-Id: I3d183e45e9b96bc08011c36f45ec2b7a9c01b627
This commit is contained in:
Inessa Vasilevskaya 2016-04-25 12:22:14 +00:00
parent a0a29df3e6
commit 08759b853a
4 changed files with 28 additions and 9 deletions

View File

@ -13,7 +13,6 @@ Create subnet pool
.. code:: bash .. code:: bash
os subnet pool create os subnet pool create
[--pool-prefix <pool-prefix> [...]]
[--default-prefix-length <default-prefix-length>] [--default-prefix-length <default-prefix-length>]
[--min-prefix-length <min-prefix-length>] [--min-prefix-length <min-prefix-length>]
[--max-prefix-length <max-prefix-length>] [--max-prefix-length <max-prefix-length>]
@ -21,13 +20,9 @@ Create subnet pool
[--address-scope <address-scope>] [--address-scope <address-scope>]
[--default | --no-default] [--default | --no-default]
[--share | --no-share] [--share | --no-share]
--pool-prefix <pool-prefix> [...]
<name> <name>
.. option:: --pool-prefix <pool-prefix>
Set subnet pool prefixes (in CIDR notation)
(repeat option to set multiple prefixes)
.. option:: --default-prefix-length <default-prefix-length> .. option:: --default-prefix-length <default-prefix-length>
Set subnet pool default prefix length Set subnet pool default prefix length
@ -70,6 +65,11 @@ Create subnet pool
Set this subnet pool as not shared Set this subnet pool as not shared
.. describe:: --pool-prefix <pool-prefix>
Set subnet pool prefixes (in CIDR notation)
(repeat option to set multiple prefixes)
.. _subnet_pool_create-name: .. _subnet_pool_create-name:
.. describe:: <name> .. describe:: <name>

View File

@ -78,12 +78,13 @@ def _get_attrs(client_manager, parsed_args):
return attrs return attrs
def _add_prefix_options(parser): def _add_prefix_options(parser, for_create=False):
parser.add_argument( parser.add_argument(
'--pool-prefix', '--pool-prefix',
metavar='<pool-prefix>', metavar='<pool-prefix>',
dest='prefixes', dest='prefixes',
action='append', action='append',
required=for_create,
help=_("Set subnet pool prefixes (in CIDR notation) " help=_("Set subnet pool prefixes (in CIDR notation) "
"(repeat option to set multiple prefixes)") "(repeat option to set multiple prefixes)")
) )
@ -131,7 +132,7 @@ class CreateSubnetPool(command.ShowOne):
metavar='<name>', metavar='<name>',
help=_("Name of the new subnet pool") help=_("Name of the new subnet pool")
) )
_add_prefix_options(parser) _add_prefix_options(parser, for_create=True)
parser.add_argument( parser.add_argument(
'--project', '--project',
metavar='<project>', metavar='<project>',

View File

@ -113,6 +113,17 @@ class TestCreateSubnetPool(TestSubnetPool):
self.assertRaises(tests_utils.ParserException, self.check_parser, self.assertRaises(tests_utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist) 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): def test_create_default_options(self):
arglist = [ arglist = [
'--pool-prefix', '10.0.10.0/24', '--pool-prefix', '10.0.10.0/24',
@ -138,6 +149,7 @@ class TestCreateSubnetPool(TestSubnetPool):
'--default-prefix-length', self._subnet_pool.default_prefixlen, '--default-prefix-length', self._subnet_pool.default_prefixlen,
'--max-prefix-length', self._subnet_pool.max_prefixlen, '--max-prefix-length', self._subnet_pool.max_prefixlen,
'--min-prefix-length', self._subnet_pool.min_prefixlen, '--min-prefix-length', self._subnet_pool.min_prefixlen,
'--pool-prefix', '10.0.10.0/24',
self._subnet_pool.name, self._subnet_pool.name,
] ]
verifylist = [ verifylist = [
@ -145,6 +157,7 @@ class TestCreateSubnetPool(TestSubnetPool):
('max_prefix_length', self._subnet_pool.max_prefixlen), ('max_prefix_length', self._subnet_pool.max_prefixlen),
('min_prefix_length', self._subnet_pool.min_prefixlen), ('min_prefix_length', self._subnet_pool.min_prefixlen),
('name', self._subnet_pool.name), ('name', self._subnet_pool.name),
('prefixes', ['10.0.10.0/24']),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -154,7 +167,7 @@ class TestCreateSubnetPool(TestSubnetPool):
'default_prefixlen': self._subnet_pool.default_prefixlen, 'default_prefixlen': self._subnet_pool.default_prefixlen,
'max_prefixlen': self._subnet_pool.max_prefixlen, 'max_prefixlen': self._subnet_pool.max_prefixlen,
'min_prefixlen': self._subnet_pool.min_prefixlen, 'min_prefixlen': self._subnet_pool.min_prefixlen,
'prefixes': [], 'prefixes': ['10.0.10.0/24'],
'name': self._subnet_pool.name, 'name': self._subnet_pool.name,
}) })
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)

View File

@ -0,0 +1,5 @@
---
fixes:
- |
``--pool-prefix`` option made required for ``subnet pool create``
[Bug `1536479 <https://bugs.launchpad.net/bugs/1536479>`_]