diff --git a/doc/source/command-objects/subnet-pool.rst b/doc/source/command-objects/subnet-pool.rst index 3330d62d5a..28a735d613 100644 --- a/doc/source/command-objects/subnet-pool.rst +++ b/doc/source/command-objects/subnet-pool.rst @@ -19,6 +19,7 @@ Create subnet pool [--default-prefix-length ] [--min-prefix-length ] [--max-prefix-length ] + [--description ] [--project [--project-domain ]] [--address-scope ] [--default | --no-default] @@ -38,6 +39,10 @@ Create subnet pool Set subnet pool maximum prefix length +.. option:: --description + + Set subnet pool description + .. option:: --project Owner's project (name or ID) @@ -163,6 +168,7 @@ Set subnet pool properties [--max-prefix-length ] [--address-scope | --no-address-scope] [--default | --no-default] + [--description ] .. option:: --name @@ -203,6 +209,10 @@ Set subnet pool properties Set this as a non-default subnet pool +.. option:: --description + + Set subnet pool description + .. _subnet_pool_set-subnet-pool: .. describe:: diff --git a/doc/source/command-objects/subnet.rst b/doc/source/command-objects/subnet.rst index d2ea6132c5..64130ee19e 100644 --- a/doc/source/command-objects/subnet.rst +++ b/doc/source/command-objects/subnet.rst @@ -26,6 +26,7 @@ Create new subnet [--gateway ] [--host-route destination=,gateway=] [--ip-version {4,6}] + [--description ] [--ipv6-ra-mode {dhcpv6-stateful,dhcpv6-stateless,slaac}] [--ipv6-address-mode {dhcpv6-stateful,dhcpv6-stateless,slaac}] [--network-segment ] @@ -100,6 +101,10 @@ Create new subnet IP version is determined from the subnet pool and this option is ignored. +.. option:: --description + + Set subnet description + .. option:: --ipv6-ra-mode {dhcpv6-stateful,dhcpv6-stateless,slaac} IPv6 RA (Router Advertisement) mode, @@ -233,6 +238,7 @@ Set subnet properties [--host-route destination=,gateway=] [--service-type ] [--name ] + [--description ] .. option:: --allocation-pool start=,end= @@ -274,6 +280,9 @@ Set subnet properties ``network:floatingip_agent_gateway``. Must be a valid device owner value for a network port (repeat option to set multiple service types) +.. option:: --description + + Set subnet description .. option:: --name diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py index 8a3f229a2d..7645348743 100644 --- a/openstackclient/network/v2/subnet.py +++ b/openstackclient/network/v2/subnet.py @@ -196,6 +196,8 @@ def _get_attrs(client_manager, parsed_args, is_create=True): if ('service_types' in parsed_args and parsed_args.service_types is not None): attrs['service_types'] = parsed_args.service_types + if parsed_args.description is not None: + attrs['description'] = parsed_args.description return attrs @@ -294,6 +296,11 @@ class CreateSubnet(command.ShowOne): metavar='', help=_("Network this subnet belongs to (name or ID)") ) + parser.add_argument( + '--description', + metavar='', + help=_("Set subnet description") + ) _get_common_parse_arguments(parser) return parser @@ -496,6 +503,11 @@ class SetSubnet(command.Command): "'none': This subnet will not use a gateway, " "e.g.: --gateway 192.168.9.1, --gateway none.") ) + parser.add_argument( + '--description', + metavar='', + help=_("Set subnet description") + ) _get_common_parse_arguments(parser) return parser diff --git a/openstackclient/network/v2/subnet_pool.py b/openstackclient/network/v2/subnet_pool.py index 6852ca27a0..a01d2f7ba2 100644 --- a/openstackclient/network/v2/subnet_pool.py +++ b/openstackclient/network/v2/subnet_pool.py @@ -81,6 +81,9 @@ def _get_attrs(client_manager, parsed_args): ).id attrs['tenant_id'] = project_id + if parsed_args.description is not None: + attrs['description'] = parsed_args.description + return attrs @@ -167,6 +170,11 @@ class CreateSubnetPool(command.ShowOne): action='store_true', help=_("Set this subnet pool as not shared"), ) + parser.add_argument( + '--description', + metavar='', + help=_("Set subnet pool description") + ) return parser def take_action(self, parsed_args): @@ -340,6 +348,11 @@ class SetSubnetPool(command.Command): help=_("Remove address scope associated with the subnet pool") ) _add_default_options(parser) + parser.add_argument( + '--description', + metavar='', + help=_("Set subnet pool description") + ) return parser diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py index 4cc3512e9d..d4cef0a361 100644 --- a/openstackclient/tests/unit/network/v2/fakes.py +++ b/openstackclient/tests/unit/network/v2/fakes.py @@ -892,6 +892,7 @@ class FakeSubnet(object): 'segment_id': None, 'service_types': [], 'subnetpool_id': None, + 'description': 'subnet-description-' + uuid.uuid4().hex, } # Overwrite default attributes. @@ -1047,6 +1048,7 @@ class FakeSubnetPool(object): 'min_prefixlen': '8', 'default_quota': None, 'ip_version': '4', + 'description': 'subnet-pool-description-' + uuid.uuid4().hex, } # Overwrite default attributes. diff --git a/openstackclient/tests/unit/network/v2/test_subnet.py b/openstackclient/tests/unit/network/v2/test_subnet.py index f09fe4faa0..5850639184 100644 --- a/openstackclient/tests/unit/network/v2/test_subnet.py +++ b/openstackclient/tests/unit/network/v2/test_subnet.py @@ -110,6 +110,7 @@ class TestCreateSubnet(TestSubnet): columns = ( 'allocation_pools', 'cidr', + 'description', 'dns_nameservers', 'enable_dhcp', 'gateway_ip', @@ -129,6 +130,7 @@ class TestCreateSubnet(TestSubnet): data = ( subnet_v2._format_allocation_pools(_subnet.allocation_pools), _subnet.cidr, + _subnet.description, utils.format_list(_subnet.dns_nameservers), _subnet.enable_dhcp, _subnet.gateway_ip, @@ -148,6 +150,7 @@ class TestCreateSubnet(TestSubnet): data_subnet_pool = ( subnet_v2._format_allocation_pools(_subnet_from_pool.allocation_pools), _subnet_from_pool.cidr, + _subnet_from_pool.description, utils.format_list(_subnet_from_pool.dns_nameservers), _subnet_from_pool.enable_dhcp, _subnet_from_pool.gateway_ip, @@ -167,6 +170,7 @@ class TestCreateSubnet(TestSubnet): data_ipv6 = ( subnet_v2._format_allocation_pools(_subnet_ipv6.allocation_pools), _subnet_ipv6.cidr, + _subnet_ipv6.description, utils.format_list(_subnet_ipv6.dns_nameservers), _subnet_ipv6.enable_dhcp, _subnet_ipv6.gateway_ip, @@ -427,6 +431,40 @@ class TestCreateSubnet(TestSubnet): self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) + def test_create_with_description(self): + # Mock SDK calls for this test. + self.network.create_subnet = mock.Mock(return_value=self._subnet) + self._network.id = self._subnet.network_id + + arglist = [ + "--subnet-range", self._subnet.cidr, + "--network", self._subnet.network_id, + "--description", self._subnet.description, + self._subnet.name, + ] + verifylist = [ + ('name', self._subnet.name), + ('description', self._subnet.description), + ('subnet_range', self._subnet.cidr), + ('network', self._subnet.network_id), + ('ip_version', self._subnet.ip_version), + ('gateway', 'auto'), + + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.network.create_subnet.assert_called_once_with(**{ + 'cidr': self._subnet.cidr, + 'ip_version': self._subnet.ip_version, + 'name': self._subnet.name, + 'network_id': self._subnet.network_id, + 'description': self._subnet.description, + }) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, data) + class TestDeleteSubnet(TestSubnet): @@ -876,6 +914,30 @@ class TestSetSubnet(TestSubnet): _testsubnet, **attrs) self.assertIsNone(result) + def test_set_non_append_options(self): + arglist = [ + "--description", "new_description", + "--dhcp", + "--gateway", self._subnet.gateway_ip, + self._subnet.name, + ] + verifylist = [ + ('description', "new_description"), + ('dhcp', True), + ('gateway', self._subnet.gateway_ip), + ('subnet', self._subnet.name), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + attrs = { + 'enable_dhcp': True, + 'gateway_ip': self._subnet.gateway_ip, + 'description': "new_description", + } + self.network.update_subnet.assert_called_with(self._subnet, **attrs) + self.assertIsNone(result) + class TestShowSubnet(TestSubnet): # The subnets to be shown @@ -884,6 +946,7 @@ class TestShowSubnet(TestSubnet): columns = ( 'allocation_pools', 'cidr', + 'description', 'dns_nameservers', 'enable_dhcp', 'gateway_ip', @@ -903,6 +966,7 @@ class TestShowSubnet(TestSubnet): data = ( subnet_v2._format_allocation_pools(_subnet.allocation_pools), _subnet.cidr, + _subnet.description, utils.format_list(_subnet.dns_nameservers), _subnet.enable_dhcp, _subnet.gateway_ip, diff --git a/openstackclient/tests/unit/network/v2/test_subnet_pool.py b/openstackclient/tests/unit/network/v2/test_subnet_pool.py index 251323d94c..fa6ffff304 100644 --- a/openstackclient/tests/unit/network/v2/test_subnet_pool.py +++ b/openstackclient/tests/unit/network/v2/test_subnet_pool.py @@ -50,6 +50,7 @@ class TestCreateSubnetPool(TestSubnetPool): 'address_scope_id', 'default_prefixlen', 'default_quota', + 'description', 'id', 'ip_version', 'is_default', @@ -64,6 +65,7 @@ class TestCreateSubnetPool(TestSubnetPool): _subnet_pool.address_scope_id, _subnet_pool.default_prefixlen, _subnet_pool.default_quota, + _subnet_pool.description, _subnet_pool.id, _subnet_pool.ip_version, _subnet_pool.is_default, @@ -245,6 +247,29 @@ class TestCreateSubnetPool(TestSubnetPool): self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) + def test_create_with_description(self): + arglist = [ + '--pool-prefix', '10.0.10.0/24', + '--description', self._subnet_pool.description, + self._subnet_pool.name, + ] + verifylist = [ + ('prefixes', ['10.0.10.0/24']), + ('description', self._subnet_pool.description), + ('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'], + 'description': self._subnet_pool.description, + }) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, data) + class TestDeleteSubnetPool(TestSubnetPool): @@ -749,6 +774,26 @@ class TestSetSubnetPool(TestSubnetPool): self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, arglist, verifylist) + def test_set_description(self): + arglist = [ + '--description', 'new_description', + self._subnet_pool.name, + ] + verifylist = [ + ('description', "new_description"), + ('subnet_pool', self._subnet_pool.name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + attrs = { + 'description': "new_description", + } + self.network.update_subnet_pool.assert_called_once_with( + self._subnet_pool, **attrs) + self.assertIsNone(result) + class TestShowSubnetPool(TestSubnetPool): @@ -759,6 +804,7 @@ class TestShowSubnetPool(TestSubnetPool): 'address_scope_id', 'default_prefixlen', 'default_quota', + 'description', 'id', 'ip_version', 'is_default', @@ -774,6 +820,7 @@ class TestShowSubnetPool(TestSubnetPool): _subnet_pool.address_scope_id, _subnet_pool.default_prefixlen, _subnet_pool.default_quota, + _subnet_pool.description, _subnet_pool.id, _subnet_pool.ip_version, _subnet_pool.is_default, diff --git a/releasenotes/notes/bug-1614458-c42be5738f447db8.yaml b/releasenotes/notes/bug-1614458-c42be5738f447db8.yaml new file mode 100644 index 0000000000..671882b0a8 --- /dev/null +++ b/releasenotes/notes/bug-1614458-c42be5738f447db8.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Adds ``description`` option to ``subnet create`` and + ``subnet set`` commands. + [Bug `1614458 `_] diff --git a/releasenotes/notes/bug-1614823-e89080342f25f2c0.yaml b/releasenotes/notes/bug-1614823-e89080342f25f2c0.yaml new file mode 100644 index 0000000000..96c6661989 --- /dev/null +++ b/releasenotes/notes/bug-1614823-e89080342f25f2c0.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Adds ``description`` option to ``subnet pool create`` + and ``subnet pool set`` commands. + [Bug `1614823 `_]