Ensure netlink.nla_slot tuple key is a string
Ensure Pyroute2 netlink.nla_slot first element ("name"), is properly
converted to a string value. E.g.:
In: (b'IFA_ADDRESS', '192.168.30.20')
Out: ('IFA_ADDRESS', '192.168.30.20')
Conflicts:
neutron/privileged/agent/linux/ip_lib.py
Change-Id: I87efe6cf8734bae6523106944e99fbd7db9ef4d5
Related-Bug: #1846360
(cherry picked from commit 43e150e690
)
This commit is contained in:
parent
043853f249
commit
c368674874
|
@ -546,7 +546,7 @@ def make_serializable(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])]
|
||||
return [_ensure_string(value[0]), make_serializable(value[1])]
|
||||
elif isinstance(value, netlink.nla_base) and six.PY3:
|
||||
return make_serializable(value.dump())
|
||||
elif isinstance(value, dict):
|
||||
|
|
|
@ -216,13 +216,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…
Reference in New Issue