Add support for setting extra DHCP options on existing ports

It is now possible to set extra DHCP option for an existing port using
"port set" command. It works in the same way like during port creation.

Story: 2009095
Task: 42927
Change-Id: I3577d4e3a303137b708ae8687c44b486aa82e296
This commit is contained in:
Slawek Kaplonski 2022-02-21 22:50:50 +01:00
parent d876b41958
commit 47fa9ba356
2 changed files with 36 additions and 0 deletions

View File

@ -819,6 +819,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>',
@ -881,6 +892,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',