From 3a103f9a467a6bf46e13ebc229938124e4b68f42 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Sat, 24 Mar 2018 13:05:44 +0100 Subject: [PATCH] ldp-topo1: fix parsing for iproute from Ubuntu 18.04 Signed-off-by: Christian Franke --- .../topotests/ldp-topo1/r1/ip_mpls_route.ref | 10 +-- .../ldp-topo1/r1/ip_mpls_route.ref-1 | 10 +-- .../topotests/ldp-topo1/r2/ip_mpls_route.ref | 8 +-- .../ldp-topo1/r2/ip_mpls_route.ref-1 | 10 +-- .../topotests/ldp-topo1/r3/ip_mpls_route.ref | 14 ++-- .../ldp-topo1/r3/ip_mpls_route.ref-1 | 20 +++--- .../topotests/ldp-topo1/r4/ip_mpls_route.ref | 12 ++-- .../ldp-topo1/r4/ip_mpls_route.ref-1 | 14 ++-- tests/topotests/ldp-topo1/test_ldp_topo1.py | 70 ++++++------------- 9 files changed, 64 insertions(+), 104 deletions(-) diff --git a/tests/topotests/ldp-topo1/r1/ip_mpls_route.ref b/tests/topotests/ldp-topo1/r1/ip_mpls_route.ref index 63b4043bf8..f244122f1a 100644 --- a/tests/topotests/ldp-topo1/r1/ip_mpls_route.ref +++ b/tests/topotests/ldp-topo1/r1/ip_mpls_route.ref @@ -1,5 +1,5 @@ -xx as to xx via inet 10.0.1.2 dev r1-eth0 proto xx -xx as to xx via inet 10.0.1.2 dev r1-eth0 proto xx -xx via inet 10.0.1.2 dev r1-eth0 proto xx -xx via inet 10.0.1.2 dev r1-eth0 proto xx -xx via inet 10.0.1.2 dev r1-eth0 proto xx +xx as to xx via inet 10.0.1.2 dev r1-eth0 proto xx +xx as to xx via inet 10.0.1.2 dev r1-eth0 proto xx +xx via inet 10.0.1.2 dev r1-eth0 proto xx +xx via inet 10.0.1.2 dev r1-eth0 proto xx +xx via inet 10.0.1.2 dev r1-eth0 proto xx diff --git a/tests/topotests/ldp-topo1/r1/ip_mpls_route.ref-1 b/tests/topotests/ldp-topo1/r1/ip_mpls_route.ref-1 index 63b4043bf8..f244122f1a 100644 --- a/tests/topotests/ldp-topo1/r1/ip_mpls_route.ref-1 +++ b/tests/topotests/ldp-topo1/r1/ip_mpls_route.ref-1 @@ -1,5 +1,5 @@ -xx as to xx via inet 10.0.1.2 dev r1-eth0 proto xx -xx as to xx via inet 10.0.1.2 dev r1-eth0 proto xx -xx via inet 10.0.1.2 dev r1-eth0 proto xx -xx via inet 10.0.1.2 dev r1-eth0 proto xx -xx via inet 10.0.1.2 dev r1-eth0 proto xx +xx as to xx via inet 10.0.1.2 dev r1-eth0 proto xx +xx as to xx via inet 10.0.1.2 dev r1-eth0 proto xx +xx via inet 10.0.1.2 dev r1-eth0 proto xx +xx via inet 10.0.1.2 dev r1-eth0 proto xx +xx via inet 10.0.1.2 dev r1-eth0 proto xx diff --git a/tests/topotests/ldp-topo1/r2/ip_mpls_route.ref b/tests/topotests/ldp-topo1/r2/ip_mpls_route.ref index 7fe092cccd..f962070c36 100644 --- a/tests/topotests/ldp-topo1/r2/ip_mpls_route.ref +++ b/tests/topotests/ldp-topo1/r2/ip_mpls_route.ref @@ -1,5 +1,3 @@ -xx proto xx - nexthopvia inet 10.0.2.3 dev r2-eth1 weight 1 - nexthopvia inet 10.0.3.3 dev r2-eth2 weight 1 -xx via inet 10.0.1.1 dev r2-eth0 proto xx -xx via inet 10.0.2.4 dev r2-eth1 proto xx +xx proto xx nexthopvia inet 10.0.2.3 dev r2-eth1 nexthopvia inet 10.0.3.3 dev r2-eth2 +xx via inet 10.0.1.1 dev r2-eth0 proto xx +xx via inet 10.0.2.4 dev r2-eth1 proto xx diff --git a/tests/topotests/ldp-topo1/r2/ip_mpls_route.ref-1 b/tests/topotests/ldp-topo1/r2/ip_mpls_route.ref-1 index 7fe092cccd..79c9bb7191 100644 --- a/tests/topotests/ldp-topo1/r2/ip_mpls_route.ref-1 +++ b/tests/topotests/ldp-topo1/r2/ip_mpls_route.ref-1 @@ -1,5 +1,5 @@ -xx proto xx - nexthopvia inet 10.0.2.3 dev r2-eth1 weight 1 - nexthopvia inet 10.0.3.3 dev r2-eth2 weight 1 -xx via inet 10.0.1.1 dev r2-eth0 proto xx -xx via inet 10.0.2.4 dev r2-eth1 proto xx +xx proto xx + nexthopvia inet 10.0.2.3 dev r2-eth1 + nexthopvia inet 10.0.3.3 dev r2-eth2 +xx via inet 10.0.1.1 dev r2-eth0 proto xx +xx via inet 10.0.2.4 dev r2-eth1 proto xx diff --git a/tests/topotests/ldp-topo1/r3/ip_mpls_route.ref b/tests/topotests/ldp-topo1/r3/ip_mpls_route.ref index 2da9e06e53..21750b4a23 100644 --- a/tests/topotests/ldp-topo1/r3/ip_mpls_route.ref +++ b/tests/topotests/ldp-topo1/r3/ip_mpls_route.ref @@ -1,10 +1,4 @@ -xx proto xx - nexthopvia inet 10.0.2.2 dev r3-eth0 weight 1 - nexthopvia inet 10.0.3.2 dev r3-eth1 weight 1 -xx proto xx - nexthopvia inet 10.0.2.2 dev r3-eth0 weight 1 - nexthopvia inet 10.0.3.2 dev r3-eth1 weight 1 -xx proto xx - nexthopvia inet 10.0.2.2 dev r3-eth0 weight 1 - nexthopvia inet 10.0.3.2 dev r3-eth1 weight 1 -xx via inet 10.0.2.4 dev r3-eth0 proto xx +xx proto xx nexthopvia inet 10.0.2.2 dev r3-eth0 nexthopvia inet 10.0.3.2 dev r3-eth1 +xx proto xx nexthopvia inet 10.0.2.2 dev r3-eth0 nexthopvia inet 10.0.3.2 dev r3-eth1 +xx proto xx nexthopvia inet 10.0.2.2 dev r3-eth0 nexthopvia inet 10.0.3.2 dev r3-eth1 +xx via inet 10.0.2.4 dev r3-eth0 proto xx diff --git a/tests/topotests/ldp-topo1/r3/ip_mpls_route.ref-1 b/tests/topotests/ldp-topo1/r3/ip_mpls_route.ref-1 index 2da9e06e53..bffae1e40e 100644 --- a/tests/topotests/ldp-topo1/r3/ip_mpls_route.ref-1 +++ b/tests/topotests/ldp-topo1/r3/ip_mpls_route.ref-1 @@ -1,10 +1,10 @@ -xx proto xx - nexthopvia inet 10.0.2.2 dev r3-eth0 weight 1 - nexthopvia inet 10.0.3.2 dev r3-eth1 weight 1 -xx proto xx - nexthopvia inet 10.0.2.2 dev r3-eth0 weight 1 - nexthopvia inet 10.0.3.2 dev r3-eth1 weight 1 -xx proto xx - nexthopvia inet 10.0.2.2 dev r3-eth0 weight 1 - nexthopvia inet 10.0.3.2 dev r3-eth1 weight 1 -xx via inet 10.0.2.4 dev r3-eth0 proto xx +xx proto xx + nexthopvia inet 10.0.2.2 dev r3-eth0 + nexthopvia inet 10.0.3.2 dev r3-eth1 +xx proto xx + nexthopvia inet 10.0.2.2 dev r3-eth0 + nexthopvia inet 10.0.3.2 dev r3-eth1 +xx proto xx + nexthopvia inet 10.0.2.2 dev r3-eth0 + nexthopvia inet 10.0.3.2 dev r3-eth1 +xx via inet 10.0.2.4 dev r3-eth0 proto xx diff --git a/tests/topotests/ldp-topo1/r4/ip_mpls_route.ref b/tests/topotests/ldp-topo1/r4/ip_mpls_route.ref index 60b3ce1a26..aef2fefd57 100644 --- a/tests/topotests/ldp-topo1/r4/ip_mpls_route.ref +++ b/tests/topotests/ldp-topo1/r4/ip_mpls_route.ref @@ -1,7 +1,5 @@ -xx proto xx - nexthopvia inet 10.0.2.2 dev r4-eth0 weight 1 - nexthopvia inet 10.0.2.3 dev r4-eth0 weight 1 -xx as to xx via inet 10.0.2.2 dev r4-eth0 proto xx -xx via inet 10.0.2.2 dev r4-eth0 proto xx -xx via inet 10.0.2.2 dev r4-eth0 proto xx -xx via inet 10.0.2.3 dev r4-eth0 proto xx +xx proto xx nexthopvia inet 10.0.2.2 dev r4-eth0 nexthopvia inet 10.0.2.3 dev r4-eth0 +xx as to xx via inet 10.0.2.2 dev r4-eth0 proto xx +xx via inet 10.0.2.2 dev r4-eth0 proto xx +xx via inet 10.0.2.2 dev r4-eth0 proto xx +xx via inet 10.0.2.3 dev r4-eth0 proto xx diff --git a/tests/topotests/ldp-topo1/r4/ip_mpls_route.ref-1 b/tests/topotests/ldp-topo1/r4/ip_mpls_route.ref-1 index 60b3ce1a26..f6dae1fad0 100644 --- a/tests/topotests/ldp-topo1/r4/ip_mpls_route.ref-1 +++ b/tests/topotests/ldp-topo1/r4/ip_mpls_route.ref-1 @@ -1,7 +1,7 @@ -xx proto xx - nexthopvia inet 10.0.2.2 dev r4-eth0 weight 1 - nexthopvia inet 10.0.2.3 dev r4-eth0 weight 1 -xx as to xx via inet 10.0.2.2 dev r4-eth0 proto xx -xx via inet 10.0.2.2 dev r4-eth0 proto xx -xx via inet 10.0.2.2 dev r4-eth0 proto xx -xx via inet 10.0.2.3 dev r4-eth0 proto xx +xx proto xx + nexthopvia inet 10.0.2.2 dev r4-eth0 + nexthopvia inet 10.0.2.3 dev r4-eth0 +xx as to xx via inet 10.0.2.2 dev r4-eth0 proto xx +xx via inet 10.0.2.2 dev r4-eth0 proto xx +xx via inet 10.0.2.2 dev r4-eth0 proto xx +xx via inet 10.0.2.3 dev r4-eth0 proto xx diff --git a/tests/topotests/ldp-topo1/test_ldp_topo1.py b/tests/topotests/ldp-topo1/test_ldp_topo1.py index 4a07a99086..9952fd80c8 100755 --- a/tests/topotests/ldp-topo1/test_ldp_topo1.py +++ b/tests/topotests/ldp-topo1/test_ldp_topo1.py @@ -693,62 +693,32 @@ def test_linux_mpls_routes(): expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router - actual = net['r%s' % i].cmd('ip -family mpls route 2> /dev/null').rstrip() - # Mask out label + actual = net['r%s' % i].cmd('ip -o -family mpls route 2> /dev/null').rstrip() + + # Mask out label and protocol actual = re.sub(r"[0-9][0-9] via inet ", "xx via inet ", actual) - actual = re.sub(r"[0-9][0-9] proto", "xx proto", actual) + actual = re.sub(r"[0-9][0-9] +proto", "xx proto", actual) actual = re.sub(r"[0-9][0-9] as to ", "xx as to ", actual) actual = re.sub(r"[ ]+proto \w+", " proto xx", actual) - - # Fix newlines (make them all the same) - actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) - # Sort lines which start with "xx via inet " - pattern = r'^xx via inet ' - swapped = True - while swapped: - swapped = False - for j in range(1, len(actual)): - if re.search(pattern, actual[j]) and re.search(pattern, actual[j-1]): - if actual[j-1] > actual[j]: - temp = actual[j-1] - actual[j-1] = actual[j] - actual[j] = temp - swapped = True + # Sort nexthops + nexthop_sorted = [] + for line in actual.splitlines(): + tokens = re.split(r'\\\t', line.strip()) + nexthop_sorted.append('{} {}'.format( + tokens[0].strip(), + ' '.join([ token.strip() for token in sorted(tokens[1:]) ]) + ).strip()) + + # Sort lines and fixup differences between old and new iproute + actual = '\n'.join(sorted(nexthop_sorted)) + actual = re.sub(r"nexthop via", "nexthopvia", actual) + actual = re.sub(r" nexthop as to xx via inet ", " nexthopvia inet ", actual) + actual = re.sub(r" weight 1", "", actual) + actual = re.sub(r" [ ]+", " ", actual) - # Sort lines which start with " nexthopvia" - pattern = r'^\snexthopvia ' - swapped = True - while swapped: - swapped = False - for j in range(1, len(actual)): - if re.search(pattern, actual[j]) and re.search(pattern, actual[j-1]): - if actual[j-1] > actual[j]: - temp = actual[j-1] - actual[j-1] = actual[j] - actual[j] = temp - swapped = True - - # Sort Sections of "xx proto zebra" (with all the indented lines below) - pattern = r'^xx via inet ' - # Join paragraphs first - j = 0 - temp = [actual[0].rstrip()] - for k in range(1, len(actual)): - if re.search(r'^\s', actual[k]): - # Continue line - temp[j] += '\n' + actual[k].rstrip() - else: - j += 1 - temp.append(actual[k].rstrip()) - # sort Array - temp.sort() - # Now write sort array back - actual = [] - for k in range(0, len(temp)): - actual.extend(temp[k].splitlines()) # put \n back at line ends - actual = ('\n'.join(actual) + '\n').splitlines(1) + actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff diff = topotest.get_textdiff(actual, expected, -- 2.39.5