Add default-quota to subnet pool commands

Add --default-quota option to subnet pool create and set commands.

Setting default-quota back to None may break the current Neutron
behavior, therefore support for Unset command is not provided in
this patch.

Neutron API:
a0e0e8b668/neutron/api/v2/attributes.py (L239)

Closes-Bug: #1667294
Change-Id: Ia4e7c23a49e91a090133c729353cdb8e62bc5674
This commit is contained in:
Reedip 2017-02-23 08:05:00 -05:00 committed by Reedip
parent e54fcd0a5c
commit eb793dc8c6
5 changed files with 110 additions and 7 deletions

View File

@ -24,6 +24,7 @@ Create subnet pool
[--address-scope <address-scope>]
[--default | --no-default]
[--share | --no-share]
[--default-quota <num-ip-addresses>]
--pool-prefix <pool-prefix> [...]
<name>
@ -73,7 +74,12 @@ Create subnet pool
Set this subnet pool as not shared
.. describe:: --pool-prefix <pool-prefix>
.. option:: --default-quota <num-ip-addresses>
Set default quota for subnet pool as the number of
IP addresses allowed in a subnet
.. option:: --pool-prefix <pool-prefix>
Set subnet pool prefixes (in CIDR notation)
(repeat option to set multiple prefixes)
@ -169,6 +175,7 @@ Set subnet pool properties
[--address-scope <address-scope> | --no-address-scope]
[--default | --no-default]
[--description <description>]
[--default-quota <num-ip-addresses>]
<subnet-pool>
.. option:: --name <name>
@ -213,6 +220,11 @@ Set subnet pool properties
Set subnet pool description
.. option:: --default-quota <num-ip-addresses>
Set default quota for subnet pool as the number of
IP addresses allowed in a subnet
.. _subnet_pool_set-subnet-pool:
.. describe:: <subnet-pool>

View File

@ -89,6 +89,9 @@ def _get_attrs(client_manager, parsed_args):
if parsed_args.description is not None:
attrs['description'] = parsed_args.description
if parsed_args.default_quota is not None:
attrs['default_quota'] = int(parsed_args.default_quota)
return attrs
@ -182,6 +185,12 @@ class CreateSubnetPool(command.ShowOne):
metavar='<description>',
help=_("Set subnet pool description")
)
parser.add_argument(
'--default-quota',
type=int,
metavar='<num-ip-addresses>',
help=_("Set default quota for subnet pool as the number of"
"IP addresses allowed in a subnet")),
return parser
def take_action(self, parsed_args):
@ -369,7 +378,12 @@ class SetSubnetPool(command.Command):
metavar='<description>',
help=_("Set subnet pool description")
)
parser.add_argument(
'--default-quota',
type=int,
metavar='<num-ip-addresses>',
help=_("Set default quota for subnet pool as the number of"
"IP addresses allowed in a subnet")),
return parser
def take_action(self, parsed_args):

View File

@ -165,7 +165,7 @@ class SubnetPoolTests(common.NetworkTests):
self.assertIn(name2, names)
def test_subnet_pool_set_show(self):
"""Test create, set, show, delete"""
"""Test create, delete, set, show, unset"""
name = uuid.uuid4().hex
new_name = name + "_"
@ -173,11 +173,15 @@ class SubnetPoolTests(common.NetworkTests):
'--default-prefix-length 16 ' +
'--min-prefix-length 16 ' +
'--max-prefix-length 32 ' +
'--description aaaa ',
'--description aaaa ' +
'--default-quota 10 ',
name,
)
self.addCleanup(self.openstack, 'subnet pool delete ' + new_name)
self.addCleanup(
self.openstack,
'subnet pool delete ' + cmd_output['id'],
)
self.assertEqual(
name,
cmd_output["name"],
@ -202,6 +206,10 @@ class SubnetPoolTests(common.NetworkTests):
32,
cmd_output["max_prefixlen"],
)
self.assertEqual(
10,
cmd_output["default_quota"],
)
# Test set
cmd_output = self.openstack(
@ -212,7 +220,8 @@ class SubnetPoolTests(common.NetworkTests):
'--default-prefix-length 8 ' +
'--min-prefix-length 8 ' +
'--max-prefix-length 16 ' +
name
'--default-quota 20 ' +
name,
)
self.assertOutput('', cmd_output)
@ -244,6 +253,28 @@ class SubnetPoolTests(common.NetworkTests):
16,
cmd_output["max_prefixlen"],
)
self.assertEqual(
20,
cmd_output["default_quota"],
)
# Test unset
# NOTE(dtroyer): The unset command --default-quota option DOES NOT
# WORK after a default quota has been set once on a
# pool. The error appears to be in a lower layer,
# once that is fixed add a test for subnet pool unset
# --default-quota.
# The unset command of --pool-prefixes also doesnt work
# right now. It would be fixed in a separate patch once
# the lower layer is fixed.
# cmd_output = self.openstack(
# '--debug ' +
# 'subnet pool unset ' +
# ' --pool-prefix 10.110.0.0/16 ' +
# new_name,
# )
# self.assertOutput('', cmd_output)
# self.assertNone(cmd_output["prefixes"])
def _subnet_pool_create(self, cmd, name, is_type_ipv4=True):
"""Make a random subnet pool

View File

@ -270,6 +270,27 @@ class TestCreateSubnetPool(TestSubnetPool):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
def test_create_with_default_quota(self):
arglist = [
'--pool-prefix', '10.0.10.0/24',
'--default-quota', '10',
self._subnet_pool.name,
]
verifylist = [
('prefixes', ['10.0.10.0/24']),
('default_quota', 10),
('name', self._subnet_pool.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = (self.cmd.take_action(parsed_args))
self.network.create_subnet_pool.assert_called_once_with(**{
'name': self._subnet_pool.name,
'prefixes': ['10.0.10.0/24'],
'default_quota': 10,
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
class TestDeleteSubnetPool(TestSubnetPool):
@ -567,7 +588,9 @@ class TestListSubnetPool(TestSubnetPool):
class TestSetSubnetPool(TestSubnetPool):
# The subnet_pool to set.
_subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool()
_subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool(
{'default_quota': 10},
)
_address_scope = network_fakes.FakeAddressScope.create_one_address_scope()
@ -794,6 +817,23 @@ class TestSetSubnetPool(TestSubnetPool):
self._subnet_pool, **attrs)
self.assertIsNone(result)
def test_set_with_default_quota(self):
arglist = [
'--default-quota', '20',
self._subnet_pool.name,
]
verifylist = [
('default_quota', 20),
('subnet_pool', self._subnet_pool.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.network.update_subnet_pool.assert_called_once_with(
self._subnet_pool,
**{'default_quota': 20, }
)
self.assertIsNone(result)
class TestShowSubnetPool(TestSubnetPool):

View File

@ -0,0 +1,6 @@
---
features:
- |
Add ``--default-quota`` option to ``subnet pool create``
and ``subnet pool set`` commands.
[Bug `1667294 <https://bugs.launchpad.net/python-openstackclient/+bug/1667294>`_]