diff options
| author | Quentin Young <qlyoung@users.noreply.github.com> | 2021-09-04 12:20:00 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-04 12:20:00 -0400 |
| commit | 5653bb515c97119661f37c6571de0164a2274744 (patch) | |
| tree | 0339eb1bb7da05987f447e9f24d01b7d1b6bb2b0 /tests/topotests/all_protocol_startup/test_all_protocol_startup.py | |
| parent | 3b934c400626e27b89a3bd7fce003b56783cb88e (diff) | |
| parent | a53c08bc131c02f4a20931d7aa9f974194ab16e7 (diff) | |
Merge pull request #9199 from LabNConsulting/chopps/micronet-prime
Diffstat (limited to 'tests/topotests/all_protocol_startup/test_all_protocol_startup.py')
| -rw-r--r-- | tests/topotests/all_protocol_startup/test_all_protocol_startup.py | 169 |
1 files changed, 80 insertions, 89 deletions
diff --git a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py index 2d75428f1a..b1203570a1 100644 --- a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py +++ b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py @@ -34,14 +34,6 @@ import pytest import glob from time import sleep -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 mininet.link import Intf - -from functools import partial pytestmark = [ pytest.mark.babeld, @@ -55,6 +47,7 @@ pytestmark = [ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest +from lib.topogen import Topogen, get_topogen fatal_error = "" @@ -66,24 +59,10 @@ fatal_error = "" ##################################################### -class NetworkTopo(Topo): - "All Protocol Startup Test" - - def build(self, **_opts): - - # Setup Routers - router = {} - # - # Setup Main Router - router[1] = topotest.addRouter(self, "r1") - # - - # Setup Switches - switch = {} - # - for i in range(0, 10): - switch[i] = self.addSwitch("sw%s" % i, cls=topotest.LegacySwitch) - self.addLink(switch[i], router[1], intfName2="r1-eth%s" % i) +def build_topo(tgen): + router = tgen.add_router("r1") + for i in range(0, 10): + tgen.add_switch("sw%d" % i).add_link(router) ##################################################### @@ -94,21 +73,16 @@ class NetworkTopo(Topo): def setup_module(module): - global topo, net global fatal_error print("\n\n** %s: Setup Topology" % module.__name__) print("******************************************\n") - print("Cleanup old Mininet runs") - os.system("sudo mn -c > /dev/null 2>&1") - os.system("sudo rm /tmp/r* > /dev/null 2>&1") - thisDir = os.path.dirname(os.path.realpath(__file__)) - topo = NetworkTopo() + tgen = Topogen(build_topo, module.__name__) + tgen.start_topology() - net = Mininet(controller=None, topo=topo) - net.start() + net = tgen.net if net["r1"].get_routertype() != "frr": fatal_error = "Test is only implemented for FRR" @@ -138,25 +112,22 @@ def setup_module(module): net["r%s" % i].loadConf("nhrpd", "%s/r%s/nhrpd.conf" % (thisDir, i)) net["r%s" % i].loadConf("babeld", "%s/r%s/babeld.conf" % (thisDir, i)) net["r%s" % i].loadConf("pbrd", "%s/r%s/pbrd.conf" % (thisDir, i)) - net["r%s" % i].startRouter() + tgen.gears["r%s" % i].start() # For debugging after starting FRR daemons, uncomment the next line # CLI(net) def teardown_module(module): - global net - print("\n\n** %s: Shutdown Topology" % module.__name__) print("******************************************\n") - - # End - Shutdown network - net.stop() + tgen = get_topogen() + tgen.stop_topology() def test_router_running(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -177,7 +148,7 @@ def test_router_running(): def test_error_messages_vtysh(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -233,7 +204,7 @@ def test_error_messages_vtysh(): def test_error_messages_daemons(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -324,7 +295,7 @@ def test_error_messages_daemons(): def test_converge_protocols(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -413,6 +384,7 @@ def test_converge_protocols(): def route_get_nhg_id(route_str): + net = get_topogen().net output = net["r1"].cmd('vtysh -c "show ip route %s nexthop-group"' % route_str) match = re.search(r"Nexthop Group ID: (\d+)", output) assert match is not None, ( @@ -424,6 +396,7 @@ def route_get_nhg_id(route_str): def verify_nexthop_group(nhg_id, recursive=False, ecmp=0): + net = get_topogen().net # Verify NHG is valid/installed output = net["r1"].cmd('vtysh -c "show nexthop-group rib %d"' % nhg_id) @@ -462,7 +435,7 @@ def verify_route_nexthop_group(route_str, recursive=False, ecmp=0): def test_nexthop_groups(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -611,7 +584,7 @@ def test_nexthop_groups(): def test_rip_status(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -671,7 +644,7 @@ def test_rip_status(): def test_ripng_status(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -738,7 +711,7 @@ def test_ripng_status(): def test_ospfv2_interfaces(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -765,7 +738,7 @@ def test_ospfv2_interfaces(): ) # 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) + 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) @@ -823,7 +796,7 @@ def test_ospfv2_interfaces(): def test_isis_interfaces(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -889,7 +862,7 @@ def test_isis_interfaces(): def test_bgp_summary(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -906,22 +879,32 @@ def test_bgp_summary(): # Read expected result from file expected_original = open(refTableFile).read().rstrip() - for arguments in ["", "remote-as internal", "remote-as external", - "remote-as 100", "remote-as 123", - "neighbor 192.168.7.10", "neighbor 192.168.7.10", - "neighbor fc00:0:0:8::1000", - "neighbor 10.0.0.1", - "terse", - "remote-as internal terse", - "remote-as external terse", - "remote-as 100 terse", "remote-as 123 terse", - "neighbor 192.168.7.10 terse", "neighbor 192.168.7.10 terse", - "neighbor fc00:0:0:8::1000 terse", - "neighbor 10.0.0.1 terse"]: + for arguments in [ + "", + "remote-as internal", + "remote-as external", + "remote-as 100", + "remote-as 123", + "neighbor 192.168.7.10", + "neighbor 192.168.7.10", + "neighbor fc00:0:0:8::1000", + "neighbor 10.0.0.1", + "terse", + "remote-as internal terse", + "remote-as external terse", + "remote-as 100 terse", + "remote-as 123 terse", + "neighbor 192.168.7.10 terse", + "neighbor 192.168.7.10 terse", + "neighbor fc00:0:0:8::1000 terse", + "neighbor 10.0.0.1 terse", + ]: # Actual output from router actual = ( net["r%s" % i] - .cmd('vtysh -c "show ip bgp summary ' + arguments + '" 2> /dev/null') + .cmd( + 'vtysh -c "show ip bgp summary ' + arguments + '" 2> /dev/null' + ) .rstrip() ) @@ -950,7 +933,9 @@ def test_bgp_summary(): actual = re.sub(r"Unknown Summary \(VRF default\):", "", actual) actual = re.sub(r"No Unknown neighbor is configured", "", actual) - actual = re.sub(r"IPv4 labeled-unicast Summary \(VRF default\):", "", actual) + actual = re.sub( + r"IPv4 labeled-unicast Summary \(VRF default\):", "", actual + ) actual = re.sub( r"No IPv4 labeled-unicast neighbor is configured", "", actual ) @@ -964,19 +949,18 @@ def test_bgp_summary(): elif "remote-as 123" in arguments: expected = re.sub( r"(192.168.7.(1|2)0|fc00:0:0:8::(1|2)000).+Active.+", - "", expected + "", + expected, ) expected = re.sub(r"\nNeighbor.+Desc", "", expected) expected = expected + "% No matching neighbor\n" elif "192.168.7.10" in arguments: expected = re.sub( - r"(192.168.7.20|fc00:0:0:8::(1|2)000).+Active.+", - "", expected + r"(192.168.7.20|fc00:0:0:8::(1|2)000).+Active.+", "", expected ) elif "fc00:0:0:8::1000" in arguments: expected = re.sub( - r"(192.168.7.(1|2)0|fc00:0:0:8::2000).+Active.+", - "", expected + r"(192.168.7.(1|2)0|fc00:0:0:8::2000).+Active.+", "", expected ) elif "10.0.0.1" in arguments: expected = "No such neighbor in VRF default" @@ -1002,8 +986,12 @@ def test_bgp_summary(): # realign expected neighbor columns if needed try: - idx_actual = re.search(r"(Neighbor\s+V\s+)", actual).group(1).find("V") - idx_expected = re.search(r"(Neighbor\s+V\s+)", expected).group(1).find("V") + idx_actual = ( + re.search(r"(Neighbor\s+V\s+)", actual).group(1).find("V") + ) + idx_expected = ( + re.search(r"(Neighbor\s+V\s+)", expected).group(1).find("V") + ) idx_diff = idx_expected - idx_actual if idx_diff > 0: # Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd @@ -1021,7 +1009,7 @@ def test_bgp_summary(): diff = topotest.get_textdiff( actual, expected, - title1="actual SHOW IP BGP SUMMARY " + arguments.upper() , + title1="actual SHOW IP BGP SUMMARY " + arguments.upper(), title2="expected SHOW IP BGP SUMMARY " + arguments.upper(), ) @@ -1034,7 +1022,9 @@ def test_bgp_summary(): else: print("r%s ok" % i) - assert failures == 0, "SHOW IP BGP SUMMARY failed for router r%s:\n%s" % ( + assert ( + failures == 0 + ), "SHOW IP BGP SUMMARY failed for router r%s:\n%s" % ( i, diff, ) @@ -1050,7 +1040,7 @@ def test_bgp_summary(): def test_bgp_ipv6_summary(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1101,7 +1091,9 @@ def test_bgp_ipv6_summary(): 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 \(VRF default\):", "", actual) + actual = re.sub( + r"IPv6 labeled-unicast Summary \(VRF default\):", "", actual + ) actual = re.sub( r"No IPv6 labeled-unicast neighbor is configured", "", actual ) @@ -1145,6 +1137,7 @@ def test_bgp_ipv6_summary(): def test_nht(): + net = get_topogen().net print("\n\n**** Test that nexthop tracking is at least nominally working ****\n") thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -1155,7 +1148,7 @@ def test_nht(): expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) actual = net["r%s" % i].cmd('vtysh -c "show ip nht" 2> /dev/null').rstrip() - actual = re.sub(r"fd [0-9][0-9]", "fd XX", actual) + actual = re.sub(r"fd [0-9]+", "fd XX", actual) actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) diff = topotest.get_textdiff( @@ -1175,7 +1168,7 @@ def test_nht(): expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) actual = net["r%s" % i].cmd('vtysh -c "show ipv6 nht" 2> /dev/null').rstrip() - actual = re.sub(r"fd [0-9][0-9]", "fd XX", actual) + actual = re.sub(r"fd [0-9]+", "fd XX", actual) actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) diff = topotest.get_textdiff( @@ -1193,7 +1186,7 @@ def test_nht(): def test_bgp_ipv4(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1263,7 +1256,7 @@ def test_bgp_ipv4(): def test_bgp_ipv6(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1332,7 +1325,7 @@ def test_bgp_ipv6(): def test_route_map(): global fatal_error - global net + net = get_topogen().net if fatal_error != "": pytest.skip(fatal_error) @@ -1375,7 +1368,7 @@ def test_route_map(): def test_nexthop_groups_with_route_maps(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1418,7 +1411,7 @@ def test_nexthop_groups_with_route_maps(): net["r1"].cmd('vtysh -c "sharp remove routes %s 1"' % route_str) net["r1"].cmd('vtysh -c "c t" -c "no ip protocol sharp route-map NH-SRC"') net["r1"].cmd( - 'vtysh -c "c t" -c "no route-map NH-SRC permit 111" -c "set src %s"' % src_str + 'vtysh -c "c t" -c "no route-map NH-SRC permit 111" # -c "set src %s"' % src_str ) net["r1"].cmd('vtysh -c "c t" -c "no route-map NH-SRC"') @@ -1472,7 +1465,7 @@ def test_nexthop_groups_with_route_maps(): def test_nexthop_group_replace(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1505,7 +1498,7 @@ def test_nexthop_group_replace(): def test_mpls_interfaces(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1574,7 +1567,7 @@ def test_mpls_interfaces(): def test_shutdown_check_stderr(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1637,7 +1630,7 @@ def test_shutdown_check_stderr(): def test_shutdown_check_memleak(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1659,8 +1652,6 @@ def test_shutdown_check_memleak(): if __name__ == "__main__": - - setLogLevel("info") # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli # retval = pytest.main(["-s", "--tb=no"]) retval = pytest.main(["-s"]) |
