diff --git a/doc/source/command-objects/subnet-pool.rst b/doc/source/command-objects/subnet-pool.rst index d47673de5..3a60974a9 100644 --- a/doc/source/command-objects/subnet-pool.rst +++ b/doc/source/command-objects/subnet-pool.rst @@ -24,6 +24,7 @@ Create subnet pool [--address-scope ] [--default | --no-default] [--share | --no-share] + [--default-quota ] --pool-prefix [...] @@ -73,7 +74,12 @@ Create subnet pool Set this subnet pool as not shared -.. describe:: --pool-prefix +.. option:: --default-quota + + Set default quota for subnet pool as the number of + IP addresses allowed in a subnet + +.. option:: --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 | --no-address-scope] [--default | --no-default] [--description ] + [--default-quota ] .. option:: --name @@ -213,6 +220,11 @@ Set subnet pool properties Set subnet pool description +.. option:: --default-quota + + Set default quota for subnet pool as the number of + IP addresses allowed in a subnet + .. _subnet_pool_set-subnet-pool: .. describe:: diff --git a/openstackclient/network/v2/subnet_pool.py b/openstackclient/network/v2/subnet_pool.py index 82ad94127..b72a74fc1 100644 --- a/openstackclient/network/v2/subnet_pool.py +++ b/openstackclient/network/v2/subnet_pool.py @@ -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='', help=_("Set subnet pool description") ) + parser.add_argument( + '--default-quota', + type=int, + metavar='', + 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='', help=_("Set subnet pool description") ) - + parser.add_argument( + '--default-quota', + type=int, + metavar='', + 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): diff --git a/openstackclient/tests/functional/network/v2/test_subnet_pool.py b/openstackclient/tests/functional/network/v2/test_subnet_pool.py index 640f68b70..a4b823f10 100644 --- a/openstackclient/tests/functional/network/v2/test_subnet_pool.py +++ b/openstackclient/tests/functional/network/v2/test_subnet_pool.py @@ -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 diff --git a/openstackclient/tests/unit/network/v2/test_subnet_pool.py b/openstackclient/tests/unit/network/v2/test_subnet_pool.py index f12537e7a..80a57bbb3 100644 --- a/openstackclient/tests/unit/network/v2/test_subnet_pool.py +++ b/openstackclient/tests/unit/network/v2/test_subnet_pool.py @@ -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): diff --git a/releasenotes/notes/bug-1667294-f92efa49627eb00a.yaml b/releasenotes/notes/bug-1667294-f92efa49627eb00a.yaml new file mode 100644 index 000000000..8f2cd31ff --- /dev/null +++ b/releasenotes/notes/bug-1667294-f92efa49627eb00a.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Add ``--default-quota`` option to ``subnet pool create`` + and ``subnet pool set`` commands. + [Bug `1667294 `_]