mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-06 15:58:18 +00:00
lib: cleanup diff text output formatting issue and move to library
Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
This commit is contained in:
parent
4942f29847
commit
17070436a3
@ -30,7 +30,6 @@ test_all_protocol_startup.py: Test of all protocols at same time
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import difflib
|
||||
import pytest
|
||||
from time import sleep
|
||||
|
||||
@ -336,9 +335,9 @@ def test_rip_status():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual IP RIP status",
|
||||
tofile="expected IP RIP status"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual IP RIP status",
|
||||
title2="expected IP RIP status")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -391,9 +390,9 @@ def test_ripng_status():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual IPv6 RIPng status",
|
||||
tofile="expected IPv6 RIPng status"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual IPv6 RIPng status",
|
||||
title2="expected IPv6 RIPng status")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -444,9 +443,9 @@ def test_ospfv2_interfaces():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual SHOW IP OSPF INTERFACE",
|
||||
tofile="expected SHOW IP OSPF INTERFACE"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual SHOW IP OSPF INTERFACE",
|
||||
title2="expected SHOW IP OSPF INTERFACE")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -503,9 +502,9 @@ def test_isis_interfaces():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual SHOW ISIS INTERFACE DETAIL",
|
||||
tofile="expected SHOW ISIS OSPF6 INTERFACE DETAIL"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual SHOW ISIS INTERFACE DETAIL",
|
||||
title2="expected SHOW ISIS OSPF6 INTERFACE DETAIL")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -584,9 +583,9 @@ def test_bgp_summary():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual SHOW IP BGP SUMMARY",
|
||||
tofile="expected SHOW IP BGP SUMMARY"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual SHOW IP BGP SUMMARY",
|
||||
title2="expected SHOW IP BGP SUMMARY")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -666,9 +665,9 @@ def test_bgp_ipv6_summary():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual SHOW BGP IPv6 SUMMARY",
|
||||
tofile="expected SHOW BGP IPv6 SUMMARY"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual SHOW BGP IPv6 SUMMARY",
|
||||
title2="expected SHOW BGP IPv6 SUMMARY")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -719,9 +718,9 @@ def test_bgp_ipv4():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual SHOW BGP IPv4",
|
||||
tofile="expected SHOW BGP IPv4"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual SHOW BGP IPv4",
|
||||
title2="expected SHOW BGP IPv4")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -772,9 +771,9 @@ def test_bgp_ipv6():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual SHOW BGP IPv6",
|
||||
tofile="expected SHOW BGP IPv6"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual SHOW BGP IPv6",
|
||||
title2="expected SHOW BGP IPv6")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -828,9 +827,9 @@ def test_mpls_interfaces():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual MPLS LDP interface status",
|
||||
tofile="expected MPLS LDP interface status"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual MPLS LDP interface status",
|
||||
title2="expected MPLS LDP interface status")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
|
@ -65,7 +65,6 @@ test_bgp_multiview_topo1.py: Simple Quagga/FRR Route-Server Test
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import difflib
|
||||
import pytest
|
||||
from time import sleep
|
||||
|
||||
@ -298,10 +297,9 @@ def test_bgp_routingTable():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual BGP routing table",
|
||||
tofile="expected BGP routing table"))
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual BGP routing table",
|
||||
title2="expected BGP routing table")
|
||||
|
||||
if diff:
|
||||
sys.stderr.write('r%s failed Routing Table Check for view %s:\n%s\n'
|
||||
|
@ -62,7 +62,6 @@ r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import difflib
|
||||
import pytest
|
||||
from time import sleep
|
||||
|
||||
@ -236,9 +235,9 @@ def test_mpls_interfaces():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual MPLS LDP interface status",
|
||||
tofile="expected MPLS LDP interface status"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual MPLS LDP interface status",
|
||||
title2="expected MPLS LDP interface status")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -357,9 +356,9 @@ def test_mpls_ldp_discovery():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual MPLS LDP discovery output",
|
||||
tofile="expected MPLS LDP discovery output"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual MPLS LDP discovery output",
|
||||
title2="expected MPLS LDP discovery output")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -422,9 +421,9 @@ def test_mpls_ldp_neighbor():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual MPLS LDP neighbor output",
|
||||
tofile="expected MPLS LDP neighbor output"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual MPLS LDP neighbor output",
|
||||
title2="expected MPLS LDP neighbor output")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -503,9 +502,9 @@ def test_mpls_ldp_binding():
|
||||
swapped = True
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual MPLS LDP binding output",
|
||||
tofile="expected MPLS LDP binding output"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual MPLS LDP binding output",
|
||||
title2="expected MPLS LDP binding output")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -561,9 +560,9 @@ def test_zebra_ipv4_routingTable():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual IPv4 zebra routing table",
|
||||
tofile="expected IPv4 zera routing table"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual IPv4 zebra routing table",
|
||||
title2="expected IPv4 zebra routing table")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -631,9 +630,9 @@ def test_mpls_table():
|
||||
swapped = True
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual MPLS table output",
|
||||
tofile="expected MPLS table output"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual MPLS table output",
|
||||
title2="expected MPLS table output")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -735,9 +734,9 @@ def test_linux_mpls_routes():
|
||||
actual = ('\n'.join(actual) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual Linux Kernel MPLS route",
|
||||
tofile="expected Linux Kernel MPLS route"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual Linux Kernel MPLS route",
|
||||
title2="expected Linux Kernel MPLS route")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
|
@ -30,6 +30,7 @@ import glob
|
||||
import StringIO
|
||||
import subprocess
|
||||
import platform
|
||||
import difflib
|
||||
|
||||
from mininet.topo import Topo
|
||||
from mininet.net import Mininet
|
||||
@ -73,6 +74,15 @@ def pid_exists(pid):
|
||||
else:
|
||||
return True
|
||||
|
||||
def get_textdiff(text1, text2, title1="", title2=""):
|
||||
"Returns empty string if same or formatted diff"
|
||||
|
||||
diff = '\n'.join(difflib.context_diff(text1, text2,
|
||||
fromfile=title1, tofile=title2))
|
||||
# Clean up line endings
|
||||
diff = os.linesep.join([s for s in diff.splitlines() if s])
|
||||
return diff
|
||||
|
||||
def checkAddressSanitizerError(output, router, component):
|
||||
"Checks for AddressSanitizer in output. If found, then logs it and returns true, false otherwise"
|
||||
|
||||
|
@ -70,29 +70,9 @@ test_ospf6_topo1.py:
|
||||
-----/
|
||||
"""
|
||||
|
||||
# import os
|
||||
# import re
|
||||
# import sys
|
||||
# import difflib
|
||||
# import StringIO
|
||||
# import glob
|
||||
# import subprocess
|
||||
|
||||
# from mininet.topo import Topo
|
||||
# from mininet.net import Mininet
|
||||
# from mininet.node import Node, OVSSwitch, Host
|
||||
# from mininet.log import setLogLevel, info
|
||||
# from mininet.cli import CLI
|
||||
|
||||
# from functools import partial
|
||||
# from time import sleep
|
||||
|
||||
# import pytest
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import difflib
|
||||
import pytest
|
||||
from time import sleep
|
||||
|
||||
@ -295,9 +275,9 @@ def test_ospfv3_routingTable():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual OSPFv3 IPv6 routing table",
|
||||
tofile="expected OSPFv3 IPv6 routing table"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual OSPFv3 IPv6 routing table",
|
||||
title2="expected OSPFv3 IPv6 routing table")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -363,9 +343,9 @@ def test_linux_ipv6_kernel_routingTable():
|
||||
# print(line.rstrip())
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual IPv6 kernel routing table",
|
||||
tofile="expected IPv6 kernel routing table"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual OSPFv3 IPv6 routing table",
|
||||
title2="expected OSPFv3 IPv6 routing table")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
|
@ -30,7 +30,6 @@ test_rip_topo1.py: Testing RIPv2
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import difflib
|
||||
import pytest
|
||||
from time import sleep
|
||||
|
||||
@ -213,9 +212,9 @@ def test_rip_status():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual IP RIP status",
|
||||
tofile="expected IP RIP status"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual IP RIP status",
|
||||
title2="expected IP RIP status")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -265,9 +264,9 @@ def test_rip_routes():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual SHOW IP RIP",
|
||||
tofile="expected SHOW IP RIP"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual SHOW IP RIP",
|
||||
title2="expected SHOW IP RIP")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -317,9 +316,9 @@ def test_zebra_ipv4_routingTable():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual Zebra IPv4 routing table",
|
||||
tofile="expected Zebra IPv4 routing table"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual Zebra IPv4 routing table",
|
||||
title2="expected Zebra IPv4 routing table")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
|
@ -30,7 +30,6 @@ test_ripng_topo1.py: Test of RIPng Topology
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import difflib
|
||||
import pytest
|
||||
import unicodedata
|
||||
from time import sleep
|
||||
@ -216,9 +215,9 @@ def test_ripng_status():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual IPv6 RIPng status",
|
||||
tofile="expected IPv6 RIPng status"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual IPv6 RIPng status",
|
||||
title2="expected IPv6 RIPng status")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -273,9 +272,9 @@ def test_ripng_routes():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual SHOW IPv6 RIPng",
|
||||
tofile="expected SHOW IPv6 RIPng"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual SHOW IPv6 RIPng",
|
||||
title2="expected SHOW IPv6 RIPng")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
@ -327,9 +326,9 @@ def test_zebra_ipv6_routingTable():
|
||||
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
|
||||
|
||||
# Generate Diff
|
||||
diff = ''.join(difflib.context_diff(actual, expected,
|
||||
fromfile="actual Zebra IPv6 routing table",
|
||||
tofile="expected Zebra IPv6 routing table"))
|
||||
diff = topotest.get_textdiff(actual, expected,
|
||||
title1="actual Zebra IPv6 routing table",
|
||||
title2="expected Zebra IPv6 routing table")
|
||||
|
||||
# Empty string if it matches, otherwise diff contains unified diff
|
||||
if diff:
|
||||
|
Loading…
Reference in New Issue
Block a user