]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: cleanup diff text output formatting issue and move to library
authorMartin Winter <mwinter@opensourcerouting.org>
Wed, 31 May 2017 02:39:21 +0000 (19:39 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 28 Nov 2018 01:22:11 +0000 (20:22 -0500)
Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
tests/topotests/all-protocol-startup/test_all_protocol_startup.py
tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py
tests/topotests/ldp-topo1/test_ldp_topo1.py
tests/topotests/lib/topotest.py
tests/topotests/ospf6-topo1/test_ospf6_topo1.py
tests/topotests/rip-topo1/test_rip_topo1.py
tests/topotests/ripng-topo1/test_ripng_topo1.py

index 6e2f12ac5d34d87a8c0a9d4a7ce3facdb7447eb1..bbec24a0b4e3872cba16aaa32810d71e3b3dc63e 100755 (executable)
@@ -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:
index d7c350f5e58afc84d2daa04842f3d1ecbca52cef..d850787fa401cdc73f649ae90033d0222e63ac5f 100755 (executable)
@@ -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' 
index af2bae185387730284f6d6e5f448cc30be672a89..82ee80fc24b6efed454b9c62b23563d9c4f9276a 100755 (executable)
@@ -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:
index b3cff8ca7d8e05fcc90ed4da2228f9f1fb46ae63..6572bc3390455a58c6c6af35395e8df7e7dffcfe 100644 (file)
@@ -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"
 
index 90489e4beca84df1200174bd7eeca2ac28606df4..8c2b80382dd5396cbff44a2548c0c843a58062a2 100755 (executable)
@@ -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:
index 60b43ee42ebaaca0e7a8995976e9f265d003098f..44be48c7026cec72c890f431c408d80aa5cc0e1f 100755 (executable)
@@ -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:
index e790808e3bed606d389fc25761155adaf2b27d1a..518f4e13e637bbb1828ba6a95417698ec495ca20 100755 (executable)
@@ -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: