Skip to content

Commit eb793dc

Browse files
committed
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: https://github.com/openstack/neutron/blob/a0e0e8b6686b847a4963a6aa6a3224b5768544e6/neutron/api/v2/attributes.py#L239 Closes-Bug: #1667294 Change-Id: Ia4e7c23a49e91a090133c729353cdb8e62bc5674
1 parent e54fcd0 commit eb793dc

5 files changed

Lines changed: 110 additions & 7 deletions

File tree

doc/source/command-objects/subnet-pool.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Create subnet pool
2424
[--address-scope <address-scope>]
2525
[--default | --no-default]
2626
[--share | --no-share]
27+
[--default-quota <num-ip-addresses>]
2728
--pool-prefix <pool-prefix> [...]
2829
<name>
2930
@@ -73,7 +74,12 @@ Create subnet pool
7374
7475
Set this subnet pool as not shared
7576
76-
.. describe:: --pool-prefix <pool-prefix>
77+
.. option:: --default-quota <num-ip-addresses>
78+
79+
Set default quota for subnet pool as the number of
80+
IP addresses allowed in a subnet
81+
82+
.. option:: --pool-prefix <pool-prefix>
7783
7884
Set subnet pool prefixes (in CIDR notation)
7985
(repeat option to set multiple prefixes)
@@ -169,6 +175,7 @@ Set subnet pool properties
169175
[--address-scope <address-scope> | --no-address-scope]
170176
[--default | --no-default]
171177
[--description <description>]
178+
[--default-quota <num-ip-addresses>]
172179
<subnet-pool>
173180
174181
.. option:: --name <name>
@@ -213,6 +220,11 @@ Set subnet pool properties
213220
214221
Set subnet pool description
215222
223+
.. option:: --default-quota <num-ip-addresses>
224+
225+
Set default quota for subnet pool as the number of
226+
IP addresses allowed in a subnet
227+
216228
.. _subnet_pool_set-subnet-pool:
217229
.. describe:: <subnet-pool>
218230

openstackclient/network/v2/subnet_pool.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def _get_attrs(client_manager, parsed_args):
8989
if parsed_args.description is not None:
9090
attrs['description'] = parsed_args.description
9191

92+
if parsed_args.default_quota is not None:
93+
attrs['default_quota'] = int(parsed_args.default_quota)
94+
9295
return attrs
9396

9497

@@ -182,6 +185,12 @@ def get_parser(self, prog_name):
182185
metavar='<description>',
183186
help=_("Set subnet pool description")
184187
)
188+
parser.add_argument(
189+
'--default-quota',
190+
type=int,
191+
metavar='<num-ip-addresses>',
192+
help=_("Set default quota for subnet pool as the number of"
193+
"IP addresses allowed in a subnet")),
185194
return parser
186195

187196
def take_action(self, parsed_args):
@@ -369,7 +378,12 @@ def get_parser(self, prog_name):
369378
metavar='<description>',
370379
help=_("Set subnet pool description")
371380
)
372-
381+
parser.add_argument(
382+
'--default-quota',
383+
type=int,
384+
metavar='<num-ip-addresses>',
385+
help=_("Set default quota for subnet pool as the number of"
386+
"IP addresses allowed in a subnet")),
373387
return parser
374388

375389
def take_action(self, parsed_args):

openstackclient/tests/functional/network/v2/test_subnet_pool.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,23 @@ def test_subnet_pool_list(self):
165165
self.assertIn(name2, names)
166166

167167
def test_subnet_pool_set_show(self):
168-
"""Test create, set, show, delete"""
168+
"""Test create, delete, set, show, unset"""
169169

170170
name = uuid.uuid4().hex
171171
new_name = name + "_"
172172
cmd_output, pool_prefix = self._subnet_pool_create(
173173
'--default-prefix-length 16 ' +
174174
'--min-prefix-length 16 ' +
175175
'--max-prefix-length 32 ' +
176-
'--description aaaa ',
176+
'--description aaaa ' +
177+
'--default-quota 10 ',
177178
name,
178179
)
179180

180-
self.addCleanup(self.openstack, 'subnet pool delete ' + new_name)
181+
self.addCleanup(
182+
self.openstack,
183+
'subnet pool delete ' + cmd_output['id'],
184+
)
181185
self.assertEqual(
182186
name,
183187
cmd_output["name"],
@@ -202,6 +206,10 @@ def test_subnet_pool_set_show(self):
202206
32,
203207
cmd_output["max_prefixlen"],
204208
)
209+
self.assertEqual(
210+
10,
211+
cmd_output["default_quota"],
212+
)
205213

206214
# Test set
207215
cmd_output = self.openstack(
@@ -212,7 +220,8 @@ def test_subnet_pool_set_show(self):
212220
'--default-prefix-length 8 ' +
213221
'--min-prefix-length 8 ' +
214222
'--max-prefix-length 16 ' +
215-
name
223+
'--default-quota 20 ' +
224+
name,
216225
)
217226
self.assertOutput('', cmd_output)
218227

@@ -244,6 +253,28 @@ def test_subnet_pool_set_show(self):
244253
16,
245254
cmd_output["max_prefixlen"],
246255
)
256+
self.assertEqual(
257+
20,
258+
cmd_output["default_quota"],
259+
)
260+
261+
# Test unset
262+
# NOTE(dtroyer): The unset command --default-quota option DOES NOT
263+
# WORK after a default quota has been set once on a
264+
# pool. The error appears to be in a lower layer,
265+
# once that is fixed add a test for subnet pool unset
266+
# --default-quota.
267+
# The unset command of --pool-prefixes also doesnt work
268+
# right now. It would be fixed in a separate patch once
269+
# the lower layer is fixed.
270+
# cmd_output = self.openstack(
271+
# '--debug ' +
272+
# 'subnet pool unset ' +
273+
# ' --pool-prefix 10.110.0.0/16 ' +
274+
# new_name,
275+
# )
276+
# self.assertOutput('', cmd_output)
277+
# self.assertNone(cmd_output["prefixes"])
247278

248279
def _subnet_pool_create(self, cmd, name, is_type_ipv4=True):
249280
"""Make a random subnet pool

openstackclient/tests/unit/network/v2/test_subnet_pool.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,27 @@ def test_create_with_description(self):
270270
self.assertEqual(self.columns, columns)
271271
self.assertEqual(self.data, data)
272272

273+
def test_create_with_default_quota(self):
274+
arglist = [
275+
'--pool-prefix', '10.0.10.0/24',
276+
'--default-quota', '10',
277+
self._subnet_pool.name,
278+
]
279+
verifylist = [
280+
('prefixes', ['10.0.10.0/24']),
281+
('default_quota', 10),
282+
('name', self._subnet_pool.name),
283+
]
284+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
285+
columns, data = (self.cmd.take_action(parsed_args))
286+
self.network.create_subnet_pool.assert_called_once_with(**{
287+
'name': self._subnet_pool.name,
288+
'prefixes': ['10.0.10.0/24'],
289+
'default_quota': 10,
290+
})
291+
self.assertEqual(self.columns, columns)
292+
self.assertEqual(self.data, data)
293+
273294

274295
class TestDeleteSubnetPool(TestSubnetPool):
275296

@@ -567,7 +588,9 @@ def test_subnet_pool_list_address_scope(self):
567588
class TestSetSubnetPool(TestSubnetPool):
568589

569590
# The subnet_pool to set.
570-
_subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool()
591+
_subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool(
592+
{'default_quota': 10},
593+
)
571594

572595
_address_scope = network_fakes.FakeAddressScope.create_one_address_scope()
573596

@@ -794,6 +817,23 @@ def test_set_description(self):
794817
self._subnet_pool, **attrs)
795818
self.assertIsNone(result)
796819

820+
def test_set_with_default_quota(self):
821+
arglist = [
822+
'--default-quota', '20',
823+
self._subnet_pool.name,
824+
]
825+
verifylist = [
826+
('default_quota', 20),
827+
('subnet_pool', self._subnet_pool.name),
828+
]
829+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
830+
result = self.cmd.take_action(parsed_args)
831+
self.network.update_subnet_pool.assert_called_once_with(
832+
self._subnet_pool,
833+
**{'default_quota': 20, }
834+
)
835+
self.assertIsNone(result)
836+
797837

798838
class TestShowSubnetPool(TestSubnetPool):
799839

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Add ``--default-quota`` option to ``subnet pool create``
5+
and ``subnet pool set`` commands.
6+
[Bug `1667294 <https://bugs.launchpad.net/python-openstackclient/+bug/1667294>`_]

0 commit comments

Comments
 (0)