def test_bgp_ipv6(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying BGP IPv6") print("******************************************\n") diffresult = {} for i in range(1, 2): success = 0 for refTableFile in (glob.glob('%s/r%s/show_bgp_ipv6*.ref' % (thisDir, i))): if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd( 'vtysh -c "show bgp ipv6" 2> /dev/null').rstrip() # Remove summary line (changed recently) actual = re.sub(r'Total number.*', '', actual) actual = re.sub(r'Displayed.*', '', actual) actual = actual.rstrip() # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: diffresult[refTableFile] = diff else: success = 1 print("template %s matched: r%s ok" % (refTableFile, i)) if not success: resultstr = 'No template matched.\n' for f in diffresult.iterkeys(): resultstr += ( 'template %s: r%s failed SHOW BGP IPv6 check:\n%s\n' % (f, i, diffresult[f])) raise AssertionError("SHOW BGP IPv6 failed for router r%s:\n%s" % (i, resultstr)) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_zebra_ipv4_routingTable(): global fatal_error global net global cli_version # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify OSPFv3 Routing Table print("\n\n** Verifying Zebra IPv4 Routing Table") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = '%s/r%s/show_ipv4_route.ref%s' % (thisDir, i, cli_version) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd( 'vtysh -c "show ip route" 2> /dev/null | grep "^O"').rstrip() # Drop timers on end of line (older Quagga Versions) actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual) # Mask out label actual = re.sub(r" label [0-9]+", " label xxx", actual) # Add missing comma before label (for old version) actual = re.sub(r"([0-9]) label xxx", r"\1, label xxx", actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write( 'r%s failed IPv4 Zebra Routing Table Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "IPv4 Zebra Routing Table verification failed for router r%s:\n%s" % ( i, diff) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_route_map(): global fatal_error global net if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying some basic routemap forward references\n") print("*******************************************************\n") failures = 0 for i in range(1, 2): refroutemap = '%s/r%s/show_route_map.ref' % (thisDir, i) if os.path.isfile(refroutemap): expected = open(refroutemap).read().rstrip() expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) actual = net['r%s' %i].cmd('vtysh -c "show route-map" 2> /dev/null').rstrip() actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) diff = topotest.get_textdiff(actual, expected, title1="actual show route-map", title2="expected show route-map") if diff: sys.stderr.write('r%s failed show route-map command Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" %i) assert failures == 0, "Show route-map command failed for router r%s:\n%s" % (i, diff)
def test_mpls_interfaces(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) # Skip if no LDP installed or old kernel if (net['r1'].daemon_available('ldpd') == False): pytest.skip("No MPLS or kernel < 4.5") thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying MPLS Interfaces") print("******************************************\n") failures = 0 for i in range(1, 2): refTableFile = '%s/r%s/show_mpls_ldp_interface.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd( 'vtysh -c "show mpls ldp interface" 2> /dev/null').rstrip() # Mask out Timer in Uptime actual = re.sub(r" [0-9][0-9]:[0-9][0-9]:[0-9][0-9] ", " xx:xx:xx ", actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write( 'r%s failed MPLS LDP Interface status Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) if failures > 0: fatal_error = "MPLS LDP Interface status failed" assert failures == 0, "MPLS LDP Interface status failed for router r%s:\n%s" % ( i, diff) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_mpls_ldp_neighbor(): global fatal_error global net global cli_version # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify OSPFv3 Routing Table print("\n\n** Verifying MPLS LDP neighbor") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = '%s/r%s/show_mpls_ldp_neighbor.ref%s' % (thisDir, i, cli_version) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show mpls ldp neighbor" 2> /dev/null').rstrip() # Mask out changing parts in output if cli_version == "-1": # Mask out Timer in Uptime actual = re.sub(r"Up time: [0-9][0-9]:[0-9][0-9]:[0-9][0-9]", "Up time: xx:xx:xx", actual) # Mask out Port numbers in TCP connection actual = re.sub(r"TCP connection: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]):[0-9]+ - ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]):[0-9]+", r"TCP connection: \1:xxx - \2:xxx", actual) else: # Current Version # # Mask out Timer in Uptime actual = re.sub(r"(ipv4 [0-9\.]+ +OPERATIONAL [0-9\.]+ +)[0-9][0-9]:[0-9][0-9]:[0-9][0-9]", r"\1xx:xx:xx", actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed MPLS LDP neighbor output Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "MPLS LDP Interface neighbor output for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_mpls_ldp_discovery(): global fatal_error global net # Skip if previous fatal error condition is raised if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify MPLS LDP discovery print("\n\n** Verifying MPLS LDP discovery") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = "%s/r%s/show_mpls_ldp_discovery.ref" % (thisDir, i) if os.path.isfile(refTableFile): # Actual output from router actual = (net["r%s" % i].cmd( 'vtysh -c "show mpls ldp discovery" 2> /dev/null').rstrip()) # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) # Actual output from router actual = (net["r%s" % i].cmd( 'vtysh -c "show mpls ldp discovery" 2> /dev/null').rstrip()) # Fix newlines (make them all the same) actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff 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: sys.stderr.write( "r%s failed MPLS LDP discovery output Check:\n%s\n" % (i, diff)) failures += 1 else: print("r%s ok" % i) assert ( failures == 0 ), "MPLS LDP Interface discovery output for router r%s:\n%s" % ( i, diff) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_ospfv2_interfaces(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying OSPFv2 interfaces") print("******************************************\n") failures = 0 for i in range(1, 2): refTableFile = '%s/r%s/show_ip_ospf_interface.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show ip ospf interface" 2> /dev/null').rstrip() # Mask out Bandwidth portion. They may change.. actual = re.sub(r"BW [0-9]+ Mbit", "BW XX Mbit", actual) actual = re.sub(r"ifindex [0-9]", "ifindex X", actual) # Drop time in next due actual = re.sub(r"Hello due in [0-9\.]+s", "Hello due in XX.XXXs", actual) actual = re.sub(r"Hello due in [0-9\.]+ usecs", "Hello due in XX.XXXs", actual) # Fix 'MTU mismatch detection: enabled' vs 'MTU mismatch detection:enabled' - accept both actual = re.sub(r"MTU mismatch detection:([a-z]+.*)", r"MTU mismatch detection: \1", actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed SHOW IP OSPF INTERFACE check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) # Ignoring the issue if told to ignore (ie not yet fixed) if (failures != 0): if (os.environ.get('bamboo_TOPOTESTS_ISSUE_348') == "IGNORE"): sys.stderr.write('Known issue - IGNORING. See https://github.com/FRRouting/frr/issues/348\n') pytest.skip('Known issue - IGNORING. See https://github.com/FRRouting/frr/issues/348') assert failures == 0, "SHOW IP OSPF INTERFACE failed for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_isis_interfaces(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying ISIS interfaces") print("******************************************\n") failures = 0 for i in range(1, 2): refTableFile = '%s/r%s/show_isis_interface_detail.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd( 'vtysh -c "show isis interface detail" 2> /dev/null').rstrip() # Mask out Link-Local mac address portion. They are random... actual = re.sub(r"fe80::[0-9a-f:]+", "fe80::XXXX:XXXX:XXXX:XXXX", actual) # Mask out SNPA mac address portion. They are random... actual = re.sub(r"SNPA: [0-9a-f\.]+", "SNPA: XXXX.XXXX.XXXX", actual) # Mask out Circuit ID number actual = re.sub(r"Circuit Id: 0x[0-9]+", "Circuit Id: 0xXX", actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write( 'r%s failed SHOW ISIS INTERFACE DETAIL check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "SHOW ISIS INTERFACE DETAIL failed for router r%s:\n%s" % ( i, diff) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_zebra_ipv6_routingTable(): global fatal_error global net # Skip if previous fatal error condition is raised if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify OSPFv3 Routing Table print("\n\n** Verifying Zebra IPv6 Routing Table") print("******************************************\n") failures = 0 for i in range(1, 4): refTableFile = "%s/r%s/show_ipv6_route.ref" % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) # Actual output from router actual = (net["r%s" % i].cmd( 'vtysh -c "show ipv6 route" 2> /dev/null | grep "^R"').rstrip( )) # Mask out Link-Local mac address portion. They are random... actual = re.sub(r" fe80::[0-9a-f:]+", " fe80::XXXX:XXXX:XXXX:XXXX", actual) # Drop timers on end of line (older Quagga Versions) actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual) # Fix newlines (make them all the same) actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff 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: sys.stderr.write( "r%s failed Zebra IPv6 Routing Table Check:\n%s\n" % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, ( "Zebra IPv6 Routing Table verification failed for router r%s:\n%s" % (i, diff)) # Make sure that all daemons are running for i in range(1, 4): fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_ospfv2_interfaces(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying OSPFv2 interfaces") print("******************************************\n") failures = 0 for i in range(1, 2): refTableFile = '%s/r%s/show_ip_ospf_interface.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show ip ospf interface" 2> /dev/null').rstrip() # Mask out Bandwidth portion. They may change.. actual = re.sub(r"BW [0-9]+ Mbit", "BW XX Mbit", actual) actual = re.sub(r"ifindex [0-9]", "ifindex X", actual) # Drop time in next due actual = re.sub(r"Hello due in [0-9\.]+s", "Hello due in XX.XXXs", actual) # Fix 'MTU mismatch detection: enabled' vs 'MTU mismatch detection:enabled' - accept both actual = re.sub(r"MTU mismatch detection:([a-z]+.*)", r"MTU mismatch detection: \1", actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed SHOW IP OSPF INTERFACE check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) # Ignoring the issue if told to ignore (ie not yet fixed) if (failures != 0): if (os.environ.get('bamboo_TOPOTESTS_ISSUE_348') == "IGNORE"): sys.stderr.write('Known issue - IGNORING. See https://github.com/FRRouting/frr/issues/348\n') pytest.skip('Known issue - IGNORING. See https://github.com/FRRouting/frr/issues/348') assert failures == 0, "SHOW IP OSPF INTERFACE failed for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_bgp_ipv4(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying BGP IPv4") print("******************************************\n") diffresult = {} for i in range(1, 2): success = 0 for refTableFile in (glob.glob( '%s/r%s/show_bgp_ipv4*.ref' % (thisDir, i))): if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show bgp ipv4" 2> /dev/null').rstrip() # Remove summary line (changed recently) actual = re.sub(r'Total number.*', '', actual) actual = re.sub(r'Displayed.*', '', actual) actual = actual.rstrip() # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: diffresult[refTableFile] = diff else: success = 1 print("template %s matched: r%s ok" % (refTableFile, i)) break if not success: resultstr = 'No template matched.\n' for f in diffresult.iterkeys(): resultstr += ( 'template %s: r%s failed SHOW BGP IPv4 check:\n%s\n' % (f, i, diffresult[f])) raise AssertionError( "SHOW BGP IPv4 failed for router r%s:\n%s" % (i, resultstr)) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_ripng_routes(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify RIPng Status print("\n\n** Verifying RIPng routes") print("******************************************\n") failures = 0 for i in range(1, 4): refTableFile = '%s/r%s/show_ipv6_ripng.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd( 'vtysh -c "show ipv6 ripng" 2> /dev/null').rstrip() # Drop Time actual = re.sub(r" [0-9][0-9]:[0-5][0-9]", " XX:XX", actual) # Mask out Link-Local mac address portion. They are random... actual = re.sub(r" fe80::[0-9a-f: ]+", " fe80::XXXX:XXXX:XXXX:XXXX ", actual) # Remove trailing spaces on all lines actual = '\n'.join([line.rstrip() for line in actual.splitlines()]) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed SHOW IPv6 RIPng check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "SHOW IPv6 RIPng failed for router r%s:\n%s" % ( i, diff) # Make sure that all daemons are running for i in range(1, 4): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def check_sharp_map_correct_runs(): actual = r1.vtysh_cmd("show route-map sharp") actual = ("\n".join(actual.splitlines()) + "\n").rstrip() return topotest.get_textdiff( actual, expected, title1="Actual Route-map output", title2="Expected Route-map output", )
def test_bgp_routingTable(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying BGP Routing Tables") print("******************************************\n") failures = 0 for i in range(1, 2): for view in range(1, 4): refTableFile = '%s/r%s/show_ip_bgp_view_%s.ref' % (thisDir, i, view) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show ip bgp view %s" 2> /dev/null' % view).rstrip() # Fix inconsitent spaces between 0.99.24 and newer versions of Quagga... actual = re.sub('0 0', '0 0', actual) actual = re.sub(r'([0-9]) 32768', r'\1 32768', actual) # Remove summary line (changed recently) actual = re.sub(r'Total number.*', '', actual) actual = re.sub(r'Displayed.*', '', actual) actual = actual.rstrip() # Fix table version (ignore it) actual = re.sub(r'(BGP table version is )[0-9]+', r'\1XXX', actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate 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' % (i, view, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "Routing Table verification failed for router r%s, view %s:\n%s" % (i, view, diff) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_rip_status(): global fatal_error global net # Skip if previous fatal error condition is raised if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify RIP Status print("\n\n** Verifing RIP status") print("******************************************\n") failures = 0 for i in range(1, 4): refTableFile = "%s/r%s/rip_status.ref" % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) # Actual output from router actual = (net["r%s" % i].cmd( 'vtysh -c "show ip rip status" 2> /dev/null').rstrip()) # Drop time in next due actual = re.sub(r"in [0-9]+ seconds", "in XX seconds", actual) # Drop time in last update actual = re.sub(r" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual) # Fix newlines (make them all the same) actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff 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: sys.stderr.write("r%s failed IP RIP status check:\n%s\n" % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "IP RIP status failed for router r%s:\n%s" % ( i, diff) # Make sure that all daemons are still running for i in range(1, 4): fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_mpls_interfaces(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) # Skip if no LDP installed or old kernel if (net['r1'].daemon_available('ldpd') == False): pytest.skip("No MPLS or kernel < 4.5") thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying MPLS Interfaces") print("******************************************\n") failures = 0 for i in range(1, 2): refTableFile = '%s/r%s/show_mpls_ldp_interface.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show mpls ldp interface" 2> /dev/null').rstrip() # Mask out Timer in Uptime actual = re.sub(r" [0-9][0-9]:[0-9][0-9]:[0-9][0-9] ", " xx:xx:xx ", actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed MPLS LDP Interface status Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) if failures>0: fatal_error = "MPLS LDP Interface status failed" assert failures == 0, "MPLS LDP Interface status failed for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_bgp_ipv6(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying BGP IPv6") print("******************************************\n") failures = 0 for i in range(1, 2): refTableFile = '%s/r%s/show_bgp_ipv6.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd( 'vtysh -c "show bgp ipv6" 2> /dev/null').rstrip() # Remove summary line (changed recently) actual = re.sub(r'Total number.*', '', actual) actual = re.sub(r'Displayed.*', '', actual) actual = actual.rstrip() # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed SHOW BGP IPv6 check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "SHOW BGP IPv6 failed for router r%s:\n%s" % ( i, diff) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_ripng_routes(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify RIPng Status print("\n\n** Verifying RIPng routes") print("******************************************\n") failures = 0 for i in range(1, 4): refTableFile = '%s/r%s/show_ipv6_ripng.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show ipv6 ripng" 2> /dev/null').rstrip() # Drop Time actual = re.sub(r" [0-9][0-9]:[0-5][0-9]", " XX:XX", actual) # Mask out Link-Local mac address portion. They are random... actual = re.sub(r" fe80::[0-9a-f: ]+", " fe80::XXXX:XXXX:XXXX:XXXX ", actual) # Remove trailing spaces on all lines actual = '\n'.join([line.rstrip() for line in actual.splitlines()]) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed SHOW IPv6 RIPng check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "SHOW IPv6 RIPng failed for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 4): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_isis_interfaces(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying ISIS interfaces") print("******************************************\n") failures = 0 for i in range(1, 2): refTableFile = '%s/r%s/show_isis_interface_detail.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show isis interface detail" 2> /dev/null').rstrip() # Mask out Link-Local mac address portion. They are random... actual = re.sub(r"fe80::[0-9a-f:]+", "fe80::XXXX:XXXX:XXXX:XXXX", actual) # Mask out SNPA mac address portion. They are random... actual = re.sub(r"SNPA: [0-9a-f\.]+", "SNPA: XXXX.XXXX.XXXX", actual) # Mask out Circuit ID number actual = re.sub(r"Circuit Id: 0x[0-9]+", "Circuit Id: 0xXX", actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed SHOW ISIS INTERFACE DETAIL check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "SHOW ISIS INTERFACE DETAIL failed for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_mpls_ldp_discovery(): global fatal_error global net global cli_version # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify OSPFv3 Routing Table print("\n\n** Verifying MPLS LDP discovery") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = '%s/r%s/show_mpls_ldp_discovery.ref%s' % (thisDir, i, cli_version) if os.path.isfile(refTableFile): # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show mpls ldp discovery" 2> /dev/null').rstrip() # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show mpls ldp discovery" 2> /dev/null').rstrip() # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed MPLS LDP discovery output Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "MPLS LDP Interface discovery output for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_ospfv3_routingTable(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify OSPFv3 Routing Table print("\n\n** Verifying OSPFv3 Routing Table") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = '%s/r%s/show_ipv6_route.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show ipv6 route" 2> /dev/null | grep "^O"').rstrip() # Mask out Link-Local mac address portion. They are random... actual = re.sub(r" fe80::[0-9a-f:]+", " fe80::XXXX:XXXX:XXXX:XXXX", actual) # Drop timers on end of line (older Quagga Versions) actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed OSPFv3 (IPv6) Routing Table Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "OSPFv3 (IPv6) Routing Table verification failed for router r%s:\n%s" % (i, diff) # Make sure that all daemons are still running for i in range(1, 5): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_rip_status(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify RIP Status print("\n\n** Verifing RIP status") print("******************************************\n") failures = 0 for i in range(1, 4): refTableFile = '%s/r%s/rip_status.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show ip rip status" 2> /dev/null').rstrip() # Drop time in next due actual = re.sub(r"in [0-9]+ seconds", "in XX seconds", actual) # Drop time in last update actual = re.sub(r" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed IP RIP status check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "IP RIP status failed for router r%s:\n%s" % (i, diff) # Make sure that all daemons are still running for i in range(1, 4): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def check_routes_installed(): actual = r1.run("ip route show") actual = ("\n".join(actual.splitlines()) + "\n").rstrip() actual = re.sub(r" nhid [0-9][0-9]", "", actual) actual = re.sub(r" proto sharp", " proto XXXX", actual) actual = re.sub(r" proto static", " proto XXXX", actual) actual = re.sub(r" proto 194", " proto XXXX", actual) actual = re.sub(r" proto 196", " proto XXXX", actual) actual = re.sub(r" proto kernel", " proto XXXX", actual) actual = re.sub(r" proto 2", " proto XXXX", actual) # Some platforms have double spaces? Why?????? actual = re.sub(r" proto XXXX ", " proto XXXX ", actual) actual = re.sub(r" metric", " metric", actual) actual = re.sub(r" link ", " link ", actual) return topotest.get_textdiff( actual, expected, title1="Actual ip route show", title2="Expected ip route show", )
def test_linux_mpls_routes(): global fatal_error global net global cli_version # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify OSPFv3 Routing Table print("\n\n** Verifying Linux Kernel MPLS routes") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = '%s/r%s/ip_mpls_route.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router 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] as to ", "xx as to ", actual) actual = re.sub(r"[ ]+proto \w+", " proto xx", actual) # 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) # put \n back at line ends actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed Linux Kernel MPLS route output Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "Linux Kernel MPLS route output for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_linux_mpls_routes(): global fatal_error global net # Skip if previous fatal error condition is raised if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify Linux Kernel MPLS routes print("\n\n** Verifying Linux Kernel MPLS routes") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = "%s/r%s/ip_mpls_route.ref" % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) # Actual output from router 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] as to ", "xx as to ", actual) actual = re.sub(r"[ ]+proto \w+", " proto xx", actual) # 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) # put \n back at line ends actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff 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: sys.stderr.write( "r%s failed Linux Kernel MPLS route output Check:\n%s\n" % (i, diff)) failures += 1 else: print("r%s ok" % i) assert ( failures == 0 ), "Linux Kernel MPLS route output for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_mpls_table(): global fatal_error global net # Skip if previous fatal error condition is raised if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify MPLS table print("\n\n** Verifying MPLS table") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = "%s/r%s/show_mpls_table.ref" % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read() # Fix newlines (make them all the same) expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) # Actual output from router actual = net["r%s" % i].cmd('vtysh -c "show mpls table" 2> /dev/null') # Fix inconsistent Label numbers at beginning of line actual = re.sub(r"(\s+)[0-9]+(\s+LDP)", r"\1XX\2", actual) # Fix inconsistent Label numbers at end of line actual = re.sub( r"(\s+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s+)[0-9][0-9]", r"\1XX", actual) # Fix newlines (make them all the same) actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Sort lines which start with " XX LDP" pattern = r"^\s+[0-9X]+\s+LDP" 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 # Generate Diff 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: sys.stderr.write("r%s failed MPLS table output Check:\n%s\n" % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "MPLS table output for router r%s:\n%s" % ( i, diff) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_zebra_ipv4_routingTable(): global fatal_error global net # Skip if previous fatal error condition is raised if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify Zebra IPv4 Routing Table print("\n\n** Verifying Zebra IPv4 Routing Table") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = "%s/r%s/show_ipv4_route.ref" % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Actual output from router actual = (net["r%s" % i].cmd( 'vtysh -c "show ip route" 2> /dev/null | grep "^O"').rstrip()) # Drop timers on end of line (older Quagga Versions) actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual) # Mask out label - all LDP labels should be >= 10 (2-digit) # leaving the implicit labels unmasked actual = re.sub(r" label [0-9][0-9]+", " label xxx", actual) # and translating remaining implicit (single-digit) labels to label implicit-null actual = re.sub(r" label [0-9]+", " label implicit-null", actual) # Check if we have implicit labels - if not, then remove them from reference if not re.search(r" label implicit-null", actual): expected = re.sub(r", label implicit-null", "", expected) # now fix newlines of expected (make them all the same) expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) # Fix newlines (make them all the same) actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff 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: sys.stderr.write( "r%s failed IPv4 Zebra Routing Table Check:\n%s\n" % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, ( "IPv4 Zebra Routing Table verification failed for router r%s:\n%s" % (i, diff)) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_mpls_ldp_binding(): global fatal_error global net # Skip this test for now until proper sorting of the output # is implemented # pytest.skip("Skipping test_mpls_ldp_binding") # Skip if previous fatal error condition is raised if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify MPLS LDP binding print("\n\n** Verifying MPLS LDP binding") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = "%s/r%s/show_mpls_ldp_binding.ref" % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) # Actual output from router actual = (net["r%s" % i].cmd( 'vtysh -c "show mpls ldp binding" 2> /dev/null').rstrip()) # Mask out changing parts in output # Mask out label actual = re.sub(r"(ipv4 [0-9\./]+ +[0-9\.]+ +)[0-9][0-9] (.*)", r"\1xxx\2", actual) actual = re.sub( r"(ipv4 [0-9\./]+ +[0-9\.]+ +[a-z\-]+ +)[0-9][0-9] (.*)", r"\1xxx\2", 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"^\s+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s+" 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 # Generate Diff 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: sys.stderr.write( "r%s failed MPLS LDP binding output Check:\n%s\n" % (i, diff)) failures += 1 else: print("r%s ok" % i) assert ( failures == 0 ), "MPLS LDP Interface binding output for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_bgp_routingTable(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying BGP Routing Tables") print("******************************************\n") diffresult = {} for i in range(1, 2): for view in range(1, 4): success = 0 # This glob pattern should work as long as number of views < 10 for refTableFile in (glob.glob( '%s/r%s/show_ip_bgp_view_%s*.ref' % (thisDir, i, view))): if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show ip bgp view %s" 2> /dev/null' % view).rstrip() # Fix inconsitent spaces between 0.99.24 and newer versions of Quagga... actual = re.sub('0 0', '0 0', actual) actual = re.sub(r'([0-9]) 32768', r'\1 32768', actual) # Remove summary line (changed recently) actual = re.sub(r'Total number.*', '', actual) actual = re.sub(r'Displayed.*', '', actual) actual = actual.rstrip() # Fix table version (ignore it) actual = re.sub(r'(BGP table version is )[0-9]+', r'\1XXX', actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff diff = topotest.get_textdiff(actual, expected, title1="actual BGP routing table", title2="expected BGP routing table") if diff: diffresult[refTableFile] = diff else: success = 1 print("template %s matched: r%s ok" % (refTableFile, i)) break; if not success: resultstr = 'No template matched.\n' for f in diffresult.iterkeys(): resultstr += ( 'template %s: r%s failed Routing Table Check for view %s:\n%s\n' % (f, i, view, diffresult[f])) raise AssertionError( "Routing Table verification failed for router r%s, view %s:\n%s" % (i, view, resultstr)) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_linux_ipv6_kernel_routingTable(): # Required linux kernel version for this suite to run. result = required_linux_kernel_version("4.15") if result is not True: pytest.skip("Kernel requirements are not met") # iproute2 needs to support VRFs for this suite to run. if not iproute2_is_vrf_capable(): pytest.skip("Installed iproute2 version does not support VRFs") tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip("skipped because of router(s) failure") # Verify Linux Kernel Routing Table logger.info("Verifying Linux IPv6 Kernel Routing Table") failures = 0 # Get a list of all current link-local addresses first as they change for # each run and we need to translate them linklocals = [] for i in range(1, 5): linklocals += tgen.net["r{}".format(i)].get_ipv6_linklocal() # Now compare the routing tables (after substituting link-local addresses) for i in range(1, 5): # Actual output from router actual = tgen.gears["r{}".format(i)].run( "ip -6 route show vrf r{}-cust1".format(i)).rstrip() if "nhid" in actual: refTableFile = os.path.join(CWD, "r{}/ip_6_address.nhg.ref".format(i)) else: refTableFile = os.path.join(CWD, "r{}/ip_6_address.ref".format(i)) if os.path.isfile(refTableFile): expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ("\n".join(expected.splitlines())).splitlines(1) # Mask out Link-Local mac addresses for ll in linklocals: actual = actual.replace(ll[1], "fe80::__(%s)__" % ll[0]) # Mask out protocol name or number actual = re.sub(r"[ ]+proto [0-9a-z]+ +", " proto XXXX ", actual) actual = re.sub(r"[ ]+nhid [0-9]+ +", " nhid XXXX ", actual) # Remove ff00::/8 routes (seen on some kernels - not from FRR) actual = re.sub(r"ff00::/8.*", "", actual) # Strip empty lines actual = actual.lstrip() actual = actual.rstrip() actual = re.sub(r" +", " ", actual) filtered_lines = [] for line in sorted(actual.splitlines()): if line.startswith("fe80::/64 ") or line.startswith( "unreachable fe80::/64 "): continue if 'anycast' in line: continue if 'multicast' in line: continue filtered_lines.append(line) actual = "\n".join(filtered_lines).splitlines(1) # Print Actual table # logger.info("Router r%s table" % i) # for line in actual: # logger.info(line.rstrip()) # Generate Diff 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: sys.stderr.write( "r%s failed Linux IPv6 Kernel Routing Table Check:\n%s\n" % (i, diff)) failures += 1 else: logger.info("r%s ok" % i) assert failures == 0, ( "Linux Kernel IPv6 Routing Table verification failed for router r%s:\n%s" % (i, diff))
def test_zebra_ipv4_routingTable(): global fatal_error global net global cli_version # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify OSPFv3 Routing Table print("\n\n** Verifying Zebra IPv4 Routing Table") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = '%s/r%s/show_ipv4_route.ref%s' % (thisDir, i, cli_version) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show ip route" 2> /dev/null | grep "^O"').rstrip() # Drop timers on end of line (older Quagga Versions) actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual) # Mask out label - all LDP labels should be >= 10 (2-digit) # leaving the implicit labels unmasked actual = re.sub(r" label [0-9][0-9]+", " label xxx", actual) # and translating remaining implicit (single-digit) labels to label implicit-null actual = re.sub(r" label [0-9]+", " label implicit-null", actual) # Check if we have implicit labels - if not, then remove them from reference if (not re.search(r" label implicit-null", actual)): expected = re.sub(r", label implicit-null", "", expected) # now fix newlines of expected (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Add missing comma before label (for old version) actual = re.sub(r"([0-9]) label ", r"\1, label ", actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed IPv4 Zebra Routing Table Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "IPv4 Zebra Routing Table verification failed for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_linux_ipv6_kernel_routingTable(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify Linux Kernel Routing Table print("\n\n** Verifying Linux IPv6 Kernel Routing Table") print("******************************************\n") failures = 0 # Get a list of all current link-local addresses first as they change for # each run and we need to translate them linklocals = [] for i in range(1, 5): linklocals += net['r%s' % i].get_ipv6_linklocal() # Now compare the routing tables (after substituting link-local addresses) for i in range(1, 5): refTableFile = '%s/r%s/ip_6_address.ref' % (thisDir, i) if os.path.isfile(refTableFile): expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines())).splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('ip -6 route').rstrip() # Mask out Link-Local mac addresses for ll in linklocals: actual = actual.replace(ll[1], "fe80::__(%s)__" % ll[0]) # Mask out protocol name or number actual = re.sub(r" proto [0-9a-z]+ ", " proto XXXX ", actual) # Remove ff00::/8 routes (seen on some kernels - not from FRR) actual = re.sub(r'ff00::/8.*', '', actual) # Strip empty lines actual = actual.lstrip() actual = actual.rstrip() # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines())).splitlines(1) # Print Actual table # print("Router r%s table" % i) # for line in actual: # print(line.rstrip()) # Generate Diff 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: sys.stderr.write( 'r%s failed Linux IPv6 Kernel Routing Table Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "Linux Kernel IPv6 Routing Table verification failed for router r%s:\n%s" % ( i, diff)
def test_converge_protocols(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Waiting for protocols convergence") print("******************************************\n") # Not really implemented yet - just sleep 60 secs for now sleep(60) # Make sure that all daemons are running failures = 0 for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error print("Show that v4 routes are right\n"); v4_routesFile = '%s/r%s/ipv4_routes.ref' % (thisDir, i) expected = open(v4_routesFile).read().rstrip() expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) actual = net['r%s' %i].cmd('vtysh -c "show ip route" | /usr/bin/tail -n +7 | sort 2> /dev/null').rstrip() # Drop time in last update actual = re.sub(r" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) diff = topotest.get_textdiff(actual, expected, title1="Actual IP Routing Table", title2="Expected IP RoutingTable") if diff: sys.stderr.write('r%s failed IP Routing table check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" %i) assert failures == 0, "IP Routing table failed for r%s\n%s" % (i, diff) failures = 0 print("Show that v6 routes are right\n") v6_routesFile = '%s/r%s/ipv6_routes.ref' % (thisDir, i) expected = open(v6_routesFile).read().rstrip() expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) actual = net['r%s' %i].cmd('vtysh -c "show ipv6 route" | /usr/bin/tail -n +7 | sort 2> /dev/null').rstrip() # Drop time in last update actual = re.sub(r" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) diff = topotest.get_textdiff(actual, expected, title1="Actual IPv6 Routing Table", title2="Expected IPv6 RoutingTable") if diff: sys.stderr.write('r%s failed IPv6 Routing table check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" %i) assert failures == 0, "IPv6 Routing table failed for r%s\n%s" % (i, diff)
def test_linux_ipv6_kernel_routingTable(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify Linux Kernel Routing Table print("\n\n** Verifying Linux IPv6 Kernel Routing Table") print("******************************************\n") failures = 0 # Get a list of all current link-local addresses first as they change for # each run and we need to translate them linklocals = [] for i in range(1, 5): linklocals += net['r%s' % i].get_ipv6_linklocal() # Now compare the routing tables (after substituting link-local addresses) for i in range(1, 5): refTableFile = '%s/r%s/ip_6_address.ref' % (thisDir, i) if os.path.isfile(refTableFile): expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines())).splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('ip -6 route').rstrip() # Mask out Link-Local mac addresses for ll in linklocals: actual = actual.replace(ll[1], "fe80::__(%s)__" % ll[0]) # Mask out protocol name or number actual = re.sub(r"[ ]+proto [0-9a-z]+ +", " proto XXXX ", actual) # Remove ff00::/8 routes (seen on some kernels - not from FRR) actual = re.sub(r'ff00::/8.*', '', actual) # Strip empty lines actual = actual.lstrip() actual = actual.rstrip() actual = re.sub(r' +', ' ', actual) filtered_lines = [] for line in sorted(actual.splitlines()): if line.startswith('fe80::/64 ') \ or line.startswith('unreachable fe80::/64 '): continue filtered_lines.append(line) actual = '\n'.join(filtered_lines).splitlines(1) # Print Actual table # print("Router r%s table" % i) # for line in actual: # print(line.rstrip()) # Generate Diff 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: sys.stderr.write('r%s failed Linux IPv6 Kernel Routing Table Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "Linux Kernel IPv6 Routing Table verification failed for router r%s:\n%s" % (i, diff)
def test_mpls_table(): global fatal_error global net global cli_version # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify OSPFv3 Routing Table print("\n\n** Verifying MPLS table") print("******************************************\n") failures = 0 version = cli_version if (version == ""): # check for new output without implicit-null output = net['r1'].cmd('vtysh -c "show mpls table" 2> /dev/null').rstrip() if 'LDP 10.0.1.2 3' in output: version = "-no-impl-null" for i in range(1, 5): refTableFile = '%s/r%s/show_mpls_table.ref%s' % (thisDir, i, version) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show mpls table" 2> /dev/null').rstrip() # Fix inconsistent Label numbers at beginning of line actual = re.sub(r"(\s+)[0-9]+(\s+LDP)", r"\1XX\2", actual) # Fix inconsistent Label numbers at end of line actual = re.sub(r"(\s+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s+)[0-9][0-9]", r"\1XX", actual) # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Sort lines which start with " XX LDP" pattern = r'^\s+[0-9X]+\s+LDP' 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 # Generate Diff 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: sys.stderr.write('r%s failed MPLS table output Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "MPLS table output for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_converge_protocols(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Waiting for protocols convergence") print("******************************************\n") # Not really implemented yet - just sleep 60 secs for now sleep(60) # Make sure that all daemons are running failures = 0 for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error print("Show that v4 routes are right\n") v4_routesFile = '%s/r%s/ipv4_routes.ref' % (thisDir, i) expected = open(v4_routesFile).read().rstrip() expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) actual = net['r%s' % i].cmd( 'vtysh -c "show ip route" | /usr/bin/tail -n +7 | env LC_ALL=en_US.UTF-8 sort 2> /dev/null' ).rstrip() # Drop time in last update actual = re.sub(r" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) diff = topotest.get_textdiff(actual, expected, title1="Actual IP Routing Table", title2="Expected IP RoutingTable") if diff: sys.stderr.write('r%s failed IP Routing table check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "IP Routing table failed for r%s\n%s" % (i, diff) failures = 0 print("Show that v6 routes are right\n") v6_routesFile = '%s/r%s/ipv6_routes.ref' % (thisDir, i) expected = open(v6_routesFile).read().rstrip() expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) actual = net['r%s' % i].cmd( 'vtysh -c "show ipv6 route" | /usr/bin/tail -n +7 | env LC_ALL=en_US.UTF-8 sort 2> /dev/null' ).rstrip() # Drop time in last update actual = re.sub(r" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) diff = topotest.get_textdiff(actual, expected, title1="Actual IPv6 Routing Table", title2="Expected IPv6 RoutingTable") if diff: sys.stderr.write('r%s failed IPv6 Routing table check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "IPv6 Routing table failed for r%s\n%s" % (i, diff)
def test_linux_ipv6_kernel_routingTable(): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip('skipped because of router(s) failure') # Verify Linux Kernel Routing Table logger.info("Verifying Linux IPv6 Kernel Routing Table") failures = 0 # Get a list of all current link-local addresses first as they change for # each run and we need to translate them linklocals = [] for i in range(1, 5): linklocals += tgen.net['r{}'.format(i)].get_ipv6_linklocal() # Now compare the routing tables (after substituting link-local addresses) for i in range(1, 5): # Actual output from router actual = tgen.gears['r{}'.format(i)].run('ip -6 route').rstrip() if "nhid" in actual: refTableFile = os.path.join(CWD, 'r{}/ip_6_address.nhg.ref'.format(i)) else: refTableFile = os.path.join(CWD, 'r{}/ip_6_address.ref'.format(i)) if os.path.isfile(refTableFile): expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines())).splitlines(1) # Mask out Link-Local mac addresses for ll in linklocals: actual = actual.replace(ll[1], "fe80::__(%s)__" % ll[0]) # Mask out protocol name or number actual = re.sub(r"[ ]+proto [0-9a-z]+ +", " proto XXXX ", actual) actual = re.sub(r"[ ]+nhid [0-9]+ +", " nhid XXXX ", actual) # Remove ff00::/8 routes (seen on some kernels - not from FRR) actual = re.sub(r'ff00::/8.*', '', actual) # Strip empty lines actual = actual.lstrip() actual = actual.rstrip() actual = re.sub(r' +', ' ', actual) filtered_lines = [] for line in sorted(actual.splitlines()): if line.startswith('fe80::/64 ') \ or line.startswith('unreachable fe80::/64 '): continue filtered_lines.append(line) actual = '\n'.join(filtered_lines).splitlines(1) # Print Actual table # logger.info("Router r%s table" % i) # for line in actual: # logger.info(line.rstrip()) # Generate Diff 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: sys.stderr.write('r%s failed Linux IPv6 Kernel Routing Table Check:\n%s\n' % (i, diff)) failures += 1 else: logger.info("r%s ok" % i) assert failures == 0, "Linux Kernel IPv6 Routing Table verification failed for router r%s:\n%s" % (i, diff)
def test_bgp_ipv6_summary(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying BGP IPv6 Summary") print("******************************************\n") failures = 0 for i in range(1, 2): refTableFile = '%s/r%s/show_bgp_ipv6_summary.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd( 'vtysh -c "show bgp ipv6 summary" 2> /dev/null').rstrip() # Mask out "using XXiXX bytes" portion. They are random... actual = re.sub(r"using [0-9]+ bytes", "using XXXX bytes", actual) # Mask out "using XiXXX KiB" portion. They are random... actual = re.sub(r"using [0-9]+ KiB", "using XXXX KiB", actual) # # Remove extra summaries which exist with newer versions # # Remove summary lines (changed recently) actual = re.sub(r'Total number.*', '', actual) actual = re.sub(r'Displayed.*', '', actual) # Remove IPv4 Unicast Summary (Title only) actual = re.sub(r'IPv6 Unicast Summary:', '', actual) # Remove IPv4 Multicast Summary (all of it) actual = re.sub(r'IPv6 Multicast Summary:', '', actual) actual = re.sub(r'No IPv6 Multicast neighbor is configured', '', actual) # Remove IPv4 VPN Summary (all of it) actual = re.sub(r'IPv6 VPN Summary:', '', actual) actual = re.sub(r'No IPv6 VPN neighbor is configured', '', actual) # Remove IPv4 Encap Summary (all of it) actual = re.sub(r'IPv6 Encap Summary:', '', actual) actual = re.sub(r'No IPv6 Encap neighbor is configured', '', actual) # Remove Unknown Summary (all of it) actual = re.sub(r'Unknown Summary:', '', actual) actual = re.sub(r'No Unknown neighbor is configured', '', actual) # Remove Labeled Unicast Summary (all of it) actual = re.sub(r'IPv6 labeled-unicast Summary:', '', actual) actual = re.sub(r'No IPv6 labeled-unicast neighbor is configured', '', actual) # Strip empty lines actual = actual.lstrip() actual = actual.rstrip() # # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write( 'r%s failed SHOW BGP IPv6 SUMMARY check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "SHOW BGP IPv6 SUMMARY failed for router r%s:\n%s" % ( i, diff) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_bgp_ipv6_summary(): global fatal_error global net # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying BGP IPv6 Summary") print("******************************************\n") failures = 0 for i in range(1, 2): refTableFile = '%s/r%s/show_bgp_ipv6_summary.ref' % (thisDir, i) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show bgp ipv6 summary" 2> /dev/null').rstrip() # Mask out "using XXiXX bytes" portion. They are random... actual = re.sub(r"using [0-9]+ bytes", "using XXXX bytes", actual) # Mask out "using XiXXX KiB" portion. They are random... actual = re.sub(r"using [0-9]+ KiB", "using XXXX KiB", actual) # # Remove extra summaries which exist with newer versions # # Remove summary lines (changed recently) actual = re.sub(r'Total number.*', '', actual) actual = re.sub(r'Displayed.*', '', actual) # Remove IPv4 Unicast Summary (Title only) actual = re.sub(r'IPv6 Unicast Summary:', '', actual) # Remove IPv4 Multicast Summary (all of it) actual = re.sub(r'IPv6 Multicast Summary:', '', actual) actual = re.sub(r'No IPv6 Multicast neighbor is configured', '', actual) # Remove IPv4 VPN Summary (all of it) actual = re.sub(r'IPv6 VPN Summary:', '', actual) actual = re.sub(r'No IPv6 VPN neighbor is configured', '', actual) # Remove IPv4 Encap Summary (all of it) actual = re.sub(r'IPv6 Encap Summary:', '', actual) actual = re.sub(r'No IPv6 Encap neighbor is configured', '', actual) # Remove Unknown Summary (all of it) actual = re.sub(r'Unknown Summary:', '', actual) actual = re.sub(r'No Unknown neighbor is configured', '', actual) # Remove Labeled Unicast Summary (all of it) actual = re.sub(r'IPv6 labeled-unicast Summary:', '', actual) actual = re.sub(r'No IPv6 labeled-unicast neighbor is configured', '', actual) # Strip empty lines actual = actual.lstrip() actual = actual.rstrip() # # Fix newlines (make them all the same) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) # Generate Diff 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: sys.stderr.write('r%s failed SHOW BGP IPv6 SUMMARY check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "SHOW BGP IPv6 SUMMARY failed for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_linux_mpls_routes(): global fatal_error global net global cli_version # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify OSPFv3 Routing Table print("\n\n** Verifying Linux Kernel MPLS routes") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = '%s/r%s/ip_mpls_route.ref%s' % (thisDir, i, cli_version) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) 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 = 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] 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 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) # Generate Diff 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: sys.stderr.write('r%s failed Linux Kernel MPLS route output Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "Linux Kernel MPLS route output for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_mpls_ldp_binding(): global fatal_error global net global cli_version # Skip this test for now until proper sorting of the output # is implemented # pytest.skip("Skipping test_mpls_ldp_binding") # Skip if previous fatal error condition is raised if (fatal_error != ""): pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) # Verify OSPFv3 Routing Table print("\n\n** Verifying MPLS LDP binding") print("******************************************\n") failures = 0 for i in range(1, 5): refTableFile = '%s/r%s/show_mpls_ldp_binding.ref%s' % (thisDir, i, cli_version) if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) # Actual output from router actual = net['r%s' % i].cmd('vtysh -c "show mpls ldp binding" 2> /dev/null').rstrip() # Mask out changing parts in output if cli_version == "-1": # Mask out label actual = re.sub(r"label: [0-9]+", "label: xxx", actual) actual = re.sub(r"(\s+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[ ]+)[0-9]+", r"\1xxx", actual) else: # Current Version # # Mask out label actual = re.sub(r"(ipv4 [0-9\./]+ +[0-9\.]+ +)[0-9][0-9] (.*)", r"\1xxx\2", actual) actual = re.sub(r"(ipv4 [0-9\./]+ +[0-9\.]+ +[a-z\-]+ +)[0-9][0-9] (.*)", r"\1xxx\2", 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'^\s+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s+' 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 # Generate Diff 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: sys.stderr.write('r%s failed MPLS LDP binding output Check:\n%s\n' % (i, diff)) failures += 1 else: print("r%s ok" % i) assert failures == 0, "MPLS LDP Interface binding output for router r%s:\n%s" % (i, diff) # Make sure that all daemons are running for i in range(1, 5): fatal_error = net['r%s' % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_bgp_routingTable(): global fatal_error global net # Skip if previous fatal error condition is raised if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying BGP Routing Tables") print("******************************************\n") diffresult = {} for i in range(1, 2): for view in range(1, 4): success = 0 # This glob pattern should work as long as number of views < 10 for refTableFile in glob.glob("%s/r%s/show_ip_bgp_view_%s*.ref" % (thisDir, i, view)): if os.path.isfile(refTableFile): # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) # Actual output from router actual = (net["r%s" % i].cmd( 'vtysh -c "show ip bgp view %s" 2> /dev/null' % view).rstrip()) # Fix inconsitent spaces between 0.99.24 and newer versions of Quagga... actual = re.sub("0 0", "0 0", actual) actual = re.sub(r"([0-9]) 32768", r"\1 32768", actual) # Remove summary line (changed recently) actual = re.sub(r"Total number.*", "", actual) actual = re.sub(r"Displayed.*", "", actual) actual = actual.rstrip() # Fix table version (ignore it) actual = re.sub(r"(BGP table version is )[0-9]+", r"\1XXX", actual) # Fix newlines (make them all the same) actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff diff = topotest.get_textdiff( actual, expected, title1="actual BGP routing table", title2="expected BGP routing table", ) if diff: diffresult[refTableFile] = diff else: success = 1 print("template %s matched: r%s ok" % (refTableFile, i)) break if not success: resultstr = "No template matched.\n" for f in diffresult.iterkeys(): resultstr += ( "template %s: r%s failed Routing Table Check for view %s:\n%s\n" % (f, i, view, diffresult[f])) raise AssertionError( "Routing Table verification failed for router r%s, view %s:\n%s" % (i, view, resultstr)) # Make sure that all daemons are running for i in range(1, 2): fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error
def test_route_map_usage(): "Test that FRR only reruns over routes associated with the routemap" logger.info("Test that FRR runs on selected re's on route-map changes") tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip("Skipped because of previous test failure") thisDir = os.path.dirname(os.path.realpath(__file__)) r1 = tgen.gears["r1"] # set the delay timer to 1 to improve test coverage (HA) r1.vtysh_cmd("conf\nzebra route-map delay-timer 1") r1.vtysh_cmd("conf\nroute-map static permit 10\nset src 192.168.215.1") r1.vtysh_cmd("conf\naccess-list 5 seq 5 permit 10.0.0.44/32") r1.vtysh_cmd("conf\naccess-list 10 seq 5 permit 10.0.1.0/24") r1.vtysh_cmd( "conf\nroute-map sharp permit 10\nmatch ip address 10\nset src 192.168.214.1" ) r1.vtysh_cmd("conf\nroute-map sharp permit 20\nset src 192.168.213.1") r1.vtysh_cmd("conf\nip protocol static route-map static") r1.vtysh_cmd("conf\nip protocol sharp route-map sharp") sleep(4) r1.vtysh_cmd("conf\nip route 10.100.100.100/32 192.168.216.3") r1.vtysh_cmd("conf\nip route 10.100.100.101/32 10.0.0.44") r1.vtysh_cmd("sharp install route 10.0.0.0 nexthop 192.168.216.3 500") sleep(4) static_rmapfile = "%s/r1/static_rmap.ref" % (thisDir) expected = open(static_rmapfile).read().rstrip() expected = ('\n'.join(expected.splitlines()) + '\n').rstrip() actual = r1.vtysh_cmd("show route-map static") actual = ('\n'.join(actual.splitlines()) + '\n').rstrip() logger.info( "Does the show route-map static command run the correct number of times" ) diff = topotest.get_textdiff(actual, expected, title1="Actual Route-map output", title2="Expected Route-map output") if diff: logger.info("Actual:") logger.info(actual) logger.info("Expected:") logger.info(expected) srun = r1.vtysh_cmd("show run") srun = ('\n'.join(srun.splitlines()) + '\n').rstrip() logger.info("Show run") logger.info(srun) assert 0, "r1 static route processing:\n" sharp_rmapfile = "%s/r1/sharp_rmap.ref" % (thisDir) expected = open(sharp_rmapfile).read().rstrip() expected = ('\n'.join(expected.splitlines()) + '\n').rstrip() actual = r1.vtysh_cmd("show route-map sharp") actual = ('\n'.join(actual.splitlines()) + '\n').rstrip() logger.info( "Does the show route-map sharp command run the correct number of times" ) diff = topotest.get_textdiff(actual, expected, title1="Actual Route-map output", title2="Expected Route-map output") if diff: logger.info("Actual:") logger.info(actual) logger.info("Expected:") logger.info(expected) srun = r1.vtysh_cmd("show run") srun = ('\n'.join(srun.splitlines()) + '\n').rstrip() logger.info("Show run:") logger.info(srun) assert 0, "r1 sharp route-map processing:\n" logger.info( "Add a extension to the static route-map to see the static route go away" ) r1.vtysh_cmd("conf\nroute-map sharp deny 5\nmatch ip address 5") sleep(2) # we are only checking the kernel here as that this will give us the implied # testing of both the route-map and staticd withdrawing the route # let's spot check that the routes were installed correctly # in the kernel logger.info("Test that the routes installed are correct") sharp_ipfile = "%s/r1/iproute.ref" % (thisDir) expected = open(sharp_ipfile).read().rstrip() expected = ('\n'.join(expected.splitlines()) + '\n').rstrip() actual = r1.run("ip route show") actual = ('\n'.join(actual.splitlines()) + '\n').rstrip() actual = re.sub(r" nhid [0-9][0-9]", "", actual) actual = re.sub(r" proto sharp", " proto XXXX", actual) actual = re.sub(r" proto static", " proto XXXX", actual) actual = re.sub(r" proto 194", " proto XXXX", actual) actual = re.sub(r" proto 196", " proto XXXX", actual) actual = re.sub(r" proto kernel", " proto XXXX", actual) actual = re.sub(r" proto 2", " proto XXXX", actual) # Some platforms have double spaces? Why?????? actual = re.sub(r" proto XXXX ", " proto XXXX ", actual) actual = re.sub(r" metric", " metric", actual) actual = re.sub(r" link ", " link ", actual) diff = topotest.get_textdiff(actual, expected, title1="Actual ip route show", title2="Expected ip route show") if diff: logger.info("Actual:") logger.info(actual) logger.info("Expected:") logger.info(expected) srun = r1.vtysh_cmd("show run") srun = ('\n'.join(srun.splitlines()) + '\n').rstrip() logger.info("Show run:") logger.info(srun) assert 0, "r1 ip route show is not correct:"