Browse Source

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)
(cherry picked from commit c368674874)
tags/14.2.0
Rodolfo Alonso Hernandez 5 months ago
parent
commit
551464dd77
2 changed files with 7 additions and 4 deletions
  1. +1
    -1
      neutron/privileged/agent/linux/ip_lib.py
  2. +6
    -3
      neutron/tests/unit/privileged/agent/linux/test_ip_lib.py

+ 1
- 1
neutron/privileged/agent/linux/ip_lib.py View File

@@ -527,7 +527,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):


+ 6
- 3
neutron/tests/unit/privileged/agent/linux/test_ip_lib.py View File

@@ -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…
Cancel
Save