diff --git a/neutronclient/neutron/v2_0/port.py b/neutronclient/neutron/v2_0/port.py index 0647bed88..c7036af00 100644 --- a/neutronclient/neutron/v2_0/port.py +++ b/neutronclient/neutron/v2_0/port.py @@ -126,6 +126,8 @@ class UpdateExtraDhcpOptMixin(object): opt_ele.update(utils.str2dict(opt)) if (('opt_name' in opt_ele) and ('opt_value' in opt_ele)): + if opt_ele['opt_value'] == 'null': + opt_ele['opt_value'] = None ops.append(opt_ele) opt_ele = {} else: diff --git a/neutronclient/tests/unit/test_cli20_port.py b/neutronclient/tests/unit/test_cli20_port.py index d03d668bd..0f41f247f 100644 --- a/neutronclient/tests/unit/test_cli20_port.py +++ b/neutronclient/tests/unit/test_cli20_port.py @@ -365,6 +365,28 @@ class CLITestV20PortJSON(test_cli20.CLITestV20Base): cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None) self._test_update_resource(resource, cmd, myid, args, updatedfields) + def test_delete_extra_dhcp_opts_from_port(self): + resource = 'port' + myid = 'myid' + args = [myid, + '--extra-dhcp-opt', + "opt_name=bootfile-name,opt_value=null", + '--extra-dhcp-opt', + "opt_name=tftp-server,opt_value=123.123.123.123", + '--extra-dhcp-opt', + "opt_name=server-ip-address,opt_value=123.123.123.45" + ] + # the client code will change the null to None and send to server, + # where its interpreted as delete the DHCP option on the port. + updatedfields = {'extra_dhcp_opts': [{'opt_name': 'bootfile-name', + 'opt_value': None}, + {'opt_name': 'tftp-server', + 'opt_value': '123.123.123.123'}, + {'opt_name': 'server-ip-address', + 'opt_value': '123.123.123.45'}]} + cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None) + self._test_update_resource(resource, cmd, myid, args, updatedfields) + def test_update_port_security_group_off(self): """Update port: --no-security-groups myid.""" resource = 'port'