Allow address pairs to be cleared with None

When the neutron client attempts to clear the allowed
address pairs using the '--action=clear' CLI param, it
sends a value of None to the Neutron server for allowed
address pairs. However, the allowed address pairs extension
was only allowing an empty list to clear the pairs.

This patch just converts None to an empty list on allowed
address pairs to be compatible with the client.

APIImpact
Closes-Bug: #1537734
Change-Id: Iba618b3e07bd3bdc202a9577954d7b97c2a5bf09
This commit is contained in:
Kevin Benton 2016-01-27 04:34:54 -08:00 committed by Kevin Benton
parent 44571236ca
commit 8052c39853
3 changed files with 19 additions and 3 deletions

View File

@ -97,6 +97,7 @@ ADDRESS_PAIRS = 'allowed_address_pairs'
EXTENDED_ATTRIBUTES_2_0 = {
'ports': {
ADDRESS_PAIRS: {'allow_post': True, 'allow_put': True,
'convert_to': attr.convert_none_to_empty_list,
'convert_list_to':
attr.convert_kvp_list_to_dict,
'validate': {'type:validate_allowed_address_pairs':

View File

@ -100,7 +100,7 @@ class TestAllowedAddressPairs(AllowedAddressPairDBTestCase):
def test_create_port_allowed_address_pairs_bad_format(self):
with self.network() as net:
bad_values = [False, True, None, 1.1, 1]
bad_values = [False, True, 1.1, 1]
for value in bad_values:
self._create_port(
self.fmt, net['network']['id'],
@ -305,7 +305,13 @@ class TestAllowedAddressPairs(AllowedAddressPairDBTestCase):
res = req.get_response(self.api)
self.assertEqual(400, res.status_int)
def test_create_port_remove_allowed_address_pairs(self):
def test_create_port_remove_allowed_address_pairs_with_list(self):
self._test_create_port_remove_allowed_address_pairs([])
def test_create_port_remove_allowed_address_pairs_with_none(self):
self._test_create_port_remove_allowed_address_pairs(None)
def _test_create_port_remove_allowed_address_pairs(self, update_value):
with self.network() as net:
address_pairs = [{'mac_address': '00:00:00:00:00:01',
'ip_address': '10.0.0.1'}]
@ -313,7 +319,7 @@ class TestAllowedAddressPairs(AllowedAddressPairDBTestCase):
arg_list=(addr_pair.ADDRESS_PAIRS,),
allowed_address_pairs=address_pairs)
port = self.deserialize(self.fmt, res)
update_port = {'port': {addr_pair.ADDRESS_PAIRS: []}}
update_port = {'port': {addr_pair.ADDRESS_PAIRS: update_value}}
req = self.new_update_request('ports', update_port,
port['port']['id'])
port = self.deserialize(self.fmt, req.get_response(self.api))

View File

@ -0,0 +1,9 @@
---
prelude: >
Allowed address pairs can now be cleared by passing
None in addition to an empty list. This is to make
it possible to use the --action=clear option with
the neutron client.
neutron port-update <uuid> --allowed-address-pairs action=clear
fixes:
- Fixes bug 1537734