Merge "Ensure netlink.nla_slot tuple key is a string"
This commit is contained in:
commit
3c210f610c
@ -26,7 +26,6 @@ from pyroute2.netlink.rtnl import ifinfmsg
|
||||
from pyroute2.netlink.rtnl import ndmsg
|
||||
from pyroute2 import NetlinkError
|
||||
from pyroute2 import netns
|
||||
import six
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron import privileged
|
||||
@ -520,16 +519,13 @@ def make_serializable(value):
|
||||
of two elements.
|
||||
"""
|
||||
def _ensure_string(value):
|
||||
# NOTE(ralonsoh): once PY2 is deprecated, the str() conversion will be
|
||||
# no needed and six.binary_type --> bytes.
|
||||
return (str(value.decode('utf-8'))
|
||||
if isinstance(value, six.binary_type) else value)
|
||||
return value.decode() if isinstance(value, bytes) else value
|
||||
|
||||
if isinstance(value, list):
|
||||
return [make_serializable(item) for item in value]
|
||||
elif isinstance(value, netlink.nla_slot):
|
||||
return [value[0], make_serializable(value[1])]
|
||||
elif isinstance(value, netlink.nla_base) and six.PY3:
|
||||
return [_ensure_string(value[0]), make_serializable(value[1])]
|
||||
elif isinstance(value, netlink.nla_base):
|
||||
return make_serializable(value.dump())
|
||||
elif isinstance(value, dict):
|
||||
return {_ensure_string(key): make_serializable(data)
|
||||
|
@ -229,13 +229,16 @@ class IpLibTestCase(base.BaseTestCase):
|
||||
|
||||
class MakeSerializableTestCase(base.BaseTestCase):
|
||||
|
||||
NLA_DATA = ifinfmsg.ifinfbase.state(data=b'54321')
|
||||
NLA_DATA1 = ifinfmsg.ifinfbase.state(data=b'54321')
|
||||
NLA_DATA2 = ifinfmsg.ifinfbase.state(data=b'abcdef')
|
||||
INPUT_1 = {'key1': 'value1', b'key2': b'value2', 'key3': ('a', 2),
|
||||
'key4': [1, 2, 'c'],
|
||||
'key5': netlink.nla_slot('nla_name', NLA_DATA)}
|
||||
b'key5': netlink.nla_slot('nla_name1', NLA_DATA1),
|
||||
'key6': netlink.nla_slot(b'nla_name2', NLA_DATA2)}
|
||||
OUTPUT_1 = {'key1': 'value1', 'key2': 'value2', 'key3': ('a', 2),
|
||||
'key4': [1, 2, 'c'],
|
||||
'key5': ['nla_name', '54321']}
|
||||
'key5': ['nla_name1', '54321'],
|
||||
'key6': ['nla_name2', 'abcdef']}
|
||||
|
||||
def test_make_serializable(self):
|
||||
self.assertEqual(self.OUTPUT_1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user