Merge "Add 'description' option to os subnet (pool) create/set cmd"

This commit is contained in:
Jenkins 2016-09-20 06:40:48 +00:00 committed by Gerrit Code Review
commit a83f3c8a71
9 changed files with 169 additions and 0 deletions

View File

@ -19,6 +19,7 @@ Create subnet pool
[--default-prefix-length <default-prefix-length>]
[--min-prefix-length <min-prefix-length>]
[--max-prefix-length <max-prefix-length>]
[--description <description>]
[--project <project> [--project-domain <project-domain>]]
[--address-scope <address-scope>]
[--default | --no-default]
@ -38,6 +39,10 @@ Create subnet pool
Set subnet pool maximum prefix length
.. option:: --description <description>
Set subnet pool description
.. option:: --project <project>
Owner's project (name or ID)
@ -163,6 +168,7 @@ Set subnet pool properties
[--max-prefix-length <max-prefix-length>]
[--address-scope <address-scope> | --no-address-scope]
[--default | --no-default]
[--description <description>]
<subnet-pool>
.. option:: --name <name>
@ -203,6 +209,10 @@ Set subnet pool properties
Set this as a non-default subnet pool
.. option:: --description <description>
Set subnet pool description
.. _subnet_pool_set-subnet-pool:
.. describe:: <subnet-pool>

View File

@ -26,6 +26,7 @@ Create new subnet
[--gateway <gateway>]
[--host-route destination=<subnet>,gateway=<ip-address>]
[--ip-version {4,6}]
[--description <description>]
[--ipv6-ra-mode {dhcpv6-stateful,dhcpv6-stateless,slaac}]
[--ipv6-address-mode {dhcpv6-stateful,dhcpv6-stateless,slaac}]
[--network-segment <network-segment>]
@ -100,6 +101,10 @@ Create new subnet
IP version is determined from the subnet pool and this option
is ignored.
.. option:: --description <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=<subnet>,gateway=<ip-address>]
[--service-type <service-type>]
[--name <new-name>]
[--description <description>]
<subnet>
.. option:: --allocation-pool start=<ip-address>,end=<ip-address>
@ -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 <description>
Set subnet description
.. option:: --name

View File

@ -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='<network>',
help=_("Network this subnet belongs to (name or ID)")
)
parser.add_argument(
'--description',
metavar='<description>',
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='<description>',
help=_("Set subnet description")
)
_get_common_parse_arguments(parser)
return parser

View File

@ -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='<description>',
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='<description>',
help=_("Set subnet pool description")
)
return parser

View File

@ -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.

View File

@ -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,

View File

@ -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,

View File

@ -0,0 +1,6 @@
---
features:
- |
Adds ``description`` option to ``subnet create`` and
``subnet set`` commands.
[Bug `1614458 <https://bugs.launchpad.net/bugs/1614458>`_]

View File

@ -0,0 +1,6 @@
---
features:
- |
Adds ``description`` option to ``subnet pool create``
and ``subnet pool set`` commands.
[Bug `1614823 <https://bugs.launchpad.net/bugs/1614823>`_]