Don't truncate interface parsing past the ninth interface.
The third argument to re.split is the *maxlength*, not flags. This causes an odd bug whereby every interface *past* number eight isn't properly parsed. Fixes-bug: #1481682 Change-Id: Ieb25dc2ecff947c93dc66faf2a5b7818d1e2eb71
This commit is contained in:
parent
7a077881c9
commit
625ec67225
@ -475,7 +475,7 @@ def _parse_interfaces(data, filters=None):
|
|||||||
:rtype: list of akanda.router.models.Interface
|
:rtype: list of akanda.router.models.Interface
|
||||||
"""
|
"""
|
||||||
retval = []
|
retval = []
|
||||||
for iface_data in re.split('(^|\n)(?=[0-9]: \w+\d{0,3}:)', data, re.M):
|
for iface_data in re.split('(^|\n)(?=[0-9]+: \w+\d{0,3}:)', data):
|
||||||
if not iface_data.strip():
|
if not iface_data.strip():
|
||||||
continue
|
continue
|
||||||
number, interface = iface_data.split(': ', 1)
|
number, interface = iface_data.split(': ', 1)
|
||||||
|
@ -417,6 +417,14 @@ class ParseTestCase(TestCase):
|
|||||||
retval = ip._parse_interfaces(SAMPLE_OUTPUT)
|
retval = ip._parse_interfaces(SAMPLE_OUTPUT)
|
||||||
self.assertEqual(len(retval), 3)
|
self.assertEqual(len(retval), 3)
|
||||||
|
|
||||||
|
def test_parse_over_many_interfaces(self):
|
||||||
|
out = SAMPLE_OUTPUT
|
||||||
|
for i in range(150):
|
||||||
|
out += """\n%d: eth%d: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
|
||||||
|
link/ether fa:16:3e:de:ad:be brd ff:ff:ff:ff:ff:ff""" % (i+4, i+2)
|
||||||
|
retval = ip._parse_interfaces(out, ['eth'])
|
||||||
|
self.assertEqual(len(retval), 152)
|
||||||
|
|
||||||
def test_parse_interfaces_with_filter(self):
|
def test_parse_interfaces_with_filter(self):
|
||||||
with mock.patch.object(ip, '_parse_interface') as parse:
|
with mock.patch.object(ip, '_parse_interface') as parse:
|
||||||
parse.side_effect = lambda x: x
|
parse.side_effect = lambda x: x
|
||||||
|
Loading…
Reference in New Issue
Block a user