From 3a9bd27f338b57f913cf61bb3df48dbc7ee5215c Mon Sep 17 00:00:00 2001 From: dekehn Date: Tue, 1 Oct 2013 09:06:46 -0600 Subject: [PATCH] Adds delete of extra-dhcp-opt to the client Add support to delete existing extra-dhcp-opt(s) for a port via the port-update operation. To use it, set the opt_value=null of the opt_name that you want deleted (i.e. neutron port-update --extra-dhcp-opt opt_name=tftp-server,opt_value=null), which will delete this DHCP option from the port. Change-Id: I9c2c2474b2bfe8c8f8c3c3cc1513d2b999643d14 Closes-Bug: 1228008 --- neutronclient/neutron/v2_0/port.py | 2 ++ neutronclient/tests/unit/test_cli20_port.py | 22 +++++++++++++++++++++ 2 files changed, 24 insertions(+) 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 b9214088f..3aa8683f1 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'