Merge "Add support for setting extra DHCP options on existing ports"

This commit is contained in:
Zuul 2022-02-25 13:26:11 +00:00 committed by Gerrit Code Review
commit 63452f362d
2 changed files with 36 additions and 0 deletions

View File

@ -820,6 +820,17 @@ class SetPort(common.NeutronCommandWithExtraArgs):
"(Specify both --allowed-address and --no-allowed-address "
"to overwrite the current allowed-address pairs)")
)
parser.add_argument(
'--extra-dhcp-option',
metavar='name=<name>[,value=<value>,ip-version={4,6}]',
default=[],
action=parseractions.MultiKeyValueCommaAction,
dest='extra_dhcp_options',
required_keys=['name'],
optional_keys=['value', "ip-version"],
help=_('Extra DHCP options to be assigned to this port: '
'name=<name>[,value=<value>,ip-version={4,6}] '
'(repeat option to set multiple extra DHCP options)'))
parser.add_argument(
'--data-plane-status',
metavar='<status>',
@ -882,6 +893,10 @@ class SetPort(common.NeutronCommandWithExtraArgs):
attrs['allowed_address_pairs'].extend(
_convert_address_pairs(parsed_args)
)
if parsed_args.extra_dhcp_options:
attrs["extra_dhcp_opts"] = _convert_extra_dhcp_options(parsed_args)
if parsed_args.data_plane_status:
attrs['data_plane_status'] = parsed_args.data_plane_status

View File

@ -1727,6 +1727,27 @@ class TestSetPort(TestPort):
self.network.update_port.assert_called_once_with(self._port, **attrs)
self.assertIsNone(result)
def test_set_port_extra_dhcp_option(self):
arglist = [
'--extra-dhcp-option', 'name=foo,value=bar',
self._port.name,
]
verifylist = [
('extra_dhcp_options', [{'name': 'foo',
'value': 'bar'}]),
('port', self._port.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
attrs = {
'extra_dhcp_opts': [{'opt_name': 'foo',
'opt_value': 'bar'}],
}
self.network.update_port.assert_called_once_with(self._port, **attrs)
self.assertIsNone(result)
def test_set_port_security_enabled(self):
arglist = [
'--enable-port-security',