diff --git a/tests/topotests/bfd-bgp-cbit-topo3/test_bfd_bgp_cbit_topo3.py b/tests/topotests/bfd-bgp-cbit-topo3/test_bfd_bgp_cbit_topo3.py index 22a4547a30..186dac31a0 100755 --- a/tests/topotests/bfd-bgp-cbit-topo3/test_bfd_bgp_cbit_topo3.py +++ b/tests/topotests/bfd-bgp-cbit-topo3/test_bfd_bgp_cbit_topo3.py @@ -33,7 +33,7 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -44,23 +44,26 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from mininet.topo import Topo + class BFDTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) # Create 4 routers. for routern in range(1, 4): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) def setup_module(mod): "Sets up the pytest environment" @@ -71,16 +74,13 @@ def setup_module(mod): for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)), + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)), ) router.load_config( - TopoRouter.RD_BFD, - os.path.join(CWD, '{}/bfdd.conf'.format(rname)) + TopoRouter.RD_BFD, os.path.join(CWD, "{}/bfdd.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) # Initialize all routers. @@ -90,10 +90,11 @@ def setup_module(mod): # daemon exists. for router in router_list.values(): # Check for Version - if router.has_version('<', '5.1'): - tgen.set_error('Unsupported FRR version') + if router.has_version("<", "5.1"): + tgen.set_error("Unsupported FRR version") break + def teardown_module(_mod): "Teardown the pytest environment" tgen = get_topogen() @@ -112,17 +113,17 @@ def test_protocols_convergence(): # Check IPv6 routing tables. logger.info("Checking IPv6 routes for convergence") for router in tgen.routers().values(): - if router.name == 'r2': + if router.name == "r2": continue - json_file = '{}/{}/ipv6_routes.json'.format(CWD, router.name) + json_file = "{}/{}/ipv6_routes.json".format(CWD, router.name) if not os.path.isfile(json_file): - logger.info('skipping file {}'.format(json_file)) + logger.info("skipping file {}".format(json_file)) continue expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show ipv6 route json', expected) - _, result = topotest.run_and_expect(test_func, None, count=40, - wait=0.5) + test_func = partial( + topotest.router_json_cmp, router, "show ipv6 route json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=40, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg @@ -133,19 +134,21 @@ def test_bfd_connection(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('waiting for bfd peers to go up') + logger.info("waiting for bfd peers to go up") for router in tgen.routers().values(): - if router.name == 'r2': + if router.name == "r2": continue - json_file = '{}/{}/peers.json'.format(CWD, router.name) + json_file = "{}/{}/peers.json".format(CWD, router.name) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show bfd peers json', expected) + test_func = partial( + topotest.router_json_cmp, router, "show bfd peers json", expected + ) _, result = topotest.run_and_expect(test_func, None, count=32, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg + def test_bfd_loss_intermediate(): """ Assert that BFD notices the bfd link down failure. @@ -155,94 +158,98 @@ def test_bfd_loss_intermediate(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('removing IPv6 address from r2 to simulate loss of connectivity') + logger.info("removing IPv6 address from r2 to simulate loss of connectivity") # Disable r2-eth0 ipv6 address - cmd = 'vtysh -c \"configure terminal\" -c \"interface r2-eth1\" -c "no ipv6 address 2001:db8:4::2/64\"' - tgen.net['r2'].cmd(cmd) - + cmd = 'vtysh -c "configure terminal" -c "interface r2-eth1" -c "no ipv6 address 2001:db8:4::2/64"' + tgen.net["r2"].cmd(cmd) + # Wait the minimum time we can before checking that BGP/BFD # converged. - logger.info('waiting for BFD converge down') + logger.info("waiting for BFD converge down") # Check that BGP converged quickly. for router in tgen.routers().values(): - if router.name == 'r2': + if router.name == "r2": continue - json_file = '{}/{}/peers_down.json'.format(CWD, router.name) + json_file = "{}/{}/peers_down.json".format(CWD, router.name) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show bfd peers json', expected) + test_func = partial( + topotest.router_json_cmp, router, "show bfd peers json", expected + ) _, result = topotest.run_and_expect(test_func, None, count=32, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg - logger.info('waiting for BGP entries to become stale') + logger.info("waiting for BGP entries to become stale") for router in tgen.routers().values(): - if router.name == 'r2': + if router.name == "r2": continue - json_file = '{}/{}/bgp_ipv6_routes_down.json'.format(CWD, router.name) + json_file = "{}/{}/bgp_ipv6_routes_down.json".format(CWD, router.name) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show bgp ipv6 json', expected) + test_func = partial( + topotest.router_json_cmp, router, "show bgp ipv6 json", expected + ) _, result = topotest.run_and_expect(test_func, None, count=50, wait=1) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg logger.info("Checking IPv6 routes on r1 should still be present") for router in tgen.routers().values(): - if router.name == 'r2': + if router.name == "r2": continue - if router.name == 'r3': + if router.name == "r3": continue - json_file = '{}/r1/ipv6_routes.json'.format(CWD) + json_file = "{}/r1/ipv6_routes.json".format(CWD) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show ipv6 route json', expected) - _, result = topotest.run_and_expect(test_func, None, count=30, - wait=0.5) + test_func = partial( + topotest.router_json_cmp, router, "show ipv6 route json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg + def test_bfd_comes_back_again(): """ Assert that BFD notices the bfd link up and that ipv6 entries appear back """ tgen = get_topogen() - logger.info('re-adding IPv6 address from r2 to simulate connectivity is back') + logger.info("re-adding IPv6 address from r2 to simulate connectivity is back") # adds back r2-eth0 ipv6 address - cmd = 'vtysh -c \"configure terminal\" -c \"interface r2-eth1\" -c "ipv6 address 2001:db8:4::2/64\"' - tgen.net['r2'].cmd(cmd) + cmd = 'vtysh -c "configure terminal" -c "interface r2-eth1" -c "ipv6 address 2001:db8:4::2/64"' + tgen.net["r2"].cmd(cmd) # Wait the minimum time we can before checking that BGP/BFD # converged. - logger.info('waiting for BFD to converge up') + logger.info("waiting for BFD to converge up") # Check that BGP converged quickly. for router in tgen.routers().values(): - if router.name == 'r2': + if router.name == "r2": continue - json_file = '{}/{}/peers.json'.format(CWD, router.name) + json_file = "{}/{}/peers.json".format(CWD, router.name) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show bfd peers json', expected) + test_func = partial( + topotest.router_json_cmp, router, "show bfd peers json", expected + ) _, result = topotest.run_and_expect(test_func, None, count=16, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg - + def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bfd-topo1/test_bfd_topo1.py b/tests/topotests/bfd-topo1/test_bfd_topo1.py index 4fd4f97436..e1865dc5a8 100644 --- a/tests/topotests/bfd-topo1/test_bfd_topo1.py +++ b/tests/topotests/bfd-topo1/test_bfd_topo1.py @@ -34,7 +34,7 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -45,27 +45,29 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from mininet.topo import Topo + class BFDTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) # Create 4 routers for routern in range(1, 5): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch('s3') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r4']) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r4"]) def setup_module(mod): @@ -76,16 +78,13 @@ def setup_module(mod): router_list = tgen.routers() for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BFD, - os.path.join(CWD, '{}/bfdd.conf'.format(rname)) + TopoRouter.RD_BFD, os.path.join(CWD, "{}/bfdd.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) # Initialize all routers. @@ -95,8 +94,8 @@ def setup_module(mod): # daemon exists. for router in router_list.values(): # Check for Version - if router.has_version('<', '5.1'): - tgen.set_error('Unsupported FRR version') + if router.has_version("<", "5.1"): + tgen.set_error("Unsupported FRR version") break @@ -112,14 +111,15 @@ def test_bfd_connection(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('waiting for bfd peers to go up') + logger.info("waiting for bfd peers to go up") for router in tgen.routers().values(): - json_file = '{}/{}/peers.json'.format(CWD, router.name) + json_file = "{}/{}/peers.json".format(CWD, router.name) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show bfd peers json', expected) + test_func = partial( + topotest.router_json_cmp, router, "show bfd peers json", expected + ) _, result = topotest.run_and_expect(test_func, None, count=8, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg @@ -131,15 +131,16 @@ def test_bgp_convergence(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('waiting for bgp peers to go up') + logger.info("waiting for bgp peers to go up") for router in tgen.routers().values(): - ref_file = '{}/{}/bgp_summary.json'.format(CWD, router.name) + ref_file = "{}/{}/bgp_summary.json".format(CWD, router.name) expected = json.loads(open(ref_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show ip bgp summary json', expected) + test_func = partial( + topotest.router_json_cmp, router, "show ip bgp summary json", expected + ) _, res = topotest.run_and_expect(test_func, None, count=125, wait=1.0) - assertmsg = '{}: bgp did not converge'.format(router.name) + assertmsg = "{}: bgp did not converge".format(router.name) assert res is None, assertmsg @@ -149,15 +150,16 @@ def test_bgp_fast_convergence(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('waiting for bgp peers converge') + logger.info("waiting for bgp peers converge") for router in tgen.routers().values(): - ref_file = '{}/{}/bgp_prefixes.json'.format(CWD, router.name) + ref_file = "{}/{}/bgp_prefixes.json".format(CWD, router.name) expected = json.loads(open(ref_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show ip bgp json', expected) + test_func = partial( + topotest.router_json_cmp, router, "show ip bgp json", expected + ) _, res = topotest.run_and_expect(test_func, None, count=40, wait=0.5) - assertmsg = '{}: bgp did not converge'.format(router.name) + assertmsg = "{}: bgp did not converge".format(router.name) assert res is None, assertmsg @@ -171,29 +173,30 @@ def test_bfd_fast_convergence(): pytest.skip(tgen.errors) # Disable r1-eth0 link. - tgen.gears['r1'].link_enable('r1-eth0', enabled=False) + tgen.gears["r1"].link_enable("r1-eth0", enabled=False) # Wait the minimum time we can before checking that BGP/BFD # converged. - logger.info('waiting for BFD converge') + logger.info("waiting for BFD converge") # Check that BGP converged quickly. for router in tgen.routers().values(): - json_file = '{}/{}/peers.json'.format(CWD, router.name) + json_file = "{}/{}/peers.json".format(CWD, router.name) expected = json.loads(open(json_file).read()) # Load the same file as previous test, but expect R1 to be down. - if router.name == 'r1': + if router.name == "r1": for peer in expected: - if peer['peer'] == '192.168.0.2': - peer['status'] = 'down' + if peer["peer"] == "192.168.0.2": + peer["status"] = "down" else: for peer in expected: - if peer['peer'] == '192.168.0.1': - peer['status'] = 'down' + if peer["peer"] == "192.168.0.1": + peer["status"] = "down" - test_func = partial(topotest.router_json_cmp, - router, 'show bfd peers json', expected) + test_func = partial( + topotest.router_json_cmp, router, "show bfd peers json", expected + ) _, res = topotest.run_and_expect(test_func, None, count=20, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert res is None, assertmsg @@ -205,31 +208,27 @@ def test_bgp_fast_reconvergence(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('waiting for BGP re convergence') + logger.info("waiting for BGP re convergence") # Check that BGP converged quickly. for router in tgen.routers().values(): - ref_file = '{}/{}/bgp_prefixes.json'.format(CWD, router.name) + ref_file = "{}/{}/bgp_prefixes.json".format(CWD, router.name) expected = json.loads(open(ref_file).read()) # Load the same file as previous test, but set networks to None # to test absence. - if router.name == 'r1': - expected['routes']['10.254.254.2/32'] = None - expected['routes']['10.254.254.3/32'] = None - expected['routes']['10.254.254.4/32'] = None + if router.name == "r1": + expected["routes"]["10.254.254.2/32"] = None + expected["routes"]["10.254.254.3/32"] = None + expected["routes"]["10.254.254.4/32"] = None else: - expected['routes']['10.254.254.1/32'] = None + expected["routes"]["10.254.254.1/32"] = None - test_func = partial(topotest.router_json_cmp, - router, 'show ip bgp json', expected) - _, res = topotest.run_and_expect( - test_func, - None, - count=3, - wait=1 + test_func = partial( + topotest.router_json_cmp, router, "show ip bgp json", expected ) - assertmsg = '{}: bgp did not converge'.format(router.name) + _, res = topotest.run_and_expect(test_func, None, count=3, wait=1) + assertmsg = "{}: bgp did not converge".format(router.name) assert res is None, assertmsg @@ -237,11 +236,11 @@ def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bfd-topo2/test_bfd_topo2.py b/tests/topotests/bfd-topo2/test_bfd_topo2.py index 773db129f0..3e87e8485a 100644 --- a/tests/topotests/bfd-topo2/test_bfd_topo2.py +++ b/tests/topotests/bfd-topo2/test_bfd_topo2.py @@ -35,7 +35,7 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -49,25 +49,26 @@ from mininet.topo import Topo class BFDTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) # Create 4 routers. for routern in range(1, 5): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch('s3') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r4']) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r4"]) def setup_module(mod): @@ -78,24 +79,19 @@ def setup_module(mod): router_list = tgen.routers() for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BFD, - os.path.join(CWD, '{}/bfdd.conf'.format(rname)) + TopoRouter.RD_BFD, os.path.join(CWD, "{}/bfdd.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) router.load_config( - TopoRouter.RD_OSPF, - os.path.join(CWD, '{}/ospfd.conf'.format(rname)) + TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname)) ) router.load_config( - TopoRouter.RD_OSPF6, - os.path.join(CWD, '{}/ospf6d.conf'.format(rname)) + TopoRouter.RD_OSPF6, os.path.join(CWD, "{}/ospf6d.conf".format(rname)) ) # Initialize all routers. @@ -105,8 +101,8 @@ def setup_module(mod): # daemon exists. for router in router_list.values(): # Check for Version - if router.has_version('<', '5.1'): - tgen.set_error('Unsupported FRR version') + if router.has_version("<", "5.1"): + tgen.set_error("Unsupported FRR version") break @@ -128,32 +124,32 @@ def test_protocols_convergence(): # Check IPv4 routing tables. logger.info("Checking IPv4 routes for convergence") for router in tgen.routers().values(): - json_file = '{}/{}/ipv4_routes.json'.format(CWD, router.name) + json_file = "{}/{}/ipv4_routes.json".format(CWD, router.name) if not os.path.isfile(json_file): - logger.info('skipping file {}'.format(json_file)) + logger.info("skipping file {}".format(json_file)) continue expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show ip route json', expected) - _, result = topotest.run_and_expect(test_func, None, count=160, - wait=0.5) + test_func = partial( + topotest.router_json_cmp, router, "show ip route json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=160, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg # Check IPv6 routing tables. logger.info("Checking IPv6 routes for convergence") for router in tgen.routers().values(): - json_file = '{}/{}/ipv6_routes.json'.format(CWD, router.name) + json_file = "{}/{}/ipv6_routes.json".format(CWD, router.name) if not os.path.isfile(json_file): - logger.info('skipping file {}'.format(json_file)) + logger.info("skipping file {}".format(json_file)) continue expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show ipv6 route json', expected) - _, result = topotest.run_and_expect(test_func, None, count=160, - wait=0.5) + test_func = partial( + topotest.router_json_cmp, router, "show ipv6 route json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=160, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg @@ -164,14 +160,15 @@ def test_bfd_connection(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('waiting for bfd peers to go up') + logger.info("waiting for bfd peers to go up") for router in tgen.routers().values(): - json_file = '{}/{}/peers.json'.format(CWD, router.name) + json_file = "{}/{}/peers.json".format(CWD, router.name) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show bfd peers json', expected) + test_func = partial( + topotest.router_json_cmp, router, "show bfd peers json", expected + ) _, result = topotest.run_and_expect(test_func, None, count=8, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg @@ -181,11 +178,11 @@ def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bfd-vrf-topo1/test_bfd_vrf_topo1.py b/tests/topotests/bfd-vrf-topo1/test_bfd_vrf_topo1.py index e2933820bd..eb4f0d4a83 100755 --- a/tests/topotests/bfd-vrf-topo1/test_bfd_vrf_topo1.py +++ b/tests/topotests/bfd-vrf-topo1/test_bfd_vrf_topo1.py @@ -35,7 +35,7 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -46,27 +46,29 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from mininet.topo import Topo + class BFDTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) # Create 4 routers for routern in range(1, 5): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch('s3') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r4']) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r4"]) def setup_module(mod): @@ -78,47 +80,50 @@ def setup_module(mod): # check for zebra capability for rname, router in router_list.iteritems(): - if router.check_capability( - TopoRouter.RD_ZEBRA, - '--vrfwnetns' - ) == False: - return pytest.skip('Skipping BFD Topo1 VRF NETNS feature. VRF NETNS backend not available on FRR') + if router.check_capability(TopoRouter.RD_ZEBRA, "--vrfwnetns") == False: + return pytest.skip( + "Skipping BFD Topo1 VRF NETNS feature. VRF NETNS backend not available on FRR" + ) - if os.system('ip netns list') != 0: - return pytest.skip('Skipping BFD Topo1 VRF NETNS Test. NETNS not available on System') + if os.system("ip netns list") != 0: + return pytest.skip( + "Skipping BFD Topo1 VRF NETNS Test. NETNS not available on System" + ) - logger.info('Testing with VRF Namespace support') + logger.info("Testing with VRF Namespace support") - cmds = ['if [ -e /var/run/netns/{0}-cust1 ] ; then ip netns del {0}-cust1 ; fi', - 'ip netns add {0}-cust1', - 'ip link set dev {0}-eth0 netns {0}-cust1', - 'ip netns exec {0}-cust1 ifconfig {0}-eth0 up'] - cmds2 = ['ip link set dev {0}-eth1 netns {0}-cust1', - 'ip netns exec {0}-cust1 ifconfig {0}-eth1 up', - 'ip link set dev {0}-eth2 netns {0}-cust1', - 'ip netns exec {0}-cust1 ifconfig {0}-eth2 up'] + cmds = [ + "if [ -e /var/run/netns/{0}-cust1 ] ; then ip netns del {0}-cust1 ; fi", + "ip netns add {0}-cust1", + "ip link set dev {0}-eth0 netns {0}-cust1", + "ip netns exec {0}-cust1 ifconfig {0}-eth0 up", + ] + cmds2 = [ + "ip link set dev {0}-eth1 netns {0}-cust1", + "ip netns exec {0}-cust1 ifconfig {0}-eth1 up", + "ip link set dev {0}-eth2 netns {0}-cust1", + "ip netns exec {0}-cust1 ifconfig {0}-eth2 up", + ] for rname, router in router_list.iteritems(): # create VRF rx-cust1 and link rx-eth0 to rx-cust1 for cmd in cmds: output = tgen.net[rname].cmd(cmd.format(rname)) - if rname == 'r2': + if rname == "r2": for cmd in cmds2: output = tgen.net[rname].cmd(cmd.format(rname)) for rname, router in router_list.iteritems(): router.load_config( TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)), - '--vrfwnetns' + os.path.join(CWD, "{}/zebra.conf".format(rname)), + "--vrfwnetns", ) router.load_config( - TopoRouter.RD_BFD, - os.path.join(CWD, '{}/bfdd.conf'.format(rname)) + TopoRouter.RD_BFD, os.path.join(CWD, "{}/bfdd.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) # Initialize all routers. @@ -128,42 +133,49 @@ def setup_module(mod): # daemon exists. for router in router_list.values(): # Check for Version - if router.has_version('<', '5.1'): - tgen.set_error('Unsupported FRR version') + if router.has_version("<", "5.1"): + tgen.set_error("Unsupported FRR version") break + def teardown_module(_mod): "Teardown the pytest environment" tgen = get_topogen() # move back rx-eth0 to default VRF # delete rx-vrf - cmds = ['ip netns exec {0}-cust1 ip link set {0}-eth0 netns 1', - 'ip netns delete {0}-cust1'] - cmds2 = ['ip netns exec {0}-cust1 ip link set {0}-eth1 netns 1', - 'ip netns exec {0}-cust2 ip link set {0}-eth1 netns 1'] + cmds = [ + "ip netns exec {0}-cust1 ip link set {0}-eth0 netns 1", + "ip netns delete {0}-cust1", + ] + cmds2 = [ + "ip netns exec {0}-cust1 ip link set {0}-eth1 netns 1", + "ip netns exec {0}-cust2 ip link set {0}-eth1 netns 1", + ] router_list = tgen.routers() for rname, router in router_list.iteritems(): - if rname == 'r2': + if rname == "r2": for cmd in cmds2: tgen.net[rname].cmd(cmd.format(rname)) for cmd in cmds: tgen.net[rname].cmd(cmd.format(rname)) tgen.stop_topology() + def test_bfd_connection(): "Assert that the BFD peers can find themselves." tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('waiting for bfd peers to go up') + logger.info("waiting for bfd peers to go up") for router in tgen.routers().values(): - json_file = '{}/{}/peers.json'.format(CWD, router.name) + json_file = "{}/{}/peers.json".format(CWD, router.name) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show bfd peers json', expected) + test_func = partial( + topotest.router_json_cmp, router, "show bfd peers json", expected + ) _, result = topotest.run_and_expect(test_func, None, count=8, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg @@ -175,15 +187,19 @@ def test_bgp_convergence(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('waiting for bgp peers to go up') + logger.info("waiting for bgp peers to go up") for router in tgen.routers().values(): - ref_file = '{}/{}/bgp_summary.json'.format(CWD, router.name) + ref_file = "{}/{}/bgp_summary.json".format(CWD, router.name) expected = json.loads(open(ref_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show ip bgp vrf {}-cust1 summary json'.format(router.name), expected) + test_func = partial( + topotest.router_json_cmp, + router, + "show ip bgp vrf {}-cust1 summary json".format(router.name), + expected, + ) _, res = topotest.run_and_expect(test_func, None, count=125, wait=1.0) - assertmsg = '{}: bgp did not converge'.format(router.name) + assertmsg = "{}: bgp did not converge".format(router.name) assert res is None, assertmsg @@ -193,15 +209,19 @@ def test_bgp_fast_convergence(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('waiting for bgp peers converge') + logger.info("waiting for bgp peers converge") for router in tgen.routers().values(): - ref_file = '{}/{}/bgp_prefixes.json'.format(CWD, router.name) + ref_file = "{}/{}/bgp_prefixes.json".format(CWD, router.name) expected = json.loads(open(ref_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show ip bgp vrf {}-cust1 json'.format(router.name), expected) + test_func = partial( + topotest.router_json_cmp, + router, + "show ip bgp vrf {}-cust1 json".format(router.name), + expected, + ) _, res = topotest.run_and_expect(test_func, None, count=40, wait=0.5) - assertmsg = '{}: bgp did not converge'.format(router.name) + assertmsg = "{}: bgp did not converge".format(router.name) assert res is None, assertmsg @@ -215,30 +235,33 @@ def test_bfd_fast_convergence(): pytest.skip(tgen.errors) # Disable r2-eth0 link - router2 = tgen.gears['r2'] - topotest.interface_set_status(router2, 'r2-eth0', ifaceaction=False, vrf_name='r2-cust1') + router2 = tgen.gears["r2"] + topotest.interface_set_status( + router2, "r2-eth0", ifaceaction=False, vrf_name="r2-cust1" + ) # Wait the minimum time we can before checking that BGP/BFD # converged. - logger.info('waiting for BFD converge') + logger.info("waiting for BFD converge") # Check that BGP converged quickly. for router in tgen.routers().values(): - json_file = '{}/{}/peers.json'.format(CWD, router.name) + json_file = "{}/{}/peers.json".format(CWD, router.name) expected = json.loads(open(json_file).read()) # Load the same file as previous test, but expect R1 to be down. - if router.name == 'r1': + if router.name == "r1": for peer in expected: - if peer['peer'] == '192.168.0.2': - peer['status'] = 'down' + if peer["peer"] == "192.168.0.2": + peer["status"] = "down" else: for peer in expected: - if peer['peer'] == '192.168.0.1': - peer['status'] = 'down' + if peer["peer"] == "192.168.0.1": + peer["status"] = "down" - test_func = partial(topotest.router_json_cmp, - router, 'show bfd peers json', expected) + test_func = partial( + topotest.router_json_cmp, router, "show bfd peers json", expected + ) _, res = topotest.run_and_expect(test_func, None, count=20, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert res is None, assertmsg @@ -250,31 +273,30 @@ def test_bgp_fast_reconvergence(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('waiting for BGP re convergence') + logger.info("waiting for BGP re convergence") # Check that BGP converged quickly. for router in tgen.routers().values(): - ref_file = '{}/{}/bgp_prefixes.json'.format(CWD, router.name) + ref_file = "{}/{}/bgp_prefixes.json".format(CWD, router.name) expected = json.loads(open(ref_file).read()) # Load the same file as previous test, but set networks to None # to test absence. - if router.name == 'r1': - expected['routes']['10.254.254.2/32'] = None - expected['routes']['10.254.254.3/32'] = None - expected['routes']['10.254.254.4/32'] = None + if router.name == "r1": + expected["routes"]["10.254.254.2/32"] = None + expected["routes"]["10.254.254.3/32"] = None + expected["routes"]["10.254.254.4/32"] = None else: - expected['routes']['10.254.254.1/32'] = None + expected["routes"]["10.254.254.1/32"] = None - test_func = partial(topotest.router_json_cmp, - router, 'show ip bgp vrf {}-cust1 json'.format(router.name), expected) - _, res = topotest.run_and_expect( - test_func, - None, - count=3, - wait=1 + test_func = partial( + topotest.router_json_cmp, + router, + "show ip bgp vrf {}-cust1 json".format(router.name), + expected, ) - assertmsg = '{}: bgp did not converge'.format(router.name) + _, res = topotest.run_and_expect(test_func, None, count=3, wait=1) + assertmsg = "{}: bgp did not converge".format(router.name) assert res is None, assertmsg @@ -282,11 +304,11 @@ def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py b/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py index 43639a81d1..7a74b62980 100755 --- a/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py +++ b/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py @@ -48,8 +48,8 @@ from copy import deepcopy # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) -sys.path.append(os.path.join(CWD, '../lib/')) +sys.path.append(os.path.join(CWD, "../")) +sys.path.append(os.path.join(CWD, "../lib/")) # Required to instantiate the topology builder class. @@ -59,30 +59,39 @@ from lib.topogen import Topogen, get_topogen from mininet.topo import Topo from lib.common_config import ( - start_topology, write_test_header, - write_test_footer, reset_config_on_routers, create_static_routes, - verify_rib, verify_admin_distance_for_static_routes + start_topology, + write_test_header, + write_test_footer, + reset_config_on_routers, + create_static_routes, + verify_rib, + verify_admin_distance_for_static_routes, ) from lib.topolog import logger from lib.bgp import ( - verify_bgp_convergence, create_router_bgp, verify_router_id, - modify_as_number, verify_as_numbers, clear_bgp_and_verify, - verify_bgp_timers_and_functionality + verify_bgp_convergence, + create_router_bgp, + verify_router_id, + modify_as_number, + verify_as_numbers, + clear_bgp_and_verify, + verify_bgp_timers_and_functionality, ) from lib.topojson import build_topo_from_json, build_config_from_json # Reading the data from JSON File for topology creation jsonFile = "{}/bgp_basic_functionality.json".format(CWD) try: - with open(jsonFile, 'r') as topoJson: + with open(jsonFile, "r") as topoJson: topo = json.load(topoJson) except IOError: assert False, "Could not read file {}".format(jsonFile) -#Global Variable +# Global Variable KEEPALIVETIMER = 2 HOLDDOWNTIMER = 6 + class CreateTopo(Topo): """ Test BasicTopo - topology 1 @@ -124,8 +133,9 @@ def setup_module(mod): global BGP_CONVERGENCE BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) - assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}". \ - format(BGP_CONVERGENCE) + assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format( + BGP_CONVERGENCE + ) logger.info("Running setup_module() done") @@ -140,8 +150,9 @@ def teardown_module(): # Stop toplogy and Remove tmp files tgen.stop_topology() - logger.info("Testsuite end time: {}". - format(time.asctime(time.localtime(time.time())))) + logger.info( + "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) + ) logger.info("=" * 40) @@ -157,7 +168,7 @@ def test_modify_and_delete_router_id(request): tgen = get_topogen() if BGP_CONVERGENCE is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name @@ -165,59 +176,31 @@ def test_modify_and_delete_router_id(request): # Modify router id input_dict = { - 'r1': { - "bgp": { - 'router_id': '12.12.12.12' - } - }, - 'r2': { - "bgp": { - 'router_id': '22.22.22.22' - } - }, - 'r3': { - "bgp": { - 'router_id': '33.33.33.33' - } - }, + "r1": {"bgp": {"router_id": "12.12.12.12"}}, + "r2": {"bgp": {"router_id": "22.22.22.22"}}, + "r3": {"bgp": {"router_id": "33.33.33.33"}}, } result = create_router_bgp(tgen, topo, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}".\ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) # Verifying router id once modified result = verify_router_id(tgen, topo, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}".\ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) # Delete router id input_dict = { - 'r1': { - "bgp": { - 'del_router_id': True - } - }, - 'r2': { - "bgp": { - 'del_router_id': True - } - }, - 'r3': { - "bgp": { - 'del_router_id': True - } - }, + "r1": {"bgp": {"del_router_id": True}}, + "r2": {"bgp": {"del_router_id": True}}, + "r3": {"bgp": {"del_router_id": True}}, } result = create_router_bgp(tgen, topo, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) # Verifying router id once deleted # Once router-id is deleted, highest interface ip should become # router-id result = verify_router_id(tgen, topo, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -229,41 +212,23 @@ def test_bgp_config_with_4byte_as_number(request): tgen = get_topogen() if BGP_CONVERGENCE is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name write_test_header(tc_name) input_dict = { - "r1": { - "bgp": { - "local_as": 131079 - } - }, - "r2": { - "bgp": { - "local_as": 131079 - } - }, - "r3": { - "bgp": { - "local_as": 131079 - } - }, - "r4": { - "bgp": { - "local_as": 131080 - } - } + "r1": {"bgp": {"local_as": 131079}}, + "r2": {"bgp": {"local_as": 131079}}, + "r3": {"bgp": {"local_as": 131079}}, + "r4": {"bgp": {"local_as": 131080}}, } result = modify_as_number(tgen, topo, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) result = verify_as_numbers(tgen, topo, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -275,7 +240,7 @@ def test_bgp_timers_functionality(request): tgen = get_topogen() if BGP_CONVERGENCE is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name @@ -293,10 +258,10 @@ def test_bgp_timers_functionality(request): "unicast": { "neighbor": { "r2": { - "dest_link":{ + "dest_link": { "r1": { "keepalivetimer": KEEPALIVETIMER, - "holddowntimer": HOLDDOWNTIMER + "holddowntimer": HOLDDOWNTIMER, } } } @@ -308,16 +273,14 @@ def test_bgp_timers_functionality(request): } } result = create_router_bgp(tgen, topo, deepcopy(input_dict)) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) # Api call to clear bgp, so timer modification would take place - clear_bgp_and_verify(tgen, topo, 'r1') + clear_bgp_and_verify(tgen, topo, "r1") # Verifying bgp timers functionality result = verify_bgp_timers_and_functionality(tgen, topo, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -327,7 +290,7 @@ def test_static_routes(request): tgen = get_topogen() if BGP_CONVERGENCE is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name @@ -339,17 +302,18 @@ def test_static_routes(request): # Api call to create static routes input_dict = { "r1": { - "static_routes": [{ - "network": "10.0.20.1/32", - "no_of_ip": 9, - "admin_distance": 100, - "next_hop": "10.0.0.2" - }] + "static_routes": [ + { + "network": "10.0.20.1/32", + "no_of_ip": 9, + "admin_distance": 100, + "next_hop": "10.0.0.2", + } + ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) # Api call to redistribute static routes input_dict_1 = { @@ -360,7 +324,7 @@ def test_static_routes(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } } @@ -370,17 +334,16 @@ def test_static_routes(request): } result = create_router_bgp(tgen, topo, input_dict_1) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' - next_hop = ['10.0.0.2', '10.0.0.5'] - result = verify_rib(tgen, 'ipv4', dut, input_dict, next_hop=next_hop, - protocol=protocol) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + dut = "r3" + protocol = "bgp" + next_hop = ["10.0.0.2", "10.0.0.5"] + result = verify_rib( + tgen, "ipv4", dut, input_dict, next_hop=next_hop, protocol=protocol + ) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -390,7 +353,7 @@ def test_admin_distance_for_existing_static_routes(request): tgen = get_topogen() if BGP_CONVERGENCE is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name @@ -401,21 +364,21 @@ def test_admin_distance_for_existing_static_routes(request): input_dict = { "r1": { - "static_routes": [{ - "network": "10.0.20.1/32", - "admin_distance": 10, - "next_hop": "10.0.0.2" - }] + "static_routes": [ + { + "network": "10.0.20.1/32", + "admin_distance": 10, + "next_hop": "10.0.0.2", + } + ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) # Verifying admin distance once modified result = verify_admin_distance_for_static_routes(tgen, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -425,7 +388,7 @@ def test_advertise_network_using_network_command(request): tgen = get_topogen() if BGP_CONVERGENCE is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name @@ -442,14 +405,8 @@ def test_advertise_network_using_network_command(request): "ipv4": { "unicast": { "advertise_networks": [ - { - "network": "20.0.0.0/32", - "no_of_network": 10 - }, - { - "network": "30.0.0.0/32", - "no_of_network": 10 - } + {"network": "20.0.0.0/32", "no_of_network": 10}, + {"network": "30.0.0.0/32", "no_of_network": 10}, ] } } @@ -459,15 +416,13 @@ def test_advertise_network_using_network_command(request): } result = create_router_bgp(tgen, topo, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes - dut = 'r2' + dut = "r2" protocol = "bgp" - result = verify_rib(tgen, 'ipv4', dut, input_dict, protocol=protocol) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -480,7 +435,7 @@ def test_clear_bgp_and_verify(request): tgen = get_topogen() if BGP_CONVERGENCE is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name @@ -490,9 +445,8 @@ def test_clear_bgp_and_verify(request): reset_config_on_routers(tgen) # clear ip bgp - result = clear_bgp_and_verify(tgen, topo, 'r1') - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + result = clear_bgp_and_verify(tgen, topo, "r1") + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -509,7 +463,7 @@ def test_bgp_with_loopback_interface(request): tgen = get_topogen() if BGP_CONVERGENCE is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name @@ -518,79 +472,51 @@ def test_bgp_with_loopback_interface(request): # Creating configuration from JSON reset_config_on_routers(tgen) - for routerN in sorted(topo['routers'].keys()): - for bgp_neighbor in \ - topo['routers'][routerN]['bgp']['address_family']['ipv4'][ - 'unicast']['neighbor'].keys(): + for routerN in sorted(topo["routers"].keys()): + for bgp_neighbor in topo["routers"][routerN]["bgp"]["address_family"]["ipv4"][ + "unicast" + ]["neighbor"].keys(): # Adding ['source_link'] = 'lo' key:value pair - topo['routers'][routerN]['bgp']['address_family']['ipv4'][ - 'unicast']['neighbor'][bgp_neighbor]["dest_link"] = { - 'lo': { - "source_link": "lo", - } - } + topo["routers"][routerN]["bgp"]["address_family"]["ipv4"]["unicast"][ + "neighbor" + ][bgp_neighbor]["dest_link"] = {"lo": {"source_link": "lo",}} # Creating configuration from JSON build_config_from_json(tgen, topo) input_dict = { "r1": { - "static_routes": [{ - "network": "1.0.2.17/32", - "next_hop": "10.0.0.2" - }, - { - "network": "1.0.3.17/32", - "next_hop": "10.0.0.6" - } + "static_routes": [ + {"network": "1.0.2.17/32", "next_hop": "10.0.0.2"}, + {"network": "1.0.3.17/32", "next_hop": "10.0.0.6"}, ] }, "r2": { - "static_routes": [{ - "network": "1.0.1.17/32", - "next_hop": "10.0.0.1" - }, - { - "network": "1.0.3.17/32", - "next_hop": "10.0.0.10" - } + "static_routes": [ + {"network": "1.0.1.17/32", "next_hop": "10.0.0.1"}, + {"network": "1.0.3.17/32", "next_hop": "10.0.0.10"}, ] }, "r3": { - "static_routes": [{ - "network": "1.0.1.17/32", - "next_hop": "10.0.0.5" - }, - { - "network": "1.0.2.17/32", - "next_hop": "10.0.0.9" - }, - { - "network": "1.0.4.17/32", - "next_hop": "10.0.0.14" - } + "static_routes": [ + {"network": "1.0.1.17/32", "next_hop": "10.0.0.5"}, + {"network": "1.0.2.17/32", "next_hop": "10.0.0.9"}, + {"network": "1.0.4.17/32", "next_hop": "10.0.0.14"}, ] }, - "r4": { - "static_routes": [{ - "network": "1.0.3.17/32", - "next_hop": "10.0.0.13" - }] - } + "r4": {"static_routes": [{"network": "1.0.3.17/32", "next_hop": "10.0.0.13"}]}, } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) # Api call verify whether BGP is converged result = verify_bgp_convergence(tgen, topo) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp-ecmp-topo1/peer1/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer1/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer1/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer1/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer1/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer1/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer1/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer1/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer10/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer10/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer10/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer10/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer10/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer10/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer10/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer10/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer11/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer11/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer11/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer11/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer11/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer11/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer11/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer11/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer12/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer12/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer12/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer12/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer12/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer12/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer12/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer12/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer13/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer13/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer13/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer13/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer13/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer13/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer13/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer13/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer14/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer14/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer14/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer14/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer14/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer14/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer14/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer14/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer15/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer15/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer15/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer15/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer15/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer15/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer15/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer15/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer16/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer16/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer16/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer16/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer16/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer16/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer16/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer16/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer17/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer17/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer17/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer17/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer17/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer17/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer17/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer17/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer18/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer18/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer18/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer18/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer18/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer18/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer18/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer18/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer19/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer19/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer19/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer19/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer19/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer19/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer19/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer19/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer2/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer2/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer2/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer2/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer2/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer2/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer2/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer2/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer20/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer20/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer20/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer20/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer20/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer20/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer20/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer20/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer3/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer3/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer3/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer3/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer3/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer3/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer3/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer3/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer4/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer4/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer4/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer4/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer4/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer4/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer4/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer4/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer5/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer5/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer5/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer5/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer5/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer5/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer5/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer5/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer6/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer6/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer6/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer6/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer6/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer6/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer6/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer6/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer7/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer7/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer7/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer7/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer7/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer7/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer7/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer7/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer8/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer8/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer8/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer8/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer8/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer8/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer8/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer8/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/peer9/exa-receive.py b/tests/topotests/bgp-ecmp-topo1/peer9/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer9/exa-receive.py +++ b/tests/topotests/bgp-ecmp-topo1/peer9/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp-ecmp-topo1/peer9/exa-send.py b/tests/topotests/bgp-ecmp-topo1/peer9/exa-send.py index 647c254250..d9ae3d1906 100755 --- a/tests/topotests/bgp-ecmp-topo1/peer9/exa-send.py +++ b/tests/topotests/bgp-ecmp-topo1/peer9/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -13,37 +13,54 @@ sleep(5) # 2nd arg is number of routes to send peer = int(argv[1]) numRoutes = int(argv[2]) -if (peer <= 10): +if peer <= 10: asnum = 99 else: - asnum = peer+100 + asnum = peer + 100 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n' % (i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp\n" + % (i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes per PE - different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.202.%s.0/24 med 100 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n' % (i, peer, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.203.%s.0/24 med %i next-hop 10.0.%i.%i origin igp\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() # Announce numRoutes equal routes with different med per PE and different neighbor AS, but same source AS for i in range(0, numRoutes): - stdout.write('announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (i, peer, (((peer-1) / 5) + 1), peer+100, asnum)) + stdout.write( + "announce route 10.204.%s.0/24 med %i next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (i, peer, (((peer - 1) / 5) + 1), peer + 100, asnum) + ) stdout.flush() # Announce 2 different route per peer -stdout.write('announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n' % (peer, (((peer-1) / 5) + 1), peer+100)) -stdout.write('announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n' % (peer, (((peer-1) / 5) + 1), peer+100, asnum)) +stdout.write( + "announce route 10.205.%i.0/24 next-hop 10.0.%i.%i origin igp\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100) +) +stdout.write( + "announce route 10.206.%i.0/24 next-hop 10.0.%i.%i origin igp as-path [ %i 200 ]\n" + % (peer, (((peer - 1) / 5) + 1), peer + 100, asnum) +) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp-ecmp-topo1/test_bgp_ecmp_topo1.py b/tests/topotests/bgp-ecmp-topo1/test_bgp_ecmp_topo1.py index d806226dff..c37f818b0f 100755 --- a/tests/topotests/bgp-ecmp-topo1/test_bgp_ecmp_topo1.py +++ b/tests/topotests/bgp-ecmp-topo1/test_bgp_ecmp_topo1.py @@ -34,7 +34,7 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -61,23 +61,24 @@ class BGPECMPTopo1(Topo): tgen = get_topogen(self) # Create the BGP router - router = tgen.add_router('r1') + router = tgen.add_router("r1") # Setup Switches - 1 switch per 5 peering routers for swNum in range(1, (total_ebgp_peers + 4) / 5 + 1): - switch = tgen.add_switch('s{}'.format(swNum)) + switch = tgen.add_switch("s{}".format(swNum)) switch.add_link(router) # Add 'total_ebgp_peers' number of eBGP ExaBGP neighbors - for peerNum in range(1, total_ebgp_peers+1): - swNum = ((peerNum - 1) / 5 + 1) + for peerNum in range(1, total_ebgp_peers + 1): + swNum = (peerNum - 1) / 5 + 1 - peer_ip = '10.0.{}.{}'.format(swNum, peerNum + 100) - peer_route = 'via 10.0.{}.1'.format(swNum) - peer = tgen.add_exabgp_peer('peer{}'.format(peerNum), - ip=peer_ip, defaultRoute=peer_route) + peer_ip = "10.0.{}.{}".format(swNum, peerNum + 100) + peer_route = "via 10.0.{}.1".format(swNum) + peer = tgen.add_exabgp_peer( + "peer{}".format(peerNum), ip=peer_ip, defaultRoute=peer_route + ) - switch = tgen.gears['s{}'.format(swNum)] + switch = tgen.gears["s{}".format(swNum)] switch.add_link(peer) @@ -87,6 +88,7 @@ class BGPECMPTopo1(Topo): # ##################################################### + def setup_module(module): tgen = Topogen(BGPECMPTopo1, module.__name__) tgen.start_topology() @@ -95,21 +97,19 @@ def setup_module(module): router_list = tgen.routers() for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) router.start() # Starting Hosts and init ExaBGP on each of them - topotest.sleep(10, 'starting BGP on all {} peers'.format(total_ebgp_peers)) + topotest.sleep(10, "starting BGP on all {} peers".format(total_ebgp_peers)) peer_list = tgen.exabgp_peers() for pname, peer in peer_list.iteritems(): peer_dir = os.path.join(CWD, pname) - env_file = os.path.join(CWD, 'exabgp.env') + env_file = os.path.join(CWD, "exabgp.env") peer.start(peer_dir, env_file) logger.info(pname) @@ -128,11 +128,11 @@ def test_bgp_convergence(): pytest.skip(tgen.errors) # Expected result - router = tgen.gears['r1'] - if router.has_version('<', '3.0'): - reffile = os.path.join(CWD, 'r1/summary20.txt') + router = tgen.gears["r1"] + if router.has_version("<", "3.0"): + reffile = os.path.join(CWD, "r1/summary20.txt") else: - reffile = os.path.join(CWD, 'r1/summary.txt') + reffile = os.path.join(CWD, "r1/summary.txt") expected = json.loads(open(reffile).read()) @@ -142,18 +142,19 @@ def test_bgp_convergence(): with 'json') and compare with `data` contents. """ output = router.vtysh_cmd(cmd, isjson=True) - if 'ipv4Unicast' in output: - output['ipv4Unicast']['vrfName'] = \ - output['ipv4Unicast']['vrfName'].replace( - 'default', 'Default') - elif 'vrfName' in output: - output['vrfName'] = output['vrfName'].replace('default', 'Default') + if "ipv4Unicast" in output: + output["ipv4Unicast"]["vrfName"] = output["ipv4Unicast"]["vrfName"].replace( + "default", "Default" + ) + elif "vrfName" in output: + output["vrfName"] = output["vrfName"].replace("default", "Default") return topotest.json_cmp(output, data) test_func = functools.partial( - _output_summary_cmp, router, 'show ip bgp summary json', expected) + _output_summary_cmp, router, "show ip bgp summary json", expected + ) _, res = topotest.run_and_expect(test_func, None, count=60, wait=0.5) - assertmsg = 'BGP router network did not converge' + assertmsg = "BGP router network did not converge" assert res is None, assertmsg @@ -165,26 +166,26 @@ def test_bgp_ecmp(): pytest.skip(tgen.errors) expect = { - 'routerId': '10.0.255.1', - 'routes': { - }, + "routerId": "10.0.255.1", + "routes": {}, } for net in range(1, 5): for subnet in range(0, 10): - netkey = '10.20{}.{}.0/24'.format(net, subnet) - expect['routes'][netkey] = [] + netkey = "10.20{}.{}.0/24".format(net, subnet) + expect["routes"][netkey] = [] for _ in range(0, 10): - peer = {'multipath': True, 'valid': True} - expect['routes'][netkey].append(peer) + peer = {"multipath": True, "valid": True} + expect["routes"][netkey].append(peer) - test_func = functools.partial(topotest.router_json_cmp, - tgen.gears['r1'], 'show ip bgp json', expect) + test_func = functools.partial( + topotest.router_json_cmp, tgen.gears["r1"], "show ip bgp json", expect + ) _, res = topotest.run_and_expect(test_func, None, count=10, wait=0.5) assertmsg = 'expected multipath routes in "show ip bgp" output' assert res is None, assertmsg -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py b/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py index 4b9f419bf2..bad421768c 100755 --- a/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py +++ b/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py @@ -41,10 +41,11 @@ import sys import time import json import pytest + # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) -sys.path.append(os.path.join(CWD, '../../')) +sys.path.append(os.path.join(CWD, "../")) +sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -52,15 +53,17 @@ from lib.topogen import Topogen, get_topogen from mininet.topo import Topo from lib.common_config import ( - start_topology, write_test_header, + start_topology, + write_test_header, write_test_footer, - verify_rib, create_static_routes, check_address_types, - interface_status, reset_config_on_routers + verify_rib, + create_static_routes, + check_address_types, + interface_status, + reset_config_on_routers, ) from lib.topolog import logger -from lib.bgp import ( - verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify) +from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify from lib.topojson import build_topo_from_json, build_config_from_json # Reading the data from JSON File for topology and configuration creation @@ -130,27 +133,32 @@ def setup_module(mod): ADDR_TYPES = check_address_types() BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) - assert BGP_CONVERGENCE is True, ("setup_module :Failed \n Error:" - " {}".format(BGP_CONVERGENCE)) + assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format( + BGP_CONVERGENCE + ) - link_data = [val for links, val in - topo["routers"]["r2"]["links"].iteritems() - if "r3" in links] + link_data = [ + val + for links, val in topo["routers"]["r2"]["links"].iteritems() + if "r3" in links + ] for adt in ADDR_TYPES: NEXT_HOPS[adt] = [val[adt].split("/")[0] for val in link_data] if adt == "ipv4": - NEXT_HOPS[adt] = sorted( - NEXT_HOPS[adt], key=lambda x: int(x.split(".")[2])) + NEXT_HOPS[adt] = sorted(NEXT_HOPS[adt], key=lambda x: int(x.split(".")[2])) elif adt == "ipv6": NEXT_HOPS[adt] = sorted( - NEXT_HOPS[adt], key=lambda x: int(x.split(':')[-3], 16)) + NEXT_HOPS[adt], key=lambda x: int(x.split(":")[-3], 16) + ) INTF_LIST_R2 = [val["interface"].split("/")[0] for val in link_data] INTF_LIST_R2 = sorted(INTF_LIST_R2, key=lambda x: int(x.split("eth")[1])) - link_data = [val for links, val in - topo["routers"]["r3"]["links"].iteritems() - if "r2" in links] + link_data = [ + val + for links, val in topo["routers"]["r3"]["links"].iteritems() + if "r2" in links + ] INTF_LIST_R3 = [val["interface"].split("/")[0] for val in link_data] INTF_LIST_R3 = sorted(INTF_LIST_R3, key=lambda x: int(x.split("eth")[1])) @@ -179,40 +187,27 @@ def static_or_nw(tgen, topo, tc_name, test_type, dut): input_dict_static = { dut: { "static_routes": [ - { - "network": NETWORK["ipv4"], - "next_hop": NEXT_HOP_IP["ipv4"] - }, - { - "network": NETWORK["ipv6"], - "next_hop": NEXT_HOP_IP["ipv6"] - } + {"network": NETWORK["ipv4"], "next_hop": NEXT_HOP_IP["ipv4"]}, + {"network": NETWORK["ipv6"], "next_hop": NEXT_HOP_IP["ipv6"]}, ] } } logger.info("Configuring static route on router %s", dut) result = create_static_routes(tgen, input_dict_static) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) input_dict_2 = { dut: { "bgp": { "address_family": { "ipv4": { - "unicast": { - "redistribute": [{ - "redist_type": "static" - }] - } + "unicast": {"redistribute": [{"redist_type": "static"}]} }, "ipv6": { - "unicast": { - "redistribute": [{ - "redist_type": "static" - }] - } - } + "unicast": {"redistribute": [{"redist_type": "static"}]} + }, } } } @@ -221,7 +216,8 @@ def static_or_nw(tgen, topo, tc_name, test_type, dut): logger.info("Configuring redistribute static route on router %s", dut) result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) elif test_type == "advertise_nw": input_dict_nw = { @@ -230,28 +226,29 @@ def static_or_nw(tgen, topo, tc_name, test_type, dut): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [ - {"network": NETWORK["ipv4"]} - ] + "advertise_networks": [{"network": NETWORK["ipv4"]}] } }, "ipv6": { "unicast": { - "advertise_networks": [ - {"network": NETWORK["ipv6"]} - ] + "advertise_networks": [{"network": NETWORK["ipv6"]}] } - } + }, } } } } - logger.info("Advertising networks %s %s from router %s", - NETWORK["ipv4"], NETWORK["ipv6"], dut) + logger.info( + "Advertising networks %s %s from router %s", + NETWORK["ipv4"], + NETWORK["ipv6"], + dut, + ) result = create_router_bgp(tgen, topo, input_dict_nw) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) @pytest.mark.parametrize("ecmp_num", ["8", "16", "32"]) @@ -274,20 +271,8 @@ def test_modify_ecmp_max_paths(request, ecmp_num, test_type): "r3": { "bgp": { "address_family": { - "ipv4": { - "unicast": { - "maximum_paths": { - "ebgp": ecmp_num, - } - } - }, - "ipv6": { - "unicast": { - "maximum_paths": { - "ebgp": ecmp_num, - } - } - } + "ipv4": {"unicast": {"maximum_paths": {"ebgp": ecmp_num,}}}, + "ipv6": {"unicast": {"maximum_paths": {"ebgp": ecmp_num,}}}, } } } @@ -295,30 +280,27 @@ def test_modify_ecmp_max_paths(request, ecmp_num, test_type): logger.info("Configuring bgp maximum-paths %s on router r3", ecmp_num) result = create_router_bgp(tgen, topo, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" for addr_type in ADDR_TYPES: - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_1, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_1, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -338,44 +320,39 @@ def test_ecmp_after_clear_bgp(request): static_or_nw(tgen, topo, tc_name, "redist_static", "r2") for addr_type in ADDR_TYPES: - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_1, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_1, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Clear bgp result = clear_bgp_and_verify(tgen, topo, dut) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_1, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_1, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -395,22 +372,20 @@ def test_ecmp_remove_redistribute_static(request): # Verifying RIB routes dut = "r3" protocol = "bgp" - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_1, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_1, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) input_dict_2 = { "r2": { @@ -418,22 +393,14 @@ def test_ecmp_remove_redistribute_static(request): "address_family": { "ipv4": { "unicast": { - "redistribute": [{ - "redist_type": "static", - "delete": True - - }] + "redistribute": [{"redist_type": "static", "delete": True}] } }, "ipv6": { "unicast": { - "redistribute": [{ - "redist_type": "static", - "delete": True - - }] + "redistribute": [{"redist_type": "static", "delete": True}] } - } + }, } } } @@ -441,76 +408,60 @@ def test_ecmp_remove_redistribute_static(request): logger.info("Remove redistribute static") result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: # Verifying RIB routes dut = "r3" protocol = "bgp" - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3 are deleted", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_1, - next_hop=[], protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_1, + next_hop=[], + protocol=protocol, + expected=False, + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Routes still" " present in RIB".format(tc_name) logger.info("Enable redistribute static") input_dict_2 = { "r2": { "bgp": { "address_family": { - "ipv4": { - "unicast": { - "redistribute": [{ - "redist_type": "static" - }] - } - }, - "ipv6": { - "unicast": { - "redistribute": [{ - "redist_type": "static" - }] - } - } + "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}}, + "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}}, } } } } result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: # Verifying RIB routes dut = "r3" protocol = "bgp" - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_1, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_1, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -537,37 +488,30 @@ def test_ecmp_shut_bgp_neighbor(request): static_or_nw(tgen, topo, tc_name, "redist_static", "r2") for addr_type in ADDR_TYPES: - input_dict = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) - for intf_num in range(len(INTF_LIST_R2)+1, 16): - intf_val = INTF_LIST_R2[intf_num:intf_num+16] + for intf_num in range(len(INTF_LIST_R2) + 1, 16): + intf_val = INTF_LIST_R2[intf_num : intf_num + 16] - input_dict_1 = { - "r2": { - "interface_list": [intf_val], - "status": "down" - } - } - logger.info("Shutting down neighbor interface {} on r2". - format(intf_val)) + input_dict_1 = {"r2": {"interface_list": [intf_val], "status": "down"}} + logger.info("Shutting down neighbor interface {} on r2".format(intf_val)) result = interface_status(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) for addr_type in ADDR_TYPES: if intf_num + 16 < 32: @@ -575,52 +519,37 @@ def test_ecmp_shut_bgp_neighbor(request): else: check_hops = [] - input_dict = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict, - next_hop=check_hops, - protocol=protocol) + result = verify_rib( + tgen, addr_type, dut, input_dict, next_hop=check_hops, protocol=protocol + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) - input_dict_1 = { - "r2": { - "interface_list": INTF_LIST_R2, - "status": "up" - } - } + input_dict_1 = {"r2": {"interface_list": INTF_LIST_R2, "status": "up"}} logger.info("Enabling all neighbor interface {} on r2") result = interface_status(tgen, topo, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) static_or_nw(tgen, topo, tc_name, "redist_static", "r2") for addr_type in ADDR_TYPES: - input_dict = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -643,22 +572,20 @@ def test_ecmp_remove_static_route(request): static_or_nw(tgen, topo, tc_name, "redist_static", "r2") for addr_type in ADDR_TYPES: - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) result = verify_rib( - tgen, addr_type, dut, input_dict_1, - next_hop=NEXT_HOPS[addr_type], protocol=protocol) + tgen, + addr_type, + dut, + input_dict_1, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) for addr_type in ADDR_TYPES: input_dict_2 = { @@ -667,7 +594,7 @@ def test_ecmp_remove_static_route(request): { "network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type], - "delete": True + "delete": True, } ] } @@ -676,23 +603,29 @@ def test_ecmp_remove_static_route(request): logger.info("Remove static routes") result = create_static_routes(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) logger.info("Verifying %s routes on r3 are removed", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_2, - next_hop=[], protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_2, + next_hop=[], + protocol=protocol, + expected=False, + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Routes still" " present in RIB".format(tc_name) for addr_type in ADDR_TYPES: # Enable static routes input_dict_4 = { "r2": { "static_routes": [ - { - "network": NETWORK[addr_type], - "next_hop": NEXT_HOP_IP[addr_type] - } + {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]} ] } } @@ -700,14 +633,21 @@ def test_ecmp_remove_static_route(request): logger.info("Enable static route") result = create_static_routes(tgen, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_4, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_4, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) def test_ecmp_remove_nw_advertise(request): @@ -727,22 +667,20 @@ def test_ecmp_remove_nw_advertise(request): reset_config_on_routers(tgen) static_or_nw(tgen, topo, tc_name, "advertise_nw", "r2") for addr_type in ADDR_TYPES: - input_dict = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) input_dict_3 = { "r2": { @@ -750,64 +688,59 @@ def test_ecmp_remove_nw_advertise(request): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [{ - "network": NETWORK["ipv4"], - "delete": True - }] - } - }, + "advertise_networks": [ + {"network": NETWORK["ipv4"], "delete": True} + ] + } + }, "ipv6": { "unicast": { - "advertise_networks": [{ - "network": NETWORK["ipv6"], - "delete": True - }] - } + "advertise_networks": [ + {"network": NETWORK["ipv6"], "delete": True} + ] } - } + }, } } } + } logger.info("Withdraw advertised networks") result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: - input_dict = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict, - next_hop=[], protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict, + next_hop=[], + protocol=protocol, + expected=False, + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Routes still" " present in RIB".format(tc_name) static_or_nw(tgen, topo, tc_name, "advertise_nw", "r2") for addr_type in ADDR_TYPES: - input_dict = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) diff --git a/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py b/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py index a9f18ed1fa..9271a780bf 100755 --- a/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py +++ b/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py @@ -41,10 +41,11 @@ import sys import time import json import pytest + # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) -sys.path.append(os.path.join(CWD, '../../')) +sys.path.append(os.path.join(CWD, "../")) +sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -52,15 +53,17 @@ from lib.topogen import Topogen, get_topogen from mininet.topo import Topo from lib.common_config import ( - start_topology, write_test_header, + start_topology, + write_test_header, write_test_footer, - verify_rib, create_static_routes, check_address_types, - interface_status, reset_config_on_routers + verify_rib, + create_static_routes, + check_address_types, + interface_status, + reset_config_on_routers, ) from lib.topolog import logger -from lib.bgp import ( - verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify) +from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify from lib.topojson import build_topo_from_json, build_config_from_json # Reading the data from JSON File for topology and configuration creation @@ -131,27 +134,32 @@ def setup_module(mod): for addr_type in ADDR_TYPES: BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) - assert BGP_CONVERGENCE is True, ("setup_module :Failed \n Error:" - " {}".format(BGP_CONVERGENCE)) + assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format( + BGP_CONVERGENCE + ) - link_data = [val for links, val in - topo["routers"]["r2"]["links"].iteritems() - if "r3" in links] + link_data = [ + val + for links, val in topo["routers"]["r2"]["links"].iteritems() + if "r3" in links + ] for adt in ADDR_TYPES: NEXT_HOPS[adt] = [val[adt].split("/")[0] for val in link_data] if adt == "ipv4": - NEXT_HOPS[adt] = sorted( - NEXT_HOPS[adt], key=lambda x: int(x.split(".")[2])) + NEXT_HOPS[adt] = sorted(NEXT_HOPS[adt], key=lambda x: int(x.split(".")[2])) elif adt == "ipv6": NEXT_HOPS[adt] = sorted( - NEXT_HOPS[adt], key=lambda x: int(x.split(':')[-3], 16)) + NEXT_HOPS[adt], key=lambda x: int(x.split(":")[-3], 16) + ) INTF_LIST_R2 = [val["interface"].split("/")[0] for val in link_data] INTF_LIST_R2 = sorted(INTF_LIST_R2, key=lambda x: int(x.split("eth")[1])) - link_data = [val for links, val in - topo["routers"]["r3"]["links"].iteritems() - if "r2" in links] + link_data = [ + val + for links, val in topo["routers"]["r3"]["links"].iteritems() + if "r2" in links + ] INTF_LIST_R3 = [val["interface"].split("/")[0] for val in link_data] INTF_LIST_R3 = sorted(INTF_LIST_R3, key=lambda x: int(x.split("eth")[1])) @@ -180,40 +188,27 @@ def static_or_nw(tgen, topo, tc_name, test_type, dut): input_dict_static = { dut: { "static_routes": [ - { - "network": NETWORK["ipv4"], - "next_hop": NEXT_HOP_IP["ipv4"] - }, - { - "network": NETWORK["ipv6"], - "next_hop": NEXT_HOP_IP["ipv6"] - } + {"network": NETWORK["ipv4"], "next_hop": NEXT_HOP_IP["ipv4"]}, + {"network": NETWORK["ipv6"], "next_hop": NEXT_HOP_IP["ipv6"]}, ] } } logger.info("Configuring static route on router %s", dut) result = create_static_routes(tgen, input_dict_static) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) input_dict_2 = { dut: { "bgp": { "address_family": { "ipv4": { - "unicast": { - "redistribute": [{ - "redist_type": "static" - }] - } + "unicast": {"redistribute": [{"redist_type": "static"}]} }, "ipv6": { - "unicast": { - "redistribute": [{ - "redist_type": "static" - }] - } - } + "unicast": {"redistribute": [{"redist_type": "static"}]} + }, } } } @@ -222,7 +217,8 @@ def static_or_nw(tgen, topo, tc_name, test_type, dut): logger.info("Configuring redistribute static route on router %s", dut) result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) elif test_type == "advertise_nw": input_dict_nw = { @@ -231,28 +227,29 @@ def static_or_nw(tgen, topo, tc_name, test_type, dut): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [ - {"network": NETWORK["ipv4"]} - ] + "advertise_networks": [{"network": NETWORK["ipv4"]}] } }, "ipv6": { "unicast": { - "advertise_networks": [ - {"network": NETWORK["ipv6"]} - ] + "advertise_networks": [{"network": NETWORK["ipv6"]}] } - } + }, } } } } - logger.info("Advertising networks %s %s from router %s", - NETWORK["ipv4"], NETWORK["ipv6"], dut) + logger.info( + "Advertising networks %s %s from router %s", + NETWORK["ipv4"], + NETWORK["ipv6"], + dut, + ) result = create_router_bgp(tgen, topo, input_dict_nw) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) @pytest.mark.parametrize("ecmp_num", ["8", "16", "32"]) @@ -275,20 +272,8 @@ def test_modify_ecmp_max_paths(request, ecmp_num, test_type): "r3": { "bgp": { "address_family": { - "ipv4": { - "unicast": { - "maximum_paths": { - "ibgp": ecmp_num, - } - } - }, - "ipv6": { - "unicast": { - "maximum_paths": { - "ibgp": ecmp_num, - } - } - } + "ipv4": {"unicast": {"maximum_paths": {"ibgp": ecmp_num,}}}, + "ipv6": {"unicast": {"maximum_paths": {"ibgp": ecmp_num,}}}, } } } @@ -296,30 +281,27 @@ def test_modify_ecmp_max_paths(request, ecmp_num, test_type): logger.info("Configuring bgp maximum-paths %s on router r3", ecmp_num) result = create_router_bgp(tgen, topo, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" for addr_type in ADDR_TYPES: - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_1, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_1, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -339,44 +321,39 @@ def test_ecmp_after_clear_bgp(request): static_or_nw(tgen, topo, tc_name, "redist_static", "r2") for addr_type in ADDR_TYPES: - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_1, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_1, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Clear bgp result = clear_bgp_and_verify(tgen, topo, dut) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_1, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_1, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -396,22 +373,20 @@ def test_ecmp_remove_redistribute_static(request): # Verifying RIB routes dut = "r3" protocol = "bgp" - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_1, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_1, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) input_dict_2 = { "r2": { @@ -419,22 +394,14 @@ def test_ecmp_remove_redistribute_static(request): "address_family": { "ipv4": { "unicast": { - "redistribute": [{ - "redist_type": "static", - "delete": True - - }] + "redistribute": [{"redist_type": "static", "delete": True}] } }, "ipv6": { "unicast": { - "redistribute": [{ - "redist_type": "static", - "delete": True - - }] + "redistribute": [{"redist_type": "static", "delete": True}] } - } + }, } } } @@ -442,76 +409,60 @@ def test_ecmp_remove_redistribute_static(request): logger.info("Remove redistribute static") result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: # Verifying RIB routes dut = "r3" protocol = "bgp" - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3 are deleted", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_1, - next_hop=[], protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_1, + next_hop=[], + protocol=protocol, + expected=False, + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Routes still" " present in RIB".format(tc_name) logger.info("Enable redistribute static") input_dict_2 = { "r2": { "bgp": { "address_family": { - "ipv4": { - "unicast": { - "redistribute": [{ - "redist_type": "static" - }] - } - }, - "ipv6": { - "unicast": { - "redistribute": [{ - "redist_type": "static" - }] - } - } + "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}}, + "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}}, } } } } result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: # Verifying RIB routes dut = "r3" protocol = "bgp" - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_1, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_1, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -533,37 +484,30 @@ def test_ecmp_shut_bgp_neighbor(request): static_or_nw(tgen, topo, tc_name, "redist_static", "r2") for addr_type in ADDR_TYPES: - input_dict = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) - for intf_num in range(len(INTF_LIST_R2)+1, 16): - intf_val = INTF_LIST_R2[intf_num:intf_num+16] + for intf_num in range(len(INTF_LIST_R2) + 1, 16): + intf_val = INTF_LIST_R2[intf_num : intf_num + 16] - input_dict_1 = { - "r2": { - "interface_list": [intf_val], - "status": "down" - } - } - logger.info("Shutting down neighbor interface {} on r2". - format(intf_val)) + input_dict_1 = {"r2": {"interface_list": [intf_val], "status": "down"}} + logger.info("Shutting down neighbor interface {} on r2".format(intf_val)) result = interface_status(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) for addr_type in ADDR_TYPES: if intf_num + 16 < 32: @@ -571,52 +515,37 @@ def test_ecmp_shut_bgp_neighbor(request): else: check_hops = [] - input_dict = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict, - next_hop=check_hops, - protocol=protocol) + result = verify_rib( + tgen, addr_type, dut, input_dict, next_hop=check_hops, protocol=protocol + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) - input_dict_1 = { - "r2": { - "interface_list": INTF_LIST_R2, - "status": "up" - } - } + input_dict_1 = {"r2": {"interface_list": INTF_LIST_R2, "status": "up"}} logger.info("Enabling all neighbor interface {} on r2") result = interface_status(tgen, topo, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) static_or_nw(tgen, topo, tc_name, "redist_static", "r2") for addr_type in ADDR_TYPES: - input_dict = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -639,22 +568,20 @@ def test_ecmp_remove_static_route(request): static_or_nw(tgen, topo, tc_name, "redist_static", "r2") for addr_type in ADDR_TYPES: - input_dict_1 = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) result = verify_rib( - tgen, addr_type, dut, input_dict_1, - next_hop=NEXT_HOPS[addr_type], protocol=protocol) + tgen, + addr_type, + dut, + input_dict_1, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) for addr_type in ADDR_TYPES: input_dict_2 = { @@ -663,7 +590,7 @@ def test_ecmp_remove_static_route(request): { "network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type], - "delete": True + "delete": True, } ] } @@ -672,23 +599,29 @@ def test_ecmp_remove_static_route(request): logger.info("Remove static routes") result = create_static_routes(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) logger.info("Verifying %s routes on r3 are removed", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_2, - next_hop=[], protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_2, + next_hop=[], + protocol=protocol, + expected=False, + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Routes still" " present in RIB".format(tc_name) for addr_type in ADDR_TYPES: # Enable static routes input_dict_4 = { "r2": { "static_routes": [ - { - "network": NETWORK[addr_type], - "next_hop": NEXT_HOP_IP[addr_type] - } + {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]} ] } } @@ -696,14 +629,21 @@ def test_ecmp_remove_static_route(request): logger.info("Enable static route") result = create_static_routes(tgen, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict_4, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict_4, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -725,22 +665,20 @@ def test_ecmp_remove_nw_advertise(request): reset_config_on_routers(tgen) static_or_nw(tgen, topo, tc_name, "advertise_nw", "r2") for addr_type in ADDR_TYPES: - input_dict = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) input_dict_3 = { "r2": { @@ -748,64 +686,59 @@ def test_ecmp_remove_nw_advertise(request): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [{ - "network": NETWORK["ipv4"], - "delete": True - }] - } - }, + "advertise_networks": [ + {"network": NETWORK["ipv4"], "delete": True} + ] + } + }, "ipv6": { "unicast": { - "advertise_networks": [{ - "network": NETWORK["ipv6"], - "delete": True - }] - } + "advertise_networks": [ + {"network": NETWORK["ipv6"], "delete": True} + ] } - } + }, } } } + } logger.info("Withdraw advertised networks") result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: - input_dict = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict, - next_hop=[], protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict, + next_hop=[], + protocol=protocol, + expected=False, + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Routes still" " present in RIB".format(tc_name) static_or_nw(tgen, topo, tc_name, "advertise_nw", "r2") for addr_type in ADDR_TYPES: - input_dict = { - "r3": { - "static_routes": [ - { - "network": NETWORK[addr_type] - } - ] - } - } + input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}} logger.info("Verifying %s routes on r3", addr_type) - result = verify_rib(tgen, addr_type, dut, input_dict, - next_hop=NEXT_HOPS[addr_type], - protocol=protocol) + result = verify_rib( + tgen, + addr_type, + dut, + input_dict, + next_hop=NEXT_HOPS[addr_type], + protocol=protocol, + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) if __name__ == "__main__": diff --git a/tests/topotests/bgp-path-attributes-topo1/test_bgp_path_attributes.py b/tests/topotests/bgp-path-attributes-topo1/test_bgp_path_attributes.py index 1cd2c4417f..b0ff3ac437 100755 --- a/tests/topotests/bgp-path-attributes-topo1/test_bgp_path_attributes.py +++ b/tests/topotests/bgp-path-attributes-topo1/test_bgp_path_attributes.py @@ -72,18 +72,26 @@ from lib.topogen import Topogen, TopoRouter, get_topogen # Required to instantiate the topology builder class. from lib.common_config import ( - start_topology, write_test_header, - write_test_footer, reset_config_on_routers, - verify_rib, create_static_routes, - create_prefix_lists, verify_prefix_lists, - create_route_maps, check_address_types + start_topology, + write_test_header, + write_test_footer, + reset_config_on_routers, + verify_rib, + create_static_routes, + create_prefix_lists, + verify_prefix_lists, + create_route_maps, + check_address_types, ) from lib.topolog import logger from lib.bgp import ( - verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify, verify_best_path_as_per_bgp_attribute, - verify_best_path_as_per_admin_distance, modify_as_number, - verify_as_numbers + verify_bgp_convergence, + create_router_bgp, + clear_bgp_and_verify, + verify_best_path_as_per_bgp_attribute, + verify_best_path_as_per_admin_distance, + modify_as_number, + verify_as_numbers, ) from lib.topojson import build_topo_from_json, build_config_from_json @@ -147,8 +155,7 @@ def setup_module(mod): # Checking BGP convergence result = verify_bgp_convergence(tgen, topo) - assert result is True, ("setup_module :Failed \n Error:" - " {}".format(result)) + assert result is True, "setup_module :Failed \n Error:" " {}".format(result) logger.info("Running setup_module() done") @@ -165,8 +172,7 @@ def teardown_module(): # Stop toplogy and Remove tmp files tgen.stop_topology() - logger.info("Testsuite end time: %s", - time.asctime(time.localtime(time.time()))) + logger.info("Testsuite end time: %s", time.asctime(time.localtime(time.time()))) logger.info("=" * 40) @@ -176,6 +182,7 @@ def teardown_module(): ## ##################################################### + def test_next_hop_attribute(request): """ Verifying route are not getting installed in, as next_hop is @@ -204,44 +211,38 @@ def test_next_hop_attribute(request): "ipv4": { "unicast": { "advertise_networks": [ - { - "network": "200.50.2.0/32" - }, - { - "network": "200.60.2.0/32" - } + {"network": "200.50.2.0/32"}, + {"network": "200.60.2.0/32"}, ] } }, "ipv6": { "unicast": { "advertise_networks": [ - { - "network": "200:50:2::/128" - }, - { - "network": "200:60:2::/128" - } + {"network": "200:50:2::/128"}, + {"network": "200:60:2::/128"}, ] } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r1" protocol = "bgp" # Verification should fail as nexthop-self is not enabled for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Error: "\ + result = verify_rib( + tgen, addr_type, dut, input_dict, protocol=protocol, expected=False + ) + assert result is not True, ( + "Testcase {} : Failed \n Error: " "{} routes are not present in RIB".format(addr_type, tc_name) + ) # Configure next-hop-self to bgp neighbor input_dict_1 = { @@ -251,25 +252,17 @@ def test_next_hop_attribute(request): "ipv4": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r2": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r2": {"next_hop_self": True}}} } } }, "ipv6": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r2": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r2": {"next_hop_self": True}}} } } - } + }, } } }, @@ -279,42 +272,33 @@ def test_next_hop_attribute(request): "ipv4": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r3": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r3": {"next_hop_self": True}}} } } }, "ipv6": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r3": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r3": {"next_hop_self": True}}} } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r1" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -343,27 +327,19 @@ def test_aspath_attribute(request): "ipv4": { "unicast": { "advertise_networks": [ - { - "network": "200.50.2.0/32" - }, - { - "network": "200.60.2.0/32" - } + {"network": "200.50.2.0/32"}, + {"network": "200.60.2.0/32"}, ] } }, "ipv6": { "unicast": { "advertise_networks": [ - { - "network": "200:50:2::/128" - }, - { - "network": "200:60:2::/128" - } + {"network": "200:50:2::/128"}, + {"network": "200:60:2::/128"}, ] } - } + }, } } }, @@ -373,25 +349,17 @@ def test_aspath_attribute(request): "ipv4": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r2": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r2": {"next_hop_self": True}}} } } }, "ipv6": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r2": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r2": {"next_hop_self": True}}} } } - } + }, } } }, @@ -401,42 +369,34 @@ def test_aspath_attribute(request): "ipv4": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r3": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r3": {"next_hop_self": True}}} } } }, "ipv6": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r3": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r3": {"next_hop_self": True}}} } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying best path dut = "r1" attribute = "path" for addr_type in ADDR_TYPES: - result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut, - {"r7": input_dict["r7"]}, - attribute) + result = verify_best_path_as_per_bgp_attribute( + tgen, addr_type, dut, {"r7": input_dict["r7"]}, attribute + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Modify AS-Path and verify best path is changed # Create Prefix list @@ -445,66 +405,52 @@ def test_aspath_attribute(request): "r3": { "prefix_lists": { "ipv4": { - "pf_ls_1_ipv4": [{ - "seqid": 10, - "network": "200.0.0.0/8", - "le": "32", - "action": "permit" - }] + "pf_ls_1_ipv4": [ + { + "seqid": 10, + "network": "200.0.0.0/8", + "le": "32", + "action": "permit", + } + ] }, "ipv6": { - "pf_ls_1_ipv6": [{ - "seqid": 10, - "network": "200::/8", - "le": "128", - "action": "permit" - }] - } + "pf_ls_1_ipv6": [ + { + "seqid": 10, + "network": "200::/8", + "le": "128", + "action": "permit", + } + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map input_dict_3 = { "r3": { "route_maps": { - "RMAP_AS_PATH": [{ - "action": "permit", - "match": { - "ipv4": { - "prefix_lists": "pf_ls_1_ipv4" - } + "RMAP_AS_PATH": [ + { + "action": "permit", + "match": {"ipv4": {"prefix_lists": "pf_ls_1_ipv4"}}, + "set": {"path": {"as_num": "111 222", "as_action": "prepend"}}, }, - "set": { - "path": { - "as_num": "111 222", - "as_action": "prepend" - } - } - }, - { - "action": "permit", - "match": { - "ipv6": { - "prefix_lists": "pf_ls_1_ipv6" - } + { + "action": "permit", + "match": {"ipv6": {"prefix_lists": "pf_ls_1_ipv6"}}, + "set": {"path": {"as_num": "111 222", "as_action": "prepend"}}, }, - "set": { - "path": { - "as_num": "111 222", - "as_action": "prepend" - } - } - }] + ] } } } result = create_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure neighbor for route map input_dict_4 = { @@ -518,8 +464,10 @@ def test_aspath_attribute(request): "dest_link": { "r3": { "route_maps": [ - {"name": "RMAP_AS_PATH", - "direction": "in"} + { + "name": "RMAP_AS_PATH", + "direction": "in", + } ] } } @@ -534,32 +482,34 @@ def test_aspath_attribute(request): "dest_link": { "r3": { "route_maps": [ - {"name": "RMAP_AS_PATH", - "direction": "in"} + { + "name": "RMAP_AS_PATH", + "direction": "in", + } ] } } } } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying best path dut = "r1" attribute = "path" for addr_type in ADDR_TYPES: - result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut, - {"r7": input_dict["r7"]}, - attribute) + result = verify_best_path_as_per_bgp_attribute( + tgen, addr_type, dut, {"r7": input_dict["r7"]}, attribute + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -588,27 +538,19 @@ def test_localpref_attribute(request): "ipv4": { "unicast": { "advertise_networks": [ - { - "network": "200.50.2.0/32" - }, - { - "network": "200.60.2.0/32" - } + {"network": "200.50.2.0/32"}, + {"network": "200.60.2.0/32"}, ] } }, "ipv6": { "unicast": { "advertise_networks": [ - { - "network": "200:50:2::/128" - }, - { - "network": "200:60:2::/128" - } + {"network": "200:50:2::/128"}, + {"network": "200:60:2::/128"}, ] } - } + }, } } }, @@ -618,25 +560,17 @@ def test_localpref_attribute(request): "ipv4": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r2": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r2": {"next_hop_self": True}}} } } }, "ipv6": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r2": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r2": {"next_hop_self": True}}} } } - } + }, } } }, @@ -646,95 +580,78 @@ def test_localpref_attribute(request): "ipv4": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r3": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r3": {"next_hop_self": True}}} } } }, "ipv6": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r3": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r3": {"next_hop_self": True}}} } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create Prefix list input_dict_2 = { "r2": { "prefix_lists": { "ipv4": { - "pf_ls_1_ipv4": [{ - "seqid": 10, - "network": "200.0.0.0/8", - "le": "32", - "action": "permit" - }] + "pf_ls_1_ipv4": [ + { + "seqid": 10, + "network": "200.0.0.0/8", + "le": "32", + "action": "permit", + } + ] }, "ipv6": { - "pf_ls_1_ipv6": [{ - "seqid": 10, - "network": "200::/8", - "le": "128", - "action": "permit" - }] - } + "pf_ls_1_ipv6": [ + { + "seqid": 10, + "network": "200::/8", + "le": "128", + "action": "permit", + } + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map input_dict_3 = { "r2": { "route_maps": { - "RMAP_LOCAL_PREF": [{ - "action": "permit", - "seq_id": "10", - "match": { - "ipv4": { - "prefix_lists": "pf_ls_1_ipv4" - } + "RMAP_LOCAL_PREF": [ + { + "action": "permit", + "seq_id": "10", + "match": {"ipv4": {"prefix_lists": "pf_ls_1_ipv4"}}, + "set": {"locPrf": 1111}, }, - "set": { - "locPrf": 1111 - } - }, - { - "action": "permit", - "seq_id": "20", - "match": { - "ipv6": { - "prefix_lists": "pf_ls_1_ipv6" - } + { + "action": "permit", + "seq_id": "20", + "match": {"ipv6": {"prefix_lists": "pf_ls_1_ipv6"}}, + "set": {"locPrf": 1111}, }, - "set": { - "locPrf": 1111 - } - }] + ] } } } result = create_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure neighbor for route map input_dict_4 = { @@ -748,8 +665,10 @@ def test_localpref_attribute(request): "dest_link": { "r2-link1": { "route_maps": [ - {"name": "RMAP_LOCAL_PREF", - "direction": "in"} + { + "name": "RMAP_LOCAL_PREF", + "direction": "in", + } ] } } @@ -764,77 +683,69 @@ def test_localpref_attribute(request): "dest_link": { "r2-link1": { "route_maps": [ - {"name": "RMAP_LOCAL_PREF", - "direction": "in"} + { + "name": "RMAP_LOCAL_PREF", + "direction": "in", + } ] } } } } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying best path dut = "r1" attribute = "locPrf" for addr_type in ADDR_TYPES: - result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut, - {"r7": input_dict["r7"]}, - attribute) + result = verify_best_path_as_per_bgp_attribute( + tgen, addr_type, dut, {"r7": input_dict["r7"]}, attribute + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Modify route map input_dict_3 = { "r2": { "route_maps": { - "RMAP_LOCAL_PREF": [{ - "action": "permit", - "seq_id": "10", - "match": { - "ipv4": { - "prefix_lists": "pf_ls_1_ipv4" - } + "RMAP_LOCAL_PREF": [ + { + "action": "permit", + "seq_id": "10", + "match": {"ipv4": {"prefix_lists": "pf_ls_1_ipv4"}}, + "set": {"locPrf": 50}, }, - "set": { - "locPrf": 50 - } - }, - { - "action": "permit", - "seq_id": "20", - "match": { - "ipv6": { - "prefix_lists": "pf_ls_1_ipv6" - } + { + "action": "permit", + "seq_id": "20", + "match": {"ipv6": {"prefix_lists": "pf_ls_1_ipv6"}}, + "set": {"locPrf": 50}, }, - "set": { - "locPrf": 50 - } - }] + ] } } } result = create_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying best path dut = "r1" attribute = "locPrf" for addr_type in ADDR_TYPES: - result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut, - {"r7": input_dict["r7"]}, - attribute) + result = verify_best_path_as_per_bgp_attribute( + tgen, addr_type, dut, {"r7": input_dict["r7"]}, attribute + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -866,27 +777,19 @@ def test_weight_attribute(request): "ipv4": { "unicast": { "advertise_networks": [ - { - "network": "200.50.2.0/32" - }, - { - "network": "200.60.2.0/32" - } + {"network": "200.50.2.0/32"}, + {"network": "200.60.2.0/32"}, ] } }, "ipv6": { "unicast": { "advertise_networks": [ - { - "network": "200:50:2::/128" - }, - { - "network": "200:60:2::/128" - } + {"network": "200:50:2::/128"}, + {"network": "200:60:2::/128"}, ] } - } + }, } } }, @@ -896,25 +799,17 @@ def test_weight_attribute(request): "ipv4": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r2": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r2": {"next_hop_self": True}}} } } }, "ipv6": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r2": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r2": {"next_hop_self": True}}} } } - } + }, } } }, @@ -924,94 +819,77 @@ def test_weight_attribute(request): "ipv4": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r3": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r3": {"next_hop_self": True}}} } } }, "ipv6": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r3": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r3": {"next_hop_self": True}}} } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create Prefix list input_dict_2 = { "r1": { "prefix_lists": { "ipv4": { - "pf_ls_1_ipv4": [{ - "seqid": 10, - "network": "200.0.0.0/8", - "le": "32", - "action": "permit" - }] + "pf_ls_1_ipv4": [ + { + "seqid": 10, + "network": "200.0.0.0/8", + "le": "32", + "action": "permit", + } + ] }, "ipv6": { - "pf_ls_1_ipv6": [{ - "seqid": 10, - "network": "200::/8", - "le": "128", - "action": "permit" - }] - } + "pf_ls_1_ipv6": [ + { + "seqid": 10, + "network": "200::/8", + "le": "128", + "action": "permit", + } + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map input_dict_3 = { "r1": { "route_maps": { - "RMAP_WEIGHT": [{ - "action": "permit", - "seq_id": "5", - "match": { - "ipv4": { - "prefix_lists": "pf_ls_1_ipv4" - } + "RMAP_WEIGHT": [ + { + "action": "permit", + "seq_id": "5", + "match": {"ipv4": {"prefix_lists": "pf_ls_1_ipv4"}}, + "set": {"weight": 500}, }, - "set": { - "weight": 500 - } - }, - { - "action": "permit", - "seq_id": "10", - "match": { - "ipv6": { - "prefix_lists": "pf_ls_1_ipv6" - } + { + "action": "permit", + "seq_id": "10", + "match": {"ipv6": {"prefix_lists": "pf_ls_1_ipv6"}}, + "set": {"weight": 500}, }, - "set": { - "weight": 500 - } - }] + ] } } } result = create_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure neighbor for route map input_dict_4 = { @@ -1025,8 +903,10 @@ def test_weight_attribute(request): "dest_link": { "r1": { "route_maps": [ - {"name": "RMAP_WEIGHT", - "direction": "in"} + { + "name": "RMAP_WEIGHT", + "direction": "in", + } ] } } @@ -1041,77 +921,69 @@ def test_weight_attribute(request): "dest_link": { "r1": { "route_maps": [ - {"name": "RMAP_WEIGHT", - "direction": "in"} + { + "name": "RMAP_WEIGHT", + "direction": "in", + } ] } } } } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying best path dut = "r1" attribute = "weight" for addr_type in ADDR_TYPES: - result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut, - {"r7": input_dict["r7"]}, - attribute) + result = verify_best_path_as_per_bgp_attribute( + tgen, addr_type, dut, {"r7": input_dict["r7"]}, attribute + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Modify route map input_dict_3 = { "r1": { "route_maps": { - "RMAP_WEIGHT": [{ - "action": "permit", - "seq_id": "5", - "match": { - "ipv4": { - "prefix_lists": "pf_ls_1_ipv4" - } + "RMAP_WEIGHT": [ + { + "action": "permit", + "seq_id": "5", + "match": {"ipv4": {"prefix_lists": "pf_ls_1_ipv4"}}, + "set": {"weight": 1000}, }, - "set": { - "weight": 1000 - } - }, - { - "action": "permit", - "seq_id": "10", - "match": { - "ipv6": { - "prefix_lists": "pf_ls_1_ipv6" - } + { + "action": "permit", + "seq_id": "10", + "match": {"ipv6": {"prefix_lists": "pf_ls_1_ipv6"}}, + "set": {"weight": 1000}, }, - "set": { - "weight": 1000 - } - }] + ] } } } result = create_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying best path dut = "r1" attribute = "weight" for addr_type in ADDR_TYPES: - result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut, - {"r7": input_dict["r7"]}, - attribute) + result = verify_best_path_as_per_bgp_attribute( + tgen, addr_type, dut, {"r7": input_dict["r7"]}, attribute + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -1143,27 +1015,19 @@ def test_origin_attribute(request): "ipv4": { "unicast": { "advertise_networks": [ - { - "network": "200.50.2.0/32" - }, - { - "network": "200.60.2.0/32" - } + {"network": "200.50.2.0/32"}, + {"network": "200.60.2.0/32"}, ] } }, "ipv6": { "unicast": { "advertise_networks": [ - { - "network": "200:50:2::/128" - }, - { - "network": "200:60:2::/128" - } + {"network": "200:50:2::/128"}, + {"network": "200:60:2::/128"}, ] } - } + }, } } }, @@ -1173,25 +1037,17 @@ def test_origin_attribute(request): "ipv4": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r2": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r2": {"next_hop_self": True}}} } } }, "ipv6": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r2": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r2": {"next_hop_self": True}}} } } - } + }, } } }, @@ -1201,25 +1057,17 @@ def test_origin_attribute(request): "ipv4": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r3": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r3": {"next_hop_self": True}}} } } }, "ipv6": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r3": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r3": {"next_hop_self": True}}} } } - } + }, } } }, @@ -1230,7 +1078,7 @@ def test_origin_attribute(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } }, @@ -1238,54 +1086,41 @@ def test_origin_attribute(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to create static routes input_dict_3 = { "r5": { "static_routes": [ - { - "network": "200.50.2.0/32", - "next_hop": "Null0" - }, - { - "network": "200.60.2.0/32", - "next_hop": "Null0" - }, - { - "network": "200:50:2::/128", - "next_hop": "Null0" - }, - { - "network": "200:60:2::/128", - "next_hop": "Null0" - } + {"network": "200.50.2.0/32", "next_hop": "Null0"}, + {"network": "200.60.2.0/32", "next_hop": "Null0"}, + {"network": "200:50:2::/128", "next_hop": "Null0"}, + {"network": "200:60:2::/128", "next_hop": "Null0"}, ] } } result = create_static_routes(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying best path dut = "r1" attribute = "origin" for addr_type in ADDR_TYPES: - result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut, - {"r4": input_dict["r4"]}, - attribute) + result = verify_best_path_as_per_bgp_attribute( + tgen, addr_type, dut, {"r4": input_dict["r4"]}, attribute + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -1317,27 +1152,19 @@ def test_med_attribute(request): "ipv4": { "unicast": { "advertise_networks": [ - { - "network": "200.50.2.0/32" - }, - { - "network": "200.60.2.0/32" - } + {"network": "200.50.2.0/32"}, + {"network": "200.60.2.0/32"}, ] } }, "ipv6": { "unicast": { "advertise_networks": [ - { - "network": "200:50:2::/128" - }, - { - "network": "200:60:2::/128" - } + {"network": "200:50:2::/128"}, + {"network": "200:60:2::/128"}, ] } - } + }, } } }, @@ -1347,145 +1174,122 @@ def test_med_attribute(request): "ipv4": { "unicast": { "advertise_networks": [ - { - "network": "200.50.2.0/32" - }, - { - "network": "200.60.2.0/32" - } + {"network": "200.50.2.0/32"}, + {"network": "200.60.2.0/32"}, ] } }, "ipv6": { "unicast": { "advertise_networks": [ - { - "network": "200:50:2::/128" - }, - { - "network": "200:60:2::/128" - } + {"network": "200:50:2::/128"}, + {"network": "200:60:2::/128"}, ] } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create Prefix list input_dict_2 = { "r2": { "prefix_lists": { "ipv4": { - "pf_ls_r2_ipv4": [{ - "seqid": 10, - "network": "200.0.0.0/8", - "le": "32", - "action": "permit" - }] + "pf_ls_r2_ipv4": [ + { + "seqid": 10, + "network": "200.0.0.0/8", + "le": "32", + "action": "permit", + } + ] }, "ipv6": { - "pf_ls_r2_ipv6": [{ - "seqid": 20, - "network": "200::/8", - "le": "128", - "action": "permit" - }] - } + "pf_ls_r2_ipv6": [ + { + "seqid": 20, + "network": "200::/8", + "le": "128", + "action": "permit", + } + ] + }, } }, "r3": { "prefix_lists": { "ipv4": { - "pf_ls_r3_ipv4": [{ - "seqid": 10, - "network": "200.0.0.0/8", - "le": "32", - "action": "permit" - }] + "pf_ls_r3_ipv4": [ + { + "seqid": 10, + "network": "200.0.0.0/8", + "le": "32", + "action": "permit", + } + ] }, "ipv6": { - "pf_ls_r3_ipv6": [{ - "seqid": 20, - "network": "200::/8", - "le": "128", - "action": "permit" - }] - } + "pf_ls_r3_ipv6": [ + { + "seqid": 20, + "network": "200::/8", + "le": "128", + "action": "permit", + } + ] + }, } - } + }, } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map input_dict_3 = { "r2": { "route_maps": { - "RMAP_MED_R2": [{ - "action": "permit", - "seq_id": "10", - "match": { - "ipv4": { - "prefix_lists": "pf_ls_r2_ipv4" - } + "RMAP_MED_R2": [ + { + "action": "permit", + "seq_id": "10", + "match": {"ipv4": {"prefix_lists": "pf_ls_r2_ipv4"}}, + "set": {"metric": 100}, }, - "set": { - "metric": 100 - } - }, - { - "action": "permit", - "seq_id": "20", - "match": { - "ipv6": { - "prefix_lists": "pf_ls_r2_ipv6" - } + { + "action": "permit", + "seq_id": "20", + "match": {"ipv6": {"prefix_lists": "pf_ls_r2_ipv6"}}, + "set": {"metric": 100}, }, - "set": { - "metric": 100 - } - }] + ] } }, "r3": { "route_maps": { - "RMAP_MED_R3": [{ - "action": "permit", - "seq_id": "10", - "match": { - "ipv4": { - "prefix_lists": "pf_ls_r3_ipv4" - } + "RMAP_MED_R3": [ + { + "action": "permit", + "seq_id": "10", + "match": {"ipv4": {"prefix_lists": "pf_ls_r3_ipv4"}}, + "set": {"metric": 10}, }, - "set": { - "metric": 10 - } - }, - { - "action": "permit", - "seq_id": "20", - "match": { - "ipv6": { - "prefix_lists": "pf_ls_r3_ipv6" - } + { + "action": "permit", + "seq_id": "20", + "match": {"ipv6": {"prefix_lists": "pf_ls_r3_ipv6"}}, + "set": {"metric": 10}, }, - "set": { - "metric": 10 - } - }] + ] } - } + }, } result = create_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure neighbor for route map input_dict_4 = { @@ -1499,17 +1303,15 @@ def test_med_attribute(request): "dest_link": { "r2-link1": { "route_maps": [ - {"name": "RMAP_MED_R2", - "direction": "in"} + { + "name": "RMAP_MED_R2", + "direction": "in", + } ] } } }, - "r1": { - "dest_link": { - "r2": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r2": {"next_hop_self": True}}}, } } }, @@ -1520,20 +1322,18 @@ def test_med_attribute(request): "dest_link": { "r2-link1": { "route_maps": [ - {"name": "RMAP_MED_R2", - "direction": "in"} + { + "name": "RMAP_MED_R2", + "direction": "in", + } ] } } }, - "r1": { - "dest_link": { - "r2": {"next_hop_self": True} - } - } + "r1": {"dest_link": {"r2": {"next_hop_self": True}}}, } } - } + }, } } }, @@ -1543,107 +1343,95 @@ def test_med_attribute(request): "ipv4": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r3": {"next_hop_self": True} - } - }, + "r1": {"dest_link": {"r3": {"next_hop_self": True}}}, "r5": { "dest_link": { "r3": { "route_maps": [ - {"name": "RMAP_MED_R3", - "direction": "in"} + { + "name": "RMAP_MED_R3", + "direction": "in", + } ] } } - } + }, } } }, "ipv6": { "unicast": { "neighbor": { - "r1": { - "dest_link": { - "r3": {"next_hop_self": True} - } - }, + "r1": {"dest_link": {"r3": {"next_hop_self": True}}}, "r5": { "dest_link": { "r3": { "route_maps": [ - {"name": "RMAP_MED_R3", - "direction": "in"} + { + "name": "RMAP_MED_R3", + "direction": "in", + } ] } } - } + }, } } - } + }, } } - } + }, } - result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + result = create_router_bgp(tgen, topo, input_dict_4) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying best path dut = "r1" attribute = "metric" for addr_type in ADDR_TYPES: - result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut, - input_dict, attribute) + result = verify_best_path_as_per_bgp_attribute( + tgen, addr_type, dut, input_dict, attribute + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Modify route-map to set med value input_dict_3 = { "r3": { "route_maps": { - "RMAP_MED_R3": [{ - "action": "permit", - "seq_id": "10", - "match": { - "ipv4": { - "prefix_lists": "pf_ls_r3_ipv4" - } + "RMAP_MED_R3": [ + { + "action": "permit", + "seq_id": "10", + "match": {"ipv4": {"prefix_lists": "pf_ls_r3_ipv4"}}, + "set": {"metric": 200}, }, - "set": { - "metric": 200 - } - }, - { - "action": "permit", - "seq_id": "20", - "match": { - "ipv6": { - "prefix_lists": "pf_ls_r3_ipv6" - } + { + "action": "permit", + "seq_id": "20", + "match": {"ipv6": {"prefix_lists": "pf_ls_r3_ipv6"}}, + "set": {"metric": 200}, }, - "set": { - "metric": 200 - } - }] + ] } } } result = create_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying best path dut = "r1" attribute = "metric" for addr_type in ADDR_TYPES: - result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut, - input_dict, attribute) + result = verify_best_path_as_per_bgp_attribute( + tgen, addr_type, dut, input_dict, attribute + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -1674,29 +1462,28 @@ def test_admin_distance(request): { "network": "200.50.2.0/32", "admin_distance": 80, - "next_hop": "10.0.0.14" + "next_hop": "10.0.0.14", }, { "network": "200.50.2.0/32", "admin_distance": 60, - "next_hop": "10.0.0.18" + "next_hop": "10.0.0.18", }, { "network": "200:50:2::/128", "admin_distance": 80, - "next_hop": "fd00::1" + "next_hop": "fd00::1", }, { "network": "200:50:2::/128", "admin_distance": 60, - "next_hop": "fd00::1" - } + "next_hop": "fd00::1", + }, ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to redistribute static routes input_dict_2 = { @@ -1707,7 +1494,7 @@ def test_admin_distance(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } }, @@ -1715,60 +1502,63 @@ def test_admin_distance(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } - } + }, } } } } result = create_router_bgp(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying best path dut = "r1" attribute = "admin_distance" input_dict = { - "ipv4": { - "r2": { - "static_routes": [{ - "network": "200.50.2.0/32", - "admin_distance": 80, - "next_hop": "10.0.0.14" - }, - { - "network": "200.50.2.0/32", - "admin_distance": 60, - "next_hop": "10.0.0.18" - } - ] - } - }, - "ipv6": { - "r2": { - "static_routes": [{ - "network": "200:50:2::/128", - "admin_distance": 80, - "next_hop": "fd00::1" - }, - { - "network": "200:50:2::/128", - "admin_distance": 60, - "next_hop": "fd00::1" - }] + "ipv4": { + "r2": { + "static_routes": [ + { + "network": "200.50.2.0/32", + "admin_distance": 80, + "next_hop": "10.0.0.14", + }, + { + "network": "200.50.2.0/32", + "admin_distance": 60, + "next_hop": "10.0.0.18", + }, + ] } - } + }, + "ipv6": { + "r2": { + "static_routes": [ + { + "network": "200:50:2::/128", + "admin_distance": 80, + "next_hop": "fd00::1", + }, + { + "network": "200:50:2::/128", + "admin_distance": 60, + "next_hop": "fd00::1", + }, + ] + } + }, } for addr_type in ADDR_TYPES: - result = verify_best_path_as_per_admin_distance(tgen, addr_type, dut, - input_dict[addr_type], - attribute) + result = verify_best_path_as_per_admin_distance( + tgen, addr_type, dut, input_dict[addr_type], attribute + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) diff --git a/tests/topotests/bgp-prefix-list-topo1/test_prefix_lists.py b/tests/topotests/bgp-prefix-list-topo1/test_prefix_lists.py index b8975997ea..22952f645c 100755 --- a/tests/topotests/bgp-prefix-list-topo1/test_prefix_lists.py +++ b/tests/topotests/bgp-prefix-list-topo1/test_prefix_lists.py @@ -60,16 +60,17 @@ from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration from lib.common_config import ( - start_topology, write_test_header, - write_test_footer, reset_config_on_routers, - verify_rib, create_static_routes, - create_prefix_lists, verify_prefix_lists + start_topology, + write_test_header, + write_test_footer, + reset_config_on_routers, + verify_rib, + create_static_routes, + create_prefix_lists, + verify_prefix_lists, ) from lib.topolog import logger -from lib.bgp import ( - verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify -) +from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify from lib.topojson import build_topo_from_json, build_config_from_json # Reading the data from JSON File for topology creation @@ -109,7 +110,7 @@ def setup_module(mod): testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) - logger.info("="*40) + logger.info("=" * 40) logger.info("Running setup_module to create topology") @@ -133,8 +134,9 @@ def setup_module(mod): # Api call verify whether BGP is converged BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) - assert BGP_CONVERGENCE is True, ("setup_module :Failed \n Error:" - " {}".format(BGP_CONVERGENCE)) + assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format( + BGP_CONVERGENCE + ) logger.info("Running setup_module() done") @@ -153,9 +155,11 @@ def teardown_module(mod): # Stop toplogy and Remove tmp files tgen.stop_topology() - logger.info("Testsuite end time: {}". - format(time.asctime(time.localtime(time.time())))) - logger.info("="*40) + logger.info( + "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) + ) + logger.info("=" * 40) + ##################################################### # @@ -180,34 +184,26 @@ def test_ip_prefix_lists_in_permit(request): # Create Static routes input_dict = { "r1": { - "static_routes": [{ - "network": "20.0.20.1/32", - "no_of_ip": 1, - "next_hop": "10.0.0.2" - }] + "static_routes": [ + {"network": "20.0.20.1/32", "no_of_ip": 1, "next_hop": "10.0.0.2"} + ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create ip prefix list input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { - "pf_list_1": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] + "pf_list_1": [{"seqid": 10, "network": "any", "action": "permit"}] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure bgp neighbor with prefix list input_dict_3 = { @@ -218,7 +214,7 @@ def test_ip_prefix_lists_in_permit(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } } @@ -235,10 +231,7 @@ def test_ip_prefix_lists_in_permit(request): "dest_link": { "r3": { "prefix_lists": [ - { - "name": "pf_list_1", - "direction": "in" - } + {"name": "pf_list_1", "direction": "in"} ] } } @@ -248,18 +241,16 @@ def test_ip_prefix_lists_in_permit(request): } } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -283,43 +274,34 @@ def test_ip_prefix_lists_out_permit(request): # Create Static routes input_dict = { "r1": { - "static_routes": [{ - "network": "10.0.20.1/32", - "no_of_ip": 1, - "next_hop": "10.0.0.2" - }] + "static_routes": [ + {"network": "10.0.20.1/32", "no_of_ip": 1, "next_hop": "10.0.0.2"} + ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create Static routes input_dict_1 = { "r1": { - "static_routes": [{ - "network": "20.0.20.1/32", - "no_of_ip": 1, - "next_hop": "10.0.0.2" - }] + "static_routes": [ + {"network": "20.0.20.1/32", "no_of_ip": 1, "next_hop": "10.0.0.2"} + ] } } result = create_static_routes(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) input_dict_5 = { "r3": { - "static_routes": [{ - "network": "10.0.0.2/30", - "no_of_ip": 1, - "next_hop": "10.0.0.9" - }] + "static_routes": [ + {"network": "10.0.0.2/30", "no_of_ip": 1, "next_hop": "10.0.0.9"} + ] } } result = create_static_routes(tgen, input_dict_5) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to redistribute static routes @@ -328,18 +310,15 @@ def test_ip_prefix_lists_out_permit(request): "r1": { "prefix_lists": { "ipv4": { - "pf_list_1": [{ - "seqid": 10, - "network": "20.0.20.1/32", - "action": "permit" - }] + "pf_list_1": [ + {"seqid": 10, "network": "20.0.20.1/32", "action": "permit"} + ] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure prefix list to bgp neighbor # Configure bgp neighbor with prefix list @@ -356,7 +335,7 @@ def test_ip_prefix_lists_out_permit(request): "prefix_lists": [ { "name": "pf_list_1", - "direction": "out" + "direction": "out", } ] } @@ -365,8 +344,8 @@ def test_ip_prefix_lists_out_permit(request): }, "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} - ] + {"redist_type": "connected"}, + ], } } } @@ -375,19 +354,20 @@ def test_ip_prefix_lists_out_permit(request): } result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" result = verify_rib(tgen, "ipv4", dut, input_dict_1, protocol=protocol) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) - result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Error: Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name) write_test_footer(tc_name) @@ -410,16 +390,13 @@ def test_ip_prefix_lists_in_deny_and_permit_any(request): # Create Static Routes input_dict = { "r1": { - "static_routes": [{ - "network": "10.0.20.1/32", - "no_of_ip": 1, - "next_hop": "10.0.0.2" - }] + "static_routes": [ + {"network": "10.0.20.1/32", "no_of_ip": 1, "next_hop": "10.0.0.2"} + ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to redistribute static routes # Create ip prefix list @@ -428,24 +405,15 @@ def test_ip_prefix_lists_in_deny_and_permit_any(request): "prefix_lists": { "ipv4": { "pf_list_1": [ - { - "seqid": "10", - "network": "10.0.20.1/32", - "action": "deny" - }, - { - "seqid": "11", - "network": "any", - "action": "permit" - } + {"seqid": "10", "network": "10.0.20.1/32", "action": "deny"}, + {"seqid": "11", "network": "any", "action": "permit"}, ] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure bgp neighbor with prefix list input_dict_3 = { @@ -456,7 +424,7 @@ def test_ip_prefix_lists_in_deny_and_permit_any(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } } @@ -473,10 +441,7 @@ def test_ip_prefix_lists_in_deny_and_permit_any(request): "dest_link": { "r3": { "prefix_lists": [ - { - "name": "pf_list_1", - "direction": "in" - } + {"name": "pf_list_1", "direction": "in"} ] } } @@ -486,19 +451,21 @@ def test_ip_prefix_lists_in_deny_and_permit_any(request): } } } - } + }, } # Configure prefix list to bgp neighbor result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" - result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Error: Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name) write_test_footer(tc_name) @@ -525,23 +492,19 @@ def test_delete_prefix_lists(request): "prefix_lists": { "ipv4": { "pf_list_1": [ - { - "seqid": "10", - "network": "10.0.20.1/32", - "action": "deny" - } + {"seqid": "10", "network": "10.0.20.1/32", "action": "deny"} ] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) result = verify_prefix_lists(tgen, input_dict_2) assert result is not True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Delete prefix list input_dict_2 = { @@ -553,7 +516,7 @@ def test_delete_prefix_lists(request): "seqid": "10", "network": "10.0.20.1/32", "action": "deny", - "delete": True + "delete": True, } ] } @@ -561,12 +524,10 @@ def test_delete_prefix_lists(request): } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) result = verify_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -590,30 +551,24 @@ def test_ip_prefix_lists_out_deny_and_permit_any(request): # Create Static Routes input_dict = { "r1": { - "static_routes": [{ - "network": "10.0.20.1/32", - "no_of_ip": 9, - "next_hop": "10.0.0.2" - }] + "static_routes": [ + {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"} + ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create Static Routes input_dict_1 = { "r2": { - "static_routes": [{ - "network": "20.0.20.1/32", - "no_of_ip": 9, - "next_hop": "10.0.0.1" - }] + "static_routes": [ + {"network": "20.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.1"} + ] } } result = create_static_routes(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to redistribute static routes @@ -627,21 +582,16 @@ def test_ip_prefix_lists_out_deny_and_permit_any(request): "seqid": "10", "network": "10.0.0.0/8", "le": "32", - "action": "deny" + "action": "deny", }, - { - "seqid": "11", - "network": "any", - "action": "permit" - } + {"seqid": "11", "network": "any", "action": "permit"}, ] } } } } result = create_prefix_lists(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure prefix list to bgp neighbor input_dict_4 = { @@ -652,7 +602,7 @@ def test_ip_prefix_lists_out_deny_and_permit_any(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } } @@ -666,7 +616,7 @@ def test_ip_prefix_lists_out_deny_and_permit_any(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } } @@ -685,7 +635,7 @@ def test_ip_prefix_lists_out_deny_and_permit_any(request): "prefix_lists": [ { "name": "pf_list_1", - "direction": "out" + "direction": "out", } ] } @@ -696,25 +646,26 @@ def test_ip_prefix_lists_out_deny_and_permit_any(request): } } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r4" protocol = "bgp" result = verify_rib(tgen, "ipv4", dut, input_dict_1, protocol=protocol) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r4" protocol = "bgp" - result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Error: Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name) write_test_footer(tc_name) @@ -737,16 +688,13 @@ def test_modify_prefix_lists_in_permit_to_deny(request): # Create Static Routes input_dict = { "r1": { - "static_routes": [{ - "network": "10.0.20.1/32", - "no_of_ip": 9, - "next_hop": "10.0.0.2" - }] + "static_routes": [ + {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"} + ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to redistribute static routes @@ -755,19 +703,20 @@ def test_modify_prefix_lists_in_permit_to_deny(request): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1": [{ - "seqid": "10", - "network": "10.0.0.0/8", - "le": "32", - "action": "permit" - }] + "pf_list_1": [ + { + "seqid": "10", + "network": "10.0.0.0/8", + "le": "32", + "action": "permit", + } + ] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure prefix list to bgp neighbor input_dict_3 = { @@ -778,7 +727,7 @@ def test_modify_prefix_lists_in_permit_to_deny(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } } @@ -792,13 +741,10 @@ def test_modify_prefix_lists_in_permit_to_deny(request): "unicast": { "neighbor": { "r1": { - "dest_link":{ + "dest_link": { "r3": { "prefix_lists": [ - { - "name": "pf_list_1", - "direction": "in" - } + {"name": "pf_list_1", "direction": "in"} ] } } @@ -808,18 +754,16 @@ def test_modify_prefix_lists_in_permit_to_deny(request): } } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Modify prefix list input_dict_1 = { @@ -831,34 +775,31 @@ def test_modify_prefix_lists_in_permit_to_deny(request): "seqid": "10", "network": "10.0.0.0/8", "le": "32", - "action": "deny" + "action": "deny", }, - { - "seqid": "11", - "network": "any", - "action": "permit" - } + {"seqid": "11", "network": "any", "action": "permit"}, ] } } } } result = create_prefix_lists(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to clear bgp, so config changes would be reflected dut = "r3" result = clear_bgp_and_verify(tgen, topo, dut) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" - result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Error: Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name) write_test_footer(tc_name) @@ -882,16 +823,13 @@ def test_modify_prefix_lists_in_deny_to_permit(request): # Create Static Routes input_dict = { "r1": { - "static_routes": [{ - "network": "10.0.20.1/32", - "no_of_ip": 9, - "next_hop": "10.0.0.2" - }] + "static_routes": [ + {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"} + ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to redistribute static routes @@ -905,21 +843,16 @@ def test_modify_prefix_lists_in_deny_to_permit(request): "seqid": "10", "network": "10.0.0.0/8", "le": "32", - "action": "deny" + "action": "deny", }, - { - "seqid": "11", - "network": "any", - "action": "permit" - } + {"seqid": "11", "network": "any", "action": "permit"}, ] } } } } result = create_prefix_lists(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure prefix list to bgp neighbor input_dict_2 = { @@ -930,7 +863,7 @@ def test_modify_prefix_lists_in_deny_to_permit(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } } @@ -947,10 +880,7 @@ def test_modify_prefix_lists_in_deny_to_permit(request): "dest_link": { "r3": { "prefix_lists": [ - { - "name": "pf_list_1", - "direction": "in" - } + {"name": "pf_list_1", "direction": "in"} ] } } @@ -960,51 +890,51 @@ def test_modify_prefix_lists_in_deny_to_permit(request): } } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" - result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Error: Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name) # Modify ip prefix list input_dict_1 = { "r3": { "prefix_lists": { "ipv4": { - "pf_list_1": [{ - "seqid": "10", - "network": "10.0.0.0/8", - "le": "32", - "action": "permit" - }] + "pf_list_1": [ + { + "seqid": "10", + "network": "10.0.0.0/8", + "le": "32", + "action": "permit", + } + ] } } } - } result = create_prefix_lists(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to clear bgp, so config changes would be reflected dut = "r3" result = clear_bgp_and_verify(tgen, topo, dut) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -1028,16 +958,13 @@ def test_modify_prefix_lists_out_permit_to_deny(request): # Create Static Routes input_dict = { "r1": { - "static_routes": [{ - "network": "10.0.20.1/32", - "no_of_ip": 9, - "next_hop": "10.0.0.2" - }] + "static_routes": [ + {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"} + ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to redistribute static routes @@ -1046,20 +973,20 @@ def test_modify_prefix_lists_out_permit_to_deny(request): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1": [{ - "seqid": "10", - "network": "10.0.0.0/8", - "le": "32", - "action": "permit" - }] + "pf_list_1": [ + { + "seqid": "10", + "network": "10.0.0.0/8", + "le": "32", + "action": "permit", + } + ] } } } - } result = create_prefix_lists(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure prefix list to bgp neighbor input_dict_2 = { @@ -1070,7 +997,7 @@ def test_modify_prefix_lists_out_permit_to_deny(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } } @@ -1089,7 +1016,7 @@ def test_modify_prefix_lists_out_permit_to_deny(request): "prefix_lists": [ { "name": "pf_list_1", - "direction": "out" + "direction": "out", } ] } @@ -1100,18 +1027,16 @@ def test_modify_prefix_lists_out_permit_to_deny(request): } } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r4" protocol = "bgp" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Modify ip prefix list input_dict_1 = { @@ -1123,35 +1048,31 @@ def test_modify_prefix_lists_out_permit_to_deny(request): "seqid": "10", "network": "10.0.0.0/8", "le": "32", - "action": "deny" + "action": "deny", }, - { - "seqid": "11", - "network": "any", - "action": "permit" - } + {"seqid": "11", "network": "any", "action": "permit"}, ] } } } - } result = create_prefix_lists(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to clear bgp, so config changes would be reflected dut = "r3" result = clear_bgp_and_verify(tgen, topo, dut) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r4" protocol = "bgp" - result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Error: Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name) write_test_footer(tc_name) @@ -1175,16 +1096,13 @@ def test_modify_prefix_lists_out_deny_to_permit(request): # Create Static Routes input_dict = { "r1": { - "static_routes": [{ - "network": "10.0.20.1/32", - "no_of_ip": 9, - "next_hop": "10.0.0.2" - }] + "static_routes": [ + {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"} + ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to redistribute static routes # Create ip prefix list @@ -1197,22 +1115,16 @@ def test_modify_prefix_lists_out_deny_to_permit(request): "seqid": "10", "network": "10.0.0.0/8", "le": "32", - "action": "deny" + "action": "deny", }, - { - "seqid": "11", - "network": "any", - "action": "permit" - } + {"seqid": "11", "network": "any", "action": "permit"}, ] } } } - } result = create_prefix_lists(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure prefix list to bgp neighbor input_dict_2 = { @@ -1223,7 +1135,7 @@ def test_modify_prefix_lists_out_deny_to_permit(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } } @@ -1237,12 +1149,12 @@ def test_modify_prefix_lists_out_deny_to_permit(request): "unicast": { "neighbor": { "r4": { - "dest_link":{ + "dest_link": { "r3": { "prefix_lists": [ { "name": "pf_list_1", - "direction": "out" + "direction": "out", } ] } @@ -1253,51 +1165,51 @@ def test_modify_prefix_lists_out_deny_to_permit(request): } } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r4" protocol = "bgp" - result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Error: Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name) # Modify ip prefix list input_dict_1 = { "r3": { "prefix_lists": { "ipv4": { - "pf_list_1": [{ - "seqid": "10", - "network": "10.0.0.0/8", - "le": "32", - "action": "permit" - }] + "pf_list_1": [ + { + "seqid": "10", + "network": "10.0.0.0/8", + "le": "32", + "action": "permit", + } + ] } } } - } result = create_prefix_lists(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to clear bgp, so config changes would be reflected dut = "r3" result = clear_bgp_and_verify(tgen, topo, dut) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r4" protocol = "bgp" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -1321,30 +1233,24 @@ def test_ip_prefix_lists_implicit_deny(request): # Create Static Routes input_dict = { "r1": { - "static_routes": [{ - "network": "10.0.20.1/32", - "no_of_ip": 9, - "next_hop": "10.0.0.2" - }] + "static_routes": [ + {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"} + ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create Static Routes input_dict_1 = { "r2": { - "static_routes": [{ - "network": "20.0.20.1/32", - "no_of_ip": 9, - "next_hop": "10.0.0.1" - }] + "static_routes": [ + {"network": "20.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.1"} + ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to redistribute static routes # Create ip prefix list @@ -1352,20 +1258,20 @@ def test_ip_prefix_lists_implicit_deny(request): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1": [{ - "seqid": "10", - "network": "10.0.0.0/8", - "le": "32", - "action": "permit" - }] + "pf_list_1": [ + { + "seqid": "10", + "network": "10.0.0.0/8", + "le": "32", + "action": "permit", + } + ] } } } - } result = create_prefix_lists(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure prefix list to bgp neighbor input_dict_4 = { @@ -1376,7 +1282,7 @@ def test_ip_prefix_lists_implicit_deny(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } } @@ -1390,7 +1296,7 @@ def test_ip_prefix_lists_implicit_deny(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } } @@ -1409,7 +1315,7 @@ def test_ip_prefix_lists_implicit_deny(request): "prefix_lists": [ { "name": "pf_list_1", - "direction": "out" + "direction": "out", } ] } @@ -1420,25 +1326,26 @@ def test_ip_prefix_lists_implicit_deny(request): } } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r4" protocol = "bgp" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r4" protocol = "bgp" - result = verify_rib(tgen, "ipv4", dut, input_dict_1, protocol=protocol, expected=False) - assert result is not True, "Testcase {} : Failed \n Error: Routes still" \ - " present in RIB".format(tc_name) + result = verify_rib( + tgen, "ipv4", dut, input_dict_1, protocol=protocol, expected=False + ) + assert ( + result is not True + ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name) write_test_footer(tc_name) diff --git a/tests/topotests/bgp-route-map/test_route_map_topo1.py b/tests/topotests/bgp-route-map/test_route_map_topo1.py index c854e5a444..1aa951edaa 100755 --- a/tests/topotests/bgp-route-map/test_route_map_topo1.py +++ b/tests/topotests/bgp-route-map/test_route_map_topo1.py @@ -82,16 +82,29 @@ from mininet.topo import Topo # Required to instantiate the topology builder class. from lib.topojson import * from lib.common_config import ( - start_topology, write_test_header, - write_test_footer, verify_bgp_community, - verify_rib, delete_route_maps, create_bgp_community_lists, - interface_status, create_route_maps, create_prefix_lists, - verify_route_maps, check_address_types, - shutdown_bringup_interface, verify_prefix_lists, reset_config_on_routers) + start_topology, + write_test_header, + write_test_footer, + verify_bgp_community, + verify_rib, + delete_route_maps, + create_bgp_community_lists, + interface_status, + create_route_maps, + create_prefix_lists, + verify_route_maps, + check_address_types, + shutdown_bringup_interface, + verify_prefix_lists, + reset_config_on_routers, +) from lib.topolog import logger from lib.bgp import ( - verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify, verify_bgp_attributes) + verify_bgp_convergence, + create_router_bgp, + clear_bgp_and_verify, + verify_bgp_attributes, +) from lib.topojson import build_topo_from_json, build_config_from_json @@ -109,15 +122,9 @@ except IOError: # Global variables bgp_convergence = False -NETWORK = { - "ipv4": ["11.0.20.1/32", "20.0.20.1/32"], - "ipv6": ["1::1/128", "2::1/128"] -} +NETWORK = {"ipv4": ["11.0.20.1/32", "20.0.20.1/32"], "ipv6": ["1::1/128", "2::1/128"]} MASK = {"ipv4": "32", "ipv6": "128"} -NEXT_HOP = { - "ipv4": "10.0.0.2", - "ipv6": "fd00::2" -} +NEXT_HOP = {"ipv4": "10.0.0.2", "ipv6": "fd00::2"} ADDR_TYPES = check_address_types() @@ -170,8 +177,9 @@ def setup_module(mod): # Api call verify whether BGP is converged bgp_convergence = verify_bgp_convergence(tgen, topo) - assert bgp_convergence is True, ("setup_module :Failed \n Error:" - " {}".format(bgp_convergence)) + assert bgp_convergence is True, "setup_module :Failed \n Error:" " {}".format( + bgp_convergence + ) logger.info("Running setup_module() done") @@ -190,8 +198,9 @@ def teardown_module(): # Stop toplogy and Remove tmp files tgen.stop_topology() - logger.info("Testsuite end time: {}". - format(time.asctime(time.localtime(time.time())))) + logger.info( + "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) + ) logger.info("=" * 40) @@ -230,7 +239,8 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Api call to redistribute static routes input_dict_1 = { @@ -242,7 +252,7 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } }, @@ -250,18 +260,19 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } - } - } + }, + }, } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) input_dict_2 = { "r4": { @@ -277,7 +288,8 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): result = create_static_routes(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Api call to redistribute static routes input_dict_5 = { @@ -288,7 +300,7 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } }, @@ -296,81 +308,94 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_5) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "action": "permit", - "network": NETWORK["ipv4"][0] - }], - "pf_list_2_ipv4": [{ - "seqid": 10, - "action": "permit", - "network": NETWORK["ipv4"][1] - }] + "pf_list_1_ipv4": [ + { + "seqid": 10, + "action": "permit", + "network": NETWORK["ipv4"][0], + } + ], + "pf_list_2_ipv4": [ + { + "seqid": 10, + "action": "permit", + "network": NETWORK["ipv4"][1], + } + ], }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "action": "permit", - "network": NETWORK["ipv6"][0] - }], - "pf_list_2_ipv6": [{ - "seqid": 100, - "action": "permit", - "network": NETWORK["ipv6"][1] - }] - } + "pf_list_1_ipv6": [ + { + "seqid": 100, + "action": "permit", + "network": NETWORK["ipv6"][0], + } + ], + "pf_list_2_ipv6": [ + { + "seqid": 100, + "action": "permit", + "network": NETWORK["ipv6"][1], + } + ], + }, } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create route map for addr_type in ADDR_TYPES: input_dict_6 = { - "r3": { - "route_maps": { - "rmap_match_tag_1_{}".format(addr_type): [{ - "action": "deny", - "match": { - addr_type: { - "prefix_lists": - "pf_list_1_{}".format(addr_type) + "r3": { + "route_maps": { + "rmap_match_tag_1_{}".format(addr_type): [ + { + "action": "deny", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, } - } - }], - "rmap_match_tag_2_{}".format(addr_type): [{ - "action": "permit", - "match": { - addr_type: { - "prefix_lists": - "pf_list_2_{}".format(addr_type) + ], + "rmap_match_tag_2_{}".format(addr_type): [ + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_list_2_{}".format(addr_type) + } + }, } - } - }] + ], + } } } - } result = create_route_maps(tgen, input_dict_6) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_7 = { @@ -384,12 +409,14 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): "dest_link": { "r3": { "route_maps": [ - {"name": - "rmap_match_tag_1_ipv4", - "direction": "in"}, - {"name": - "rmap_match_tag_1_ipv4", - "direction": "out"} + { + "name": "rmap_match_tag_1_ipv4", + "direction": "in", + }, + { + "name": "rmap_match_tag_1_ipv4", + "direction": "out", + }, ] } } @@ -404,19 +431,21 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): "dest_link": { "r3": { "route_maps": [ - {"name": - "rmap_match_tag_1_ipv6", - "direction": "in"}, - {"name": - "rmap_match_tag_1_ipv6", - "direction": "out"} + { + "name": "rmap_match_tag_1_ipv6", + "direction": "in", + }, + { + "name": "rmap_match_tag_1_ipv6", + "direction": "out", + }, ] } } } } } - } + }, } } } @@ -424,7 +453,8 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): result = create_router_bgp(tgen, topo, input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) for adt in ADDR_TYPES: # Verifying RIB routes @@ -436,17 +466,17 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): { "network": [NETWORK[adt][1]], "no_of_ip": 9, - "next_hop": NEXT_HOP[adt] + "next_hop": NEXT_HOP[adt], } ] } } - result = verify_rib(tgen, adt, dut, input_dict_2, protocol=protocol, - expected=False) + result = verify_rib( + tgen, adt, dut, input_dict_2, protocol=protocol, expected=False + ) assert result is not True, "Testcase {} : Failed \n" - "routes are not present in rib \n Error: {}".format( - tc_name, result) + "routes are not present in rib \n Error: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes @@ -457,26 +487,28 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): { "network": [NETWORK[adt][0]], "no_of_ip": 9, - "next_hop": NEXT_HOP[adt] + "next_hop": NEXT_HOP[adt], } ] } } - result = verify_rib(tgen, adt, dut, input_dict, protocol=protocol, - expected=False) + result = verify_rib( + tgen, adt, dut, input_dict, protocol=protocol, expected=False + ) assert result is not True, "Testcase {} : Failed \n " - "routes are not present in rib \n Error: {}".format( - tc_name, result) + "routes are not present in rib \n Error: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) -@pytest.mark.parametrize("prefix_action, rmap_action", [("permit", "permit"), - ("permit", "deny"), ("deny", "permit"), - ("deny", "deny")]) +@pytest.mark.parametrize( + "prefix_action, rmap_action", + [("permit", "permit"), ("permit", "deny"), ("deny", "permit"), ("deny", "deny")], +) def test_route_map_with_action_values_combination_of_prefix_action_p0( - request, prefix_action, rmap_action): + request, prefix_action, rmap_action +): """ TC_36: Test permit/deny statements operation in route-maps with a permutation and @@ -501,7 +533,7 @@ def test_route_map_with_action_values_combination_of_prefix_action_p0( { "network": NETWORK[adt][0], "no_of_ip": 9, - "next_hop": NEXT_HOP[adt] + "next_hop": NEXT_HOP[adt], } ] } @@ -509,7 +541,8 @@ def test_route_map_with_action_values_combination_of_prefix_action_p0( result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Api call to redistribute static routes input_dict_1 = { @@ -521,7 +554,7 @@ def test_route_map_with_action_values_combination_of_prefix_action_p0( "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } }, @@ -529,65 +562,64 @@ def test_route_map_with_action_values_combination_of_prefix_action_p0( "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } - } - } + }, + }, } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Permit in perfix list and route-map input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": prefix_action - }] + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": prefix_action} + ] }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": prefix_action - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": prefix_action} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": rmap_action, - "match": { - addr_type: { - "prefix_lists": - "pf_list_1_{}".format(addr_type) - } + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": rmap_action, + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, } - } - ] + ] + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_7 = { @@ -601,9 +633,10 @@ def test_route_map_with_action_values_combination_of_prefix_action_p0( "dest_link": { "r3": { "route_maps": [ - {"name": - "rmap_match_pf_1_ipv4", - "direction": "in"} + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } ] } } @@ -618,16 +651,17 @@ def test_route_map_with_action_values_combination_of_prefix_action_p0( "dest_link": { "r3": { "route_maps": [ - {"name": - "rmap_match_pf_1_ipv6", - "direction": "in"} + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } ] } } } } } - } + }, } } } @@ -635,7 +669,8 @@ def test_route_map_with_action_values_combination_of_prefix_action_p0( result = create_router_bgp(tgen, topo, input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) dut = "r3" protocol = "bgp" @@ -651,17 +686,18 @@ def test_route_map_with_action_values_combination_of_prefix_action_p0( } } - #tgen.mininet_cli() - result = verify_rib(tgen, adt, dut, input_dict_2, protocol=protocol, - expected=False) + # tgen.mininet_cli() + result = verify_rib( + tgen, adt, dut, input_dict_2, protocol=protocol, expected=False + ) if "deny" in [prefix_action, rmap_action]: assert result is not True, "Testcase {} : Failed \n " - "Routes are still present \n Error: {}".\ - format(tc_name, result) + "Routes are still present \n Error: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) else: assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) def test_route_map_multiple_seq_different_match_set_clause_p0(request): @@ -683,16 +719,19 @@ def test_route_map_multiple_seq_different_match_set_clause_p0(request): # Create Static routes input_dict = { "r1": { - "static_routes": [{ - "network": NETWORK[adt][0], - "no_of_ip": 1, - "next_hop": NEXT_HOP[adt] - }] + "static_routes": [ + { + "network": NETWORK[adt][0], + "no_of_ip": 1, + "next_hop": NEXT_HOP[adt], + } + ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Api call to redistribute static routes input_dict_1 = { @@ -703,7 +742,7 @@ def test_route_map_multiple_seq_different_match_set_clause_p0(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } }, @@ -711,94 +750,82 @@ def test_route_map_multiple_seq_different_match_set_clause_p0(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create ip prefix list input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [ - { - "action": "permit", - "match": { - addr_type: { - "prefix_lists": - "pf_list_2_{}".format(addr_type) - } + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_list_2_{}".format(addr_type) + } + }, + "set": {"path": {"as_num": 500}}, }, - "set": { - "path": { - "as_num": 500 - } - } - }, - { - "action": "permit", - "match": { - addr_type: { - "prefix_lists": - "pf_list_2_{}".format(addr_type) - } + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_list_2_{}".format(addr_type) + } + }, + "set": {"locPrf": 150,}, }, - "set": { - "locPrf": 150, - } - }, - { - "action": "permit", - "match": { - addr_type: { - "prefix_lists": - "pf_list_1_{}".format(addr_type) - } + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"metric": 50}, }, - "set": { - "metric": 50 - } - } - ] - } - } + ] + } + } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { @@ -811,25 +838,27 @@ def test_route_map_multiple_seq_different_match_set_clause_p0(request): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] } } }, "r4": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "out", + } + ] } } - } + }, } } }, @@ -839,65 +868,64 @@ def test_route_map_multiple_seq_different_match_set_clause_p0(request): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] } } }, "r4": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "out", + } + ] } } - } + }, } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) for adt in ADDR_TYPES: # Verifying RIB routes dut = "r3" protocol = "bgp" input_dict = { - "r3": { - "route_maps": { - "rmap_match_pf_list1": [{ - "set": { - "metric": 50, - } - }], - } - } + "r3": {"route_maps": {"rmap_match_pf_list1": [{"set": {"metric": 50,}}],}} } static_routes = [NETWORK[adt][0]] time.sleep(2) - result = verify_bgp_attributes(tgen, adt, dut, static_routes, - "rmap_match_pf_list1", input_dict) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_attributes( + tgen, adt, dut, static_routes, "rmap_match_pf_list1", input_dict + ) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) dut = "r4" - result = verify_bgp_attributes(tgen, adt, dut, static_routes, - "rmap_match_pf_list1", input_dict) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_attributes( + tgen, adt, dut, static_routes, "rmap_match_pf_list1", input_dict + ) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) logger.info("Testcase " + tc_name + " :Passed \n") @@ -924,16 +952,19 @@ def test_route_map_set_only_no_match_p0(request): # Create Static routes input_dict = { "r1": { - "static_routes": [{ - "network": NETWORK[adt][0], - "no_of_ip": 1, - "next_hop": NEXT_HOP[adt] - }] + "static_routes": [ + { + "network": NETWORK[adt][0], + "no_of_ip": 1, + "next_hop": NEXT_HOP[adt], + } + ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Api call to redistribute static routes input_dict_1 = { @@ -944,7 +975,7 @@ def test_route_map_set_only_no_match_p0(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } }, @@ -952,17 +983,18 @@ def test_route_map_set_only_no_match_p0(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create route map input_dict_3 = { @@ -971,11 +1003,7 @@ def test_route_map_set_only_no_match_p0(request): "rmap_match_pf_1": [ { "action": "permit", - "set": { - "metric": 50, - "locPrf": 150, - "weight": 4000 - } + "set": {"metric": 50, "locPrf": 150, "weight": 4000}, } ] } @@ -983,7 +1011,8 @@ def test_route_map_set_only_no_match_p0(request): } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { @@ -996,23 +1025,27 @@ def test_route_map_set_only_no_match_p0(request): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": "rmap_match_pf_1", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1", + "direction": "in", + } + ] } } }, "r4": { "dest_link": { "r3": { - "route_maps": [{ - "name": "rmap_match_pf_1", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1", + "direction": "out", + } + ] } } - } + }, } } }, @@ -1022,61 +1055,63 @@ def test_route_map_set_only_no_match_p0(request): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": "rmap_match_pf_1", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1", + "direction": "in", + } + ] } } }, "r4": { "dest_link": { "r3": { - "route_maps": [{ - "name": "rmap_match_pf_1", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1", + "direction": "out", + } + ] } } - } + }, } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) time.sleep(2) for adt in ADDR_TYPES: input_dict_4 = { "r3": { "route_maps": { - "rmap_match_pf_1": [ - { - "action": "permit", - "set": { - "metric": 50, - } - } - ] + "rmap_match_pf_1": [{"action": "permit", "set": {"metric": 50,}}] } } } # Verifying RIB routes static_routes = [NETWORK[adt][0]] - result = verify_bgp_attributes(tgen, adt, "r3", static_routes, - "rmap_match_pf_1", input_dict_3) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_attributes( + tgen, adt, "r3", static_routes, "rmap_match_pf_1", input_dict_3 + ) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) - result = verify_bgp_attributes(tgen, adt, "r4", static_routes, - "rmap_match_pf_1", input_dict_4) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_attributes( + tgen, adt, "r4", static_routes, "rmap_match_pf_1", input_dict_4 + ) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) logger.info("Testcase " + tc_name + " :Passed \n") @@ -1103,16 +1138,19 @@ def test_route_map_match_only_no_set_p0(request): # Create Static routes input_dict = { "r1": { - "static_routes": [{ - "network": NETWORK[adt][0], - "no_of_ip": 1, - "next_hop": NEXT_HOP[adt] - }] + "static_routes": [ + { + "network": NETWORK[adt][0], + "no_of_ip": 1, + "next_hop": NEXT_HOP[adt], + } + ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Api call to redistribute static routes input_dict_1 = { @@ -1123,7 +1161,7 @@ def test_route_map_match_only_no_set_p0(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } }, @@ -1131,62 +1169,56 @@ def test_route_map_match_only_no_set_p0(request): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create ip prefix list input_dict_2 = { "r1": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { "r1": { "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "set": { - "metric": 50, - "locPrf": 150, - } - } + "rmap_match_pf_1_{}".format(addr_type): [ + {"action": "permit", "set": {"metric": 50, "locPrf": 150,}} ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { @@ -1199,11 +1231,12 @@ def test_route_map_match_only_no_set_p0(request): "r3": { "dest_link": { "r1": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "out", + } + ] } } } @@ -1216,63 +1249,62 @@ def test_route_map_match_only_no_set_p0(request): "r3": { "dest_link": { "r1": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "out", + } + ] } } } } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create ip prefix list input_dict_5 = { "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_5) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create route map for addr_type in ADDR_TYPES: input_dict_6 = { "r3": { "route_maps": { - "rmap_match_pf_2_{}".format(addr_type): [{ + "rmap_match_pf_2_{}".format(addr_type): [ + { "action": "permit", "match": { addr_type: { - "prefix_lists": - "pf_list_1_{}".format(addr_type) + "prefix_lists": "pf_list_1_{}".format(addr_type) } - } + }, } ] } @@ -1280,7 +1312,8 @@ def test_route_map_match_only_no_set_p0(request): } result = create_route_maps(tgen, input_dict_6) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_7 = { @@ -1293,25 +1326,27 @@ def test_route_map_match_only_no_set_p0(request): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv4", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv4", + "direction": "in", + } + ] } } }, "r4": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv4", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv4", + "direction": "out", + } + ] } } - } + }, } } }, @@ -1321,47 +1356,50 @@ def test_route_map_match_only_no_set_p0(request): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv6", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv6", + "direction": "in", + } + ] } } }, "r4": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv6", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv6", + "direction": "out", + } + ] } } - } + }, } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) for adt in ADDR_TYPES: # Verifying RIB routes static_routes = [NETWORK[adt][0]] - result = verify_bgp_attributes(tgen, adt, "r3", static_routes, - "rmap_match_pf_1", input_dict_3) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_attributes( + tgen, adt, "r3", static_routes, "rmap_match_pf_1", input_dict_3 + ) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) - - diff --git a/tests/topotests/bgp-route-map/test_route_map_topo2.py b/tests/topotests/bgp-route-map/test_route_map_topo2.py index 609cea5f92..3056aa29f3 100755 --- a/tests/topotests/bgp-route-map/test_route_map_topo2.py +++ b/tests/topotests/bgp-route-map/test_route_map_topo2.py @@ -122,17 +122,31 @@ from mininet.topo import Topo # Required to instantiate the topology builder class. from lib.common_config import ( - start_topology, write_test_header, - write_test_footer, create_static_routes, - verify_rib, delete_route_maps, create_bgp_community_lists, - interface_status, create_route_maps, create_prefix_lists, - verify_route_maps, check_address_types, verify_bgp_community, - shutdown_bringup_interface, verify_prefix_lists, reset_config_on_routers, - verify_create_community_list) + start_topology, + write_test_header, + write_test_footer, + create_static_routes, + verify_rib, + delete_route_maps, + create_bgp_community_lists, + interface_status, + create_route_maps, + create_prefix_lists, + verify_route_maps, + check_address_types, + verify_bgp_community, + shutdown_bringup_interface, + verify_prefix_lists, + reset_config_on_routers, + verify_create_community_list, +) from lib.topolog import logger from lib.bgp import ( - verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify, verify_bgp_attributes) + verify_bgp_convergence, + create_router_bgp, + clear_bgp_and_verify, + verify_bgp_attributes, +) from lib.topojson import build_topo_from_json, build_config_from_json # Reading the data from JSON File for topology and configuration creation @@ -147,10 +161,7 @@ except IOError: # Global variables # Global variables bgp_convergence = False -NETWORK = { - "ipv4": ["11.0.20.1/32", "11.0.20.2/32"], - "ipv6": ["2::1/128", "2::2/128"] -} +NETWORK = {"ipv4": ["11.0.20.1/32", "11.0.20.2/32"], "ipv6": ["2::1/128", "2::2/128"]} bgp_convergence = False BGP_CONVERGENCE = False @@ -180,7 +191,7 @@ def setup_module(mod): """ testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) - logger.info("="*40) + logger.info("=" * 40) logger.info("Running setup_module to create topology") @@ -205,8 +216,9 @@ def setup_module(mod): # Api call verify whether BGP is converged bgp_convergence = verify_bgp_convergence(tgen, topo) - assert bgp_convergence is True, ("setup_module :Failed \n Error:" - " {}".format(bgp_convergence)) + assert bgp_convergence is True, "setup_module :Failed \n Error:" " {}".format( + bgp_convergence + ) logger.info("Running setup_module() done") @@ -222,9 +234,10 @@ def teardown_module(mod): # Stop toplogy and Remove tmp files tgen.stop_topology() - logger.info("Testsuite end time: {}".format( - time.asctime(time.localtime(time.time())))) - logger.info("="*40) + logger.info( + "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) + ) + logger.info("=" * 40) ##################################################### @@ -254,134 +267,126 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit", - }] + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit",} + ] }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 10, - "network": "any", - "action": "permit", - }] - } + "pf_list_1_ipv6": [ + {"seqid": 10, "network": "any", "action": "permit",} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: - # Create route map + # Create route map input_dict_3 = { "r3": { "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_" + addr_type - } + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: {"prefix_lists": "pf_list_1_" + addr_type} + }, + "set": {"locPrf": 150, "weight": 100}, }, - "set": { - "locPrf": 150, - "weight": 100 - } - }, ], - "rmap_match_pf_2_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_" + addr_type - } + "rmap_match_pf_2_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: {"prefix_lists": "pf_list_1_" + addr_type} + }, + "set": {"metric": 50}, }, - "set": { - "metric": 50 - } - }, - ] + ], } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { - "r3": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] - } - } - }, - "r4": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv4", - "direction": "out" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] - } - } - }, - "r4": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv6", - "direction": "out" - }] - } - } - } - } - } - } - } - } - } + "r3": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] + } + } + }, + "r4": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv4", + "direction": "out", + } + ] + } + } + }, + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] + } + } + }, + "r4": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv6", + "direction": "out", + } + ] + } + } + }, + } + } + }, + } + } + } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" @@ -390,48 +395,52 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): # dual stack changes for addr_type in ADDR_TYPES: - result4 = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result4 is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result4) + tc_name, result4 + ) # Verifying BGP set attributes dut = "r3" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } # dual stack changes for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result4 = verify_bgp_attributes(tgen, addr_type, dut, routes[ - addr_type],rmap_name, input_dict_3) + result4 = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result4 is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result4) + tc_name, result4 + ) # Verifying RIB routes dut = "r4" protocol = "bgp" # dual stack changes for addr_type in ADDR_TYPES: - result4 = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result4 is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result4) + tc_name, result4 + ) # Verifying BGP set attributes dut = "r4" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } # dual stack changes for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_2_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) # Uncomment next line for debugging @@ -462,267 +471,271 @@ def test_modify_set_match_clauses_in_rmap_p0(): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit", - }], - "pf_list_2_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit",} + ], + "pf_list_2_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ], }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 10, - "network": "any", - "action": "permit", - }], - "pf_list_2_ipv6": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] - } + "pf_list_1_ipv6": [ + {"seqid": 10, "network": "any", "action": "permit",} + ], + "pf_list_2_ipv6": [ + {"seqid": 10, "network": "any", "action": "permit"} + ], + }, } } - } + } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 150,}, } - }, - "set": { - "locPrf": 150, - } - }], - "rmap_match_pf_2_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) + ], + "rmap_match_pf_2_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"metric": 50}, } - }, - "set": { - "metric": 50 - } - }] + ], + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { - "r3": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] - } - } - }, - "r4": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv4", - "direction": "out" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] - } - } - }, - "r4": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv6", - "direction": "out" - }] - } - } - } - } - } - } - } - } - } - } + "r3": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] + } + } + }, + "r4": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv4", + "direction": "out", + } + ] + } + } + }, + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] + } + } + }, + "r4": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv6", + "direction": "out", + } + ] + } + } + }, + } + } + }, + } + } + } + } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } # dual stack changes for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result4 = verify_bgp_attributes(tgen, addr_type, dut, routes[ - addr_type],rmap_name, input_dict_3) + result4 = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result4 is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result4) + tc_name, result4 + ) # Verifying RIB routes dut = "r4" protocol = "bgp" # dual stack changes for addr_type in ADDR_TYPES: - result4 = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result4 is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result4) + tc_name, result4 + ) # Verifying BGP set attributes dut = "r4" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_2_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[ - addr_type],rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Modify set/match clause of in-used route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } - }, - "set": { - "locPrf": 1000, + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 1000,}, + } + ], + "rmap_match_pf_2_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"metric": 2000}, + } + ], } - }], - "rmap_match_pf_2_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } - }, - "set": { - "metric": 2000 - } - }] - } - } + } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying RIB routes dut = "r3" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying RIB routes dut = "r4" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r4" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_2_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -750,37 +763,29 @@ def test_delete_route_maps_p1(): # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_tag_1_{}".format(addr_type): [{ - "action": "deny", - "match": { - addr_type: { - "tag": "4001" - } - } - }] + "r3": { + "route_maps": { + "rmap_match_tag_1_{}".format(addr_type): [ + {"action": "deny", "match": {addr_type: {"tag": "4001"}}} + ] + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Delete route maps for addr_type in ADDR_TYPES: - input_dict = { - "r3": { - "route_maps": ["rmap_match_tag_1_{}".format(addr_type)] - } - } + input_dict = {"r3": {"route_maps": ["rmap_match_tag_1_{}".format(addr_type)]}} result = delete_route_maps(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) result = verify_route_maps(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) # Uncomment next line for debugging @@ -810,226 +815,223 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit", - }] + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit",} + ] }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit", - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit",} + ] + }, } } - } + } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 150, "weight": 100}, } - }, - "set": { - "locPrf": 150, - "weight": 100 - } - }], - "rmap_match_pf_2_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) + ], + "rmap_match_pf_2_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"metric": 50}, } - }, - "set": { - "metric": 50 - } - }] + ], + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { - "r3": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] - } - } - }, - "r4": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv4", - "direction": "out" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] - } - } - }, - "r4": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv6", - "direction": "out" - }] - } - } - } - } - } - } - } - } - } - } + "r3": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] + } + } + }, + "r4": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv4", + "direction": "out", + } + ] + } + } + }, + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] + } + } + }, + "r4": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv6", + "direction": "out", + } + ] + } + } + }, + } + } + }, + } + } + } + } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying RIB routes dut = "r4" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r4" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_2_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Modify ip prefix list input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "deny" - }] - }, - "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "deny" - }] - } + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "deny"} + ] + }, + "ipv6": { + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "deny"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) sleep(5) # Verifying RIB routes dut = "r3" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol, expected=False) + result = verify_rib( + tgen, addr_type, dut, input_dict, protocol=protocol, expected=False + ) assert result is not True, "Testcase {} : Failed \n" - "routes are not present \n Error: {}".format( - tc_name, result) + "routes are not present \n Error: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes dut = "r4" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol, expected=False) + result = verify_rib( + tgen, addr_type, dut, input_dict, protocol=protocol, expected=False + ) assert result is not True, "Testcase {} : Failed \n" "Expected behaviour: routes are not present \n " - "Error: {}".format( - tc_name, result) + "Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -1059,234 +1061,240 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] - }, + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] + }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } - } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 150,}, } - }, - "set": { - "locPrf": 150, - } - }], - "rmap_match_pf_2_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } - }, - "set": { - "metric": 50 - } - }] + ], + "rmap_match_pf_2_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"metric": 50}, + } + ], + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map for addr_type in ADDR_TYPES: input_dict_4 = { - "r3": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] - } - } - }, - "r4": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv4", - "direction": "out" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] - } - } - }, - "r4": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv6", - "direction": "out" - }] - } - } - } - } - } - } - } - } - } - } + "r3": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] + } + } + }, + "r4": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv4", + "direction": "out", + } + ] + } + } + }, + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] + } + } + }, + "r4": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv6", + "direction": "out", + } + ] + } + } + }, + } + } + }, + } + } + } + } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying RIB routes dut = "r3" protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying RIB routes dut = "r4" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r4" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_2_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Remove/Delete prefix list input_dict_3 = { "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit", - "delete": True - }] - }, + "pf_list_1_ipv4": [ + { + "seqid": 10, + "network": "any", + "action": "permit", + "delete": True, + } + ] + }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit", - "delete": True - }] + "pf_list_1_ipv6": [ + { + "seqid": 100, + "network": "any", + "action": "permit", + "delete": True, + } + ] + }, } } - } } result = create_prefix_lists(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) result = verify_prefix_lists(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to clear bgp, so config changes would be reflected dut = "r3" result = clear_bgp_and_verify(tgen, topo, dut) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol, expected=False) + result = verify_rib( + tgen, addr_type, dut, input_dict, protocol=protocol, expected=False + ) assert result is not True, "Testcase {} : Failed \n" - "routes are not present \n Error: {}".format( - tc_name, result) + "routes are not present \n Error: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes dut = "r4" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol, expected=False) + result = verify_rib( + tgen, addr_type, dut, input_dict, protocol=protocol, expected=False + ) assert result is not True, "Testcase {} : Failed \n" - "routes are not present \n Error: {}".\ - format(tc_name, result) + "routes are not present \n Error: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -1318,157 +1326,170 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): # Create route map for addr_type in ADDR_TYPES: input_dict_5 = { - "r1": { - "route_maps": { - "rm_r1_out_{}".format(addr_type): [{ - "action": "permit", - "set": { - "large_community": {"num": "1:1:1 1:2:3 2:1:1 2:2:2"} - } - }] - } - } - } - result = create_route_maps(tgen, input_dict_5) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) - - # Configure neighbor for route map - input_dict_6 = { - "r1": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r3": { - "dest_link": { - "r1": { - "route_maps": [{ - "name": "rm_r1_out_ipv4", - "direction": "out" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r3": { - "dest_link": { - "r1": { - "route_maps": [{ - "name": "rm_r1_out_ipv6", - "direction": "out" - }] - } - } - } - } - } - } - } - } - } - } - - result = create_router_bgp(tgen, topo, input_dict_6) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) - - for addr_type in ADDR_TYPES: - # Create standard large commumity-list - input_dict_1 = { - "r3": { - "bgp_community_lists": [ + "r1": { + "route_maps": { + "rm_r1_out_{}".format(addr_type): [ { - "community_type": "standard", "action": "permit", - "name": "rmap_lcomm_{}".format(addr_type), - "value": "1:1:1 1:2:3 2:1:1 2:2:2", - "large": True + "set": { + "large_community": {"num": "1:1:1 1:2:3 2:1:1 2:2:2"} + }, } ] } } - result = create_bgp_community_lists(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + } + result = create_route_maps(tgen, input_dict_5) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + # Configure neighbor for route map + input_dict_6 = { + "r1": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r3": { + "dest_link": { + "r1": { + "route_maps": [ + { + "name": "rm_r1_out_ipv4", + "direction": "out", + } + ] + } + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r3": { + "dest_link": { + "r1": { + "route_maps": [ + { + "name": "rm_r1_out_ipv6", + "direction": "out", + } + ] + } + } + } + } + } + }, + } + } + } + } + + result = create_router_bgp(tgen, topo, input_dict_6) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + for addr_type in ADDR_TYPES: + # Create standard large commumity-list + input_dict_1 = { + "r3": { + "bgp_community_lists": [ + { + "community_type": "standard", + "action": "permit", + "name": "rmap_lcomm_{}".format(addr_type), + "value": "1:1:1 1:2:3 2:1:1 2:2:2", + "large": True, + } + ] + } + } + result = create_bgp_community_lists(tgen, input_dict_1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) # Verify BGP large community is created result = verify_create_community_list(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: - # Create route map + # Create route map input_dict_2 = { - "r3": { - "route_maps": { - "rm_r3_in_{}".format(addr_type): [{ - "action": "permit", - "match": { - addr_type : { - "large-community-list": {"id": "rmap_lcomm_"+ - addr_type} - } - } - }] + "r3": { + "route_maps": { + "rm_r3_in_{}".format(addr_type): [ + { + "action": "permit", + "match": { + addr_type: { + "large-community-list": { + "id": "rmap_lcomm_" + addr_type + } + } + }, + } + ] + } } } - } result = create_route_maps(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_3 = { - "r3": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": "rm_r3_in_ipv4", - "direction": "in" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": "rm_r3_in_ipv6", - "direction": "in" - }] - } - } - } - } - } - } - } - } - } - } + "r3": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rm_r3_in_ipv4", + "direction": "in", + } + ] + } + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rm_r3_in_ipv6", + "direction": "in", + } + ] + } + } + } + } + } + }, + } + } + } + } result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) sleep(5) # Verifying RIB routes @@ -1476,25 +1497,25 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verify large-community-list dut = "r3" networks = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] - } - input_dict_4 = { - "largeCommunity": "1:1:1 1:2:3 2:1:1 2:2:2" + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } + input_dict_4 = {"largeCommunity": "1:1:1 1:2:3 2:1:1 2:2:2"} for addr_type in ADDR_TYPES: - result = verify_bgp_community(tgen, addr_type, dut, networks[ - addr_type],input_dict_4) + result = verify_bgp_community( + tgen, addr_type, dut, networks[addr_type], input_dict_4 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) # Uncomment next line for debugging @@ -1520,242 +1541,220 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): # Api call to advertise networks input_dict_nw1 = { - "r1": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "advertise_networks": [ - {"network": "10.0.30.1/32"} - ] - } - }, - "ipv6": { - "unicast": { - "advertise_networks": [ - {"network": "1::1/128"} - ] - } - } - } + "r1": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": {"advertise_networks": [{"network": "10.0.30.1/32"}]} + }, + "ipv6": { + "unicast": {"advertise_networks": [{"network": "1::1/128"}]} + }, } } } + } result = create_router_bgp(tgen, topo, input_dict_nw1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to advertise networks input_dict_nw2 = { - "r1": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "advertise_networks": [ - {"network": "20.0.30.1/32"} - ] - } - }, - "ipv6": { - "unicast": { - "advertise_networks": [ - {"network": "2::1/128"} - ] - } - } - } + "r1": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": {"advertise_networks": [{"network": "20.0.30.1/32"}]} + }, + "ipv6": { + "unicast": {"advertise_networks": [{"network": "2::1/128"}]} + }, } } } + } result = create_router_bgp(tgen, topo, input_dict_nw2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create ip prefix list input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] - }, + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] + }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create ip prefix list input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { - "pf_list_2_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] - }, + "pf_list_2_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] + }, "ipv6": { - "pf_list_2_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "pf_list_2_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) - input_dict_3_addr_type ={} + input_dict_3_addr_type = {} # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 150}, } - }, - "set": { - "locPrf": 150 - } - }] + ] + } } } - } input_dict_3_addr_type[addr_type] = input_dict_3 result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } - }, - "set": { - "locPrf": 200 - } - }] + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 200}, + } + ] + } } } - } input_dict_3_addr_type[addr_type] = input_dict_3 result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_6 = { - "r3": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] - } - } - } - } - } - } - } - } - } - } + "r3": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] + } + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] + } + } + } + } + } + }, + } + } + } + } result = create_router_bgp(tgen, topo, input_dict_6) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" - routes = { - "ipv4": ["10.0.30.1/32"], - "ipv6": ["1::1/128"] - } + routes = {"ipv4": ["10.0.30.1/32"], "ipv6": ["1::1/128"]} for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3_addr_type[addr_type]) + result = verify_bgp_attributes( + tgen, + addr_type, + dut, + routes[addr_type], + rmap_name, + input_dict_3_addr_type[addr_type], + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes - routes = { - "ipv4": ["20.0.30.1/32"], - "ipv6": ["2::1/128"] - } + routes = {"ipv4": ["20.0.30.1/32"], "ipv6": ["2::1/128"]} for addr_type in ADDR_TYPES: - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -1785,79 +1784,80 @@ def test_multiple_match_statement_in_route_map_logical_ANDed_p1(): input_dict_5 = { "r1": { "route_maps": { - "rm_r1_out_{}".format(addr_type): [{ - "action": "permit", - "set": { - "large_community": { - "num": "1:1:1 1:2:3 2:1:1 2:2:2"} + "rm_r1_out_{}".format(addr_type): [ + { + "action": "permit", + "set": { + "large_community": {"num": "1:1:1 1:2:3 2:1:1 2:2:2"} + }, } - }] + ] } } } result = create_route_maps(tgen, input_dict_5) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map for addr_type in ADDR_TYPES: input_dict_6 = { - "r1": { - "bgp": { - "address_family": { - addr_type: { - "unicast": { - "neighbor": { - "r3": { - "dest_link": { - "r1": { - "route_maps": [{ - "name": - "rm_r1_out_{}".format(addr_type), - "direction": "out" - }] - } - } - } - } - } - } - } - } - } + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "neighbor": { + "r3": { + "dest_link": { + "r1": { + "route_maps": [ + { + "name": "rm_r1_out_{}".format( + addr_type + ), + "direction": "out", + } + ] + } + } + } + } + } + } + } + } + } } result = create_router_bgp(tgen, topo, input_dict_6) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create ip prefix list input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: - # Create standard large commumity-list + # Create standard large commumity-list input_dict_1 = { "r3": { "bgp_community_lists": [ @@ -1866,98 +1866,105 @@ def test_multiple_match_statement_in_route_map_logical_ANDed_p1(): "action": "permit", "name": "rmap_lcomm_{}".format(addr_type), "value": "1:1:1 1:2:3 2:1:1 2:2:2", - "large": True + "large": True, } ] } } result = create_bgp_community_lists(tgen, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verify BGP large community is created result = verify_create_community_list(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { "r3": { "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 150,}, } - }, - "set": { - "locPrf": 150, - } - }] + ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) for addr_type in ADDR_TYPES: - # Create route map + # Create route map input_dict_3 = { "r3": { "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type : { - "large_community_list": {"id": "rmap_lcomm_"+ - addr_type} + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "large_community_list": { + "id": "rmap_lcomm_" + addr_type + } + } + }, + "set": {"locPrf": 150,}, } - }, - "set": { - "locPrf": 150, - } - }] + ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map for addr_type in ADDR_TYPES: input_dict_4 = { - "r3": { - "bgp": { - "address_family": { - addr_type: { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_{}".format(addr_type), - "direction": "in" - }] - } - } - } - } - } - } - } - } - } + "r3": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_{}".format( + addr_type + ), + "direction": "in", + } + ] + } + } + } + } + } + } + } + } + } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # sleep(10) # Verifying RIB routes dut = "r3" @@ -1966,20 +1973,23 @@ def test_multiple_match_statement_in_route_map_logical_ANDed_p1(): for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -2008,50 +2018,46 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): input_dict_2 = { "r3": { "prefix_lists": { - "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "deny" - }] - }, - "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "deny" - }] - } + "ipv4": { + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "deny"} + ] + }, + "ipv6": { + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "deny"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } - }, - "set": { - "locPrf": 150, - } - }] + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 150,}, + } + ] + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { @@ -2064,11 +2070,12 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] } } } @@ -2081,36 +2088,36 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] } } } } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol, expected=False) + result = verify_rib( + tgen, addr_type, dut, input_dict, protocol=protocol, expected=False + ) assert result is not True, "Testcase {} : Failed \n Error" - "Routes are still present: {}".format( - tc_name, result) + "Routes are still present: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) # Remove applied rmap from neighbor @@ -2124,12 +2131,13 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", "direction": "in", - "delete": True - }] + "delete": True, + } + ] } } } @@ -2142,26 +2150,26 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", "direction": "in", - "delete": True - }] + "delete": True, + } + ] } } } } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" @@ -2170,7 +2178,8 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -2200,50 +2209,45 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] - }, + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] + }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } - }, - "set": { - "locPrf": 150, - "weight": 100 - } - }] + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "5", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 150, "weight": 100}, + } + ] + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { @@ -2256,11 +2260,12 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] } } } @@ -2273,25 +2278,25 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] } } } } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" @@ -2300,26 +2305,28 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # clear bgp, so config changes would be reflected dut = "r3" result = clear_bgp_and_verify(tgen, topo, dut) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" @@ -2328,20 +2335,23 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Flap interface to see if route-map properties are intact # Shutdown interface @@ -2358,8 +2368,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): # Verify BGP convergence once interface is up result = verify_bgp_convergence(tgen, topo) - assert result is True, ( - "setup_module :Failed \n Error:" " {}".format(result)) + assert result is True, "setup_module :Failed \n Error:" " {}".format(result) # Verifying RIB routes dut = "r3" @@ -2368,20 +2377,23 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -2409,22 +2421,21 @@ def test_rmap_without_match_and_set_clause_p0(): # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_no_match_set_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "5" - }], - "rmap_no_match_set_2_{}".format(addr_type): [{ - "action": "deny", - "seq_id": "5" - }] + "r3": { + "route_maps": { + "rmap_no_match_set_1_{}".format(addr_type): [ + {"action": "permit", "seq_id": "5"} + ], + "rmap_no_match_set_2_{}".format(addr_type): [ + {"action": "deny", "seq_id": "5"} + ], + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { @@ -2437,25 +2448,27 @@ def test_rmap_without_match_and_set_clause_p0(): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_no_match_set_1_ipv4", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_no_match_set_1_ipv4", + "direction": "in", + } + ] } } }, "r4": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_no_match_set_2_ipv4", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_no_match_set_2_ipv4", + "direction": "out", + } + ] } } - } + }, } } }, @@ -2465,36 +2478,37 @@ def test_rmap_without_match_and_set_clause_p0(): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_no_match_set_1_ipv6", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_no_match_set_1_ipv6", + "direction": "in", + } + ] } } }, "r4": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_no_match_set_2_ipv6", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_no_match_set_2_ipv6", + "direction": "out", + } + ] } } - } + }, } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" @@ -2503,17 +2517,18 @@ def test_rmap_without_match_and_set_clause_p0(): for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying RIB routes dut = "r4" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol, expected=False) + result = verify_rib( + tgen, addr_type, dut, input_dict, protocol=protocol, expected=False + ) assert result is not True, "Testcase {} : Failed \n" - "routes are not present \n Error: {}".format( - tc_name, result) + "routes are not present \n Error: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -2542,74 +2557,69 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): input_dict_2 = { "r3": { "prefix_lists": { - "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] - }, - "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "ipv4": { + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] + }, + "ipv6": { + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map - input_dict_3_addr_type ={} + input_dict_3_addr_type = {} for addr_type in ADDR_TYPES: input_dict_3 = { "r3": { "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ + "rmap_match_pf_1_{}".format(addr_type): [ + { "action": "permit", "match": { addr_type: { - "prefix_lists": "pf_list_1_{}".format( - addr_type) + "prefix_lists": "pf_list_1_{}".format(addr_type) } }, - "set": { - "metric": 50 - } - }], - "rmap_match_pf_2_{}".format(addr_type): [{ + "set": {"metric": 50}, + } + ], + "rmap_match_pf_2_{}".format(addr_type): [ + { "action": "permit", "match": { addr_type: { - "prefix_lists": "pf_list_1_{}".format( - addr_type) - }}, - "set": { - "locPrf": 150 - } - }], - "rmap_match_pf_3_{}".format(addr_type): [{ - "action": "permit", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format( - addr_type) - }}, - "set": { - "weight": 1000 - } - }] - } + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 150}, } - } + ], + "rmap_match_pf_3_{}".format(addr_type): [ + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"weight": 1000}, + } + ], + } + } + } input_dict_3_addr_type[addr_type] = input_dict_3 result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { @@ -2622,36 +2632,39 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] } } }, "r4": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv4", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv4", + "direction": "out", + } + ] } } }, "r5": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_3_ipv4", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_match_pf_3_ipv4", + "direction": "out", + } + ] } } - } + }, } } }, @@ -2661,123 +2674,137 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "r1": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] } } }, "r4": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv6", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv6", + "direction": "out", + } + ] } } }, "r5": { "dest_link": { "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_3_ipv6", - "direction": "out" - }] + "route_maps": [ + { + "name": "rmap_match_pf_3_ipv6", + "direction": "out", + } + ] } } - } + }, } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } rmap_name = "rmap_match_pf_1" for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[ - addr_type],rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying RIB routes dut = "r4" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r4" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } rmap_name = "rmap_match_pf_2" for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_2_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3_addr_type[addr_type], - expected=False) + result = verify_bgp_attributes( + tgen, + addr_type, + dut, + routes[addr_type], + rmap_name, + input_dict_3_addr_type[addr_type], + expected=False, + ) assert result is not True, "Testcase {} : Failed \n" - "Attributes are not set \n Error: {}".format( - tc_name, result) + "Attributes are not set \n Error: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes dut = "r5" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r5" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } rmap_name = "rmap_match_pf_3" for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_3_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3_addr_type[addr_type], - expected=False) + result = verify_bgp_attributes( + tgen, + addr_type, + dut, + routes[addr_type], + rmap_name, + input_dict_3_addr_type[addr_type], + expected=False, + ) assert result is not True, "Testcase {} : Failed \n" - "Attributes are not set \n Error: {}".format( - tc_name, result) + "Attributes are not set \n Error: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -2808,97 +2835,92 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } - }, - "set": { - "locPrf": 150, - "weight": 100, - "metric": 50 - } - }] + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 150, "weight": 100, "metric": 50}, + } + ] + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { - "r3": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] - } - } - } - } - } - } - } - } - } - } + "r3": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] + } + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] + } + } + } + } + } + }, + } + } + } + } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" @@ -2907,22 +2929,25 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } rmap_name = "rmap_match_pf_1" for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -2951,150 +2976,147 @@ def test_route_maps_with_continue_clause_p0(): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] - }, + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] + }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "10", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "10", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 150}, + "continue": "30", }, - "set": { - "locPrf": 150 + { + "action": "permit", + "seq_id": "20", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"metric": 200}, }, - "continue": "30" - }, - { - "action": "permit", - "seq_id": "20", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } + { + "action": "permit", + "seq_id": "30", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"metric": 100}, }, - "set": { - "metric": 200 - } - }, - { - "action": "permit", - "seq_id": "30", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } - }, - "set": { - "metric": 100 - } - } - ] + ] + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { - "r3": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] - } - } - } - } - } - } - } - } - } - } + "r3": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] + } + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] + } + } + } + } + } + }, + } + } + } + } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" rmap_name = "rmap_match_pf_1" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] - } - seq_id = { - "ipv4": ["10", "30"], - "ipv6": ["10", "30"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } + seq_id = {"ipv4": ["10", "30"], "ipv6": ["10", "30"]} for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[ - addr_type],rmap_name, input_dict_3, seq_id[addr_type]) + result = verify_bgp_attributes( + tgen, + addr_type, + dut, + routes[addr_type], + rmap_name, + input_dict_3, + seq_id[addr_type], + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -3123,120 +3145,114 @@ def test_route_maps_with_goto_clause_p0(): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] - }, + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] + }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "seq_id": "10", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "seq_id": "10", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "goto": "30", }, - "goto": "30" - }, - { - "action": "permit", - "seq_id": "20", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } + { + "action": "permit", + "seq_id": "20", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"metric": 100}, }, - "set": { - "metric": 100 - } - }, - { - "action": "permit", - "seq_id": "30", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } + { + "action": "permit", + "seq_id": "30", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"metric": 200}, }, - "set": { - "metric": 200 - } - } - ] + ] + } } } - } result = create_route_maps(tgen, input_dict_3) # tgen.mininet_cli() assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { - "r3": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] - } - } - } - } - } - } - } - } - } - } + "r3": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] + } + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] + } + } + } + } + } + }, + } + } + } + } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" @@ -3245,25 +3261,31 @@ def test_route_maps_with_goto_clause_p0(): for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" rmap_name = "rmap_match_pf_1" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] - } - seq_id = { - "ipv4": ["10", "30"], - "ipv6": ["10", "30"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } + seq_id = {"ipv4": ["10", "30"], "ipv6": ["10", "30"]} for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[ - addr_type],rmap_name, input_dict_3, seq_id[addr_type]) + result = verify_bgp_attributes( + tgen, + addr_type, + dut, + routes[addr_type], + rmap_name, + input_dict_3, + seq_id[addr_type], + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -3292,107 +3314,104 @@ def test_route_maps_with_call_clause_p0(): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] - }, + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] + }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "permit", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } - }, - "set": { - "locPrf": 150 - }, - "call": "rmap_match_pf_2_{}".format(addr_type) - }], - "rmap_match_pf_2_{}".format(addr_type): [{ - "action": "permit", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } - }, - "set": { - "metric": 200 - } - }] + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 150}, + "call": "rmap_match_pf_2_{}".format(addr_type), + } + ], + "rmap_match_pf_2_{}".format(addr_type): [ + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"metric": 200}, + } + ], + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { - "r3": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv6", - "direction": "in" - }] - } - } - } - } - } - } - } - } - } - } + "r3": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] + } + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv6", + "direction": "in", + } + ] + } + } + } + } + } + }, + } + } + } + } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" @@ -3401,29 +3420,34 @@ def test_route_maps_with_call_clause_p0(): for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Verifying BGP set attributes dut = "r3" routes = { - "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], - "ipv6": ["1::1/128", "1::2/128"] + "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], + "ipv6": ["1::1/128", "1::2/128"], } rmap_name = "rmap_match_pf_1" for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_1_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) rmap_name = "rmap_match_pf_2" for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_2_{}".format(addr_type) - result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3) + result = verify_bgp_attributes( + tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3 + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -3453,150 +3477,149 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): "r3": { "prefix_lists": { "ipv4": { - "pf_list_1_ipv4": [{ - "seqid": 10, - "network": "any", - "action": "permit" - }] - }, + "pf_list_1_ipv4": [ + {"seqid": 10, "network": "any", "action": "permit"} + ] + }, "ipv6": { - "pf_list_1_ipv6": [{ - "seqid": 100, - "network": "any", - "action": "permit" - }] - } + "pf_list_1_ipv6": [ + {"seqid": 100, "network": "any", "action": "permit"} + ] + }, } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { - "r3": { - "route_maps": { - "rmap_match_pf_1_{}".format(addr_type): [{ - "action": "deny", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } - }, - "set": { - "locPrf": 150, - } - }], - "rmap_match_pf_2_{}".format(addr_type): [{ - "action": "deny", - "match": { - addr_type: { - "prefix_lists": "pf_list_1_{}".format(addr_type) - } - }, - "set": { - "metric": 50 - } - }] + "r3": { + "route_maps": { + "rmap_match_pf_1_{}".format(addr_type): [ + { + "action": "deny", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"locPrf": 150,}, + } + ], + "rmap_match_pf_2_{}".format(addr_type): [ + { + "action": "deny", + "match": { + addr_type: { + "prefix_lists": "pf_list_1_{}".format(addr_type) + } + }, + "set": {"metric": 50}, + } + ], + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { - "r3": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] - } - } - }, - "r4": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv6", - "direction": "out" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r1": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_1_ipv4", - "direction": "in" - }] - } - } - }, - "r4": { - "dest_link": { - "r3": { - "route_maps": [{ - "name": - "rmap_match_pf_2_ipv6", - "direction": "out" - }] - } - } - } - } - } - } - } - } - } - } + "r3": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] + } + } + }, + "r4": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv6", + "direction": "out", + } + ] + } + } + }, + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_1_ipv4", + "direction": "in", + } + ] + } + } + }, + "r4": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "rmap_match_pf_2_ipv6", + "direction": "out", + } + ] + } + } + }, + } + } + }, + } + } + } + } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol, expected=False) + result = verify_rib( + tgen, addr_type, dut, input_dict, protocol=protocol, expected=False + ) assert result is not True, "Testcase {} : Failed \n" - "routes are not present \n Error: {}".\ - format(tc_name, result) + "routes are not present \n Error: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes dut = "r4" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol, expected=False) + result = verify_rib( + tgen, addr_type, dut, input_dict, protocol=protocol, expected=False + ) assert result is not True, "Testcase {} : Failed \n" - "routes are not present \n Error: {}".\ - format(tc_name, result) + "routes are not present \n Error: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -3627,18 +3650,15 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): input_dict = { "r1": { "static_routes": [ - { - "network": NETWORK[addr_type], - "next_hop": "Null0", - "tag": 4001 - } + {"network": NETWORK[addr_type], "next_hop": "Null0", "tag": 4001} ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Api call to redistribute static routes input_dict_1 = { @@ -3650,7 +3670,7 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } }, @@ -3658,84 +3678,82 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } - } - } + }, + }, } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create route map input_dict_3 = { - "r1": { - "route_maps": { - "rmap_match_tag_1_{}".format(addr_type): [{ - "action": "permit", - "match": { - addr_type: { - "tag": "4001" - } - } - }] + "r1": { + "route_maps": { + "rmap_match_tag_1_{}".format(addr_type): [ + {"action": "permit", "match": {addr_type: {"tag": "4001"}}} + ] + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { - "r1": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r3": { - "dest_link": { - "r1": { - "route_maps": [{ - "name": - "rmap_match_tag_1_ipv4", - "direction": "out" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r3": { - "dest_link": { - "r1": { - "route_maps": [{ - "name": - "rmap_match_tag_1_ipv6", - "direction": "out" - }] - } - } - } - } - } - } - } - } - } - } + "r1": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r3": { + "dest_link": { + "r1": { + "route_maps": [ + { + "name": "rmap_match_tag_1_ipv4", + "direction": "out", + } + ] + } + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r3": { + "dest_link": { + "r1": { + "route_maps": [ + { + "name": "rmap_match_tag_1_ipv6", + "direction": "out", + } + ] + } + } + } + } + } + }, + } + } + } + } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" @@ -3745,18 +3763,14 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): input_dict = { "r1": { "static_routes": [ - { - "network": NETWORK[addr_type], - "next_hop": "Null0", - "tag": 4001 - } + {"network": NETWORK[addr_type], "next_hop": "Null0", "tag": 4001} ] } } - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) + result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -3786,18 +3800,15 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): input_dict = { "r1": { "static_routes": [ - { - "network": NETWORK[addr_type], - "next_hop": "Null0", - "tag": 4001 - } + {"network": NETWORK[addr_type], "next_hop": "Null0", "tag": 4001} ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Api call to redistribute static routes input_dict_1 = { @@ -3809,7 +3820,7 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } }, @@ -3817,84 +3828,82 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): "unicast": { "redistribute": [ {"redist_type": "static"}, - {"redist_type": "connected"} + {"redist_type": "connected"}, ] } - } - } + }, + }, } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Create route map input_dict_3 = { - "r1": { - "route_maps": { - "rmap_match_tag_1_{}".format(addr_type): [{ - "action": "deny", - "match": { - addr_type: { - "tag": "4001" - } - } - }] + "r1": { + "route_maps": { + "rmap_match_tag_1_{}".format(addr_type): [ + {"action": "deny", "match": {addr_type: {"tag": "4001"}}} + ] + } } } - } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) # Configure neighbor for route map input_dict_4 = { - "r1": { - "bgp": { - "address_family": { - "ipv4": { - "unicast": { - "neighbor": { - "r3": { - "dest_link": { - "r1": { - "route_maps": [{ - "name": - "rmap_match_tag_1_ipv4", - "direction": "out" - }] - } - } - } - } - } - }, - "ipv6": { - "unicast": { - "neighbor": { - "r3": { - "dest_link": { - "r1": { - "route_maps": [{ - "name": - "rmap_match_tag_1_ipv6", - "direction": "out" - }] - } - } - } - } - } - } - } - } - } + "r1": { + "bgp": { + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r3": { + "dest_link": { + "r1": { + "route_maps": [ + { + "name": "rmap_match_tag_1_ipv4", + "direction": "out", + } + ] + } + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r3": { + "dest_link": { + "r1": { + "route_maps": [ + { + "name": "rmap_match_tag_1_ipv6", + "direction": "out", + } + ] + } + } + } + } + } + }, + } + } + } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" @@ -3904,19 +3913,15 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): input_dict = { "r1": { "static_routes": [ - { - "network": NETWORK[addr_type], - "next_hop": "Null0", - "tag": 4001 - } + {"network": NETWORK[addr_type], "next_hop": "Null0", "tag": 4001} ] } } - result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol, expected=False) + result = verify_rib( + tgen, addr_type, dut, input_dict, protocol=protocol, expected=False + ) assert result is not True, "Testcase {} : Failed \n" - "routes are denied \n Error: {}".format( - tc_name, result) + "routes are denied \n Error: {}".format(tc_name, result) logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -3924,6 +3929,7 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): # Uncomment next line for debugging # tgen.mininet_cli() + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp-vrf-route-leak-basic/test_bgp.py b/tests/topotests/bgp-vrf-route-leak-basic/test_bgp.py index b0d60403db..5aba89e3ca 100755 --- a/tests/topotests/bgp-vrf-route-leak-basic/test_bgp.py +++ b/tests/topotests/bgp-vrf-route-leak-basic/test_bgp.py @@ -31,7 +31,7 @@ import sys import pytest CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -47,7 +47,8 @@ class BGPVRFTopo(Topo): tgen = get_topogen(self) for routern in range(1, 2): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) + def setup_module(mod): "Sets up the pytest environment" @@ -58,17 +59,16 @@ def setup_module(mod): for rname, router in tgen.routers().iteritems(): router.run("/bin/bash {}/setup_vrfs".format(CWD)) router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) # After loading the configurations, this function loads configured daemons. tgen.start_router() - #tgen.mininet_cli() + # tgen.mininet_cli() + def teardown_module(mod): "Teardown the pytest environment" @@ -77,6 +77,7 @@ def teardown_module(mod): # This function tears down the whole topology. tgen.stop_topology() + def test_vrf_route_leak(): logger.info("Ensure that routes are leaked back and forth") tgen = get_topogen() @@ -84,49 +85,50 @@ def test_vrf_route_leak(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - r1 = tgen.gears['r1'] + r1 = tgen.gears["r1"] donna = r1.vtysh_cmd("show ip route vrf DONNA json", isjson=True) route0 = donna["10.0.0.0/24"][0] - assert route0['protocol'] == "connected" + assert route0["protocol"] == "connected" route1 = donna["10.0.1.0/24"][0] - assert route1['protocol'] == "bgp" - assert route1['selected'] == True - nhop = route1['nexthops'][0] - assert nhop['fib'] == True + assert route1["protocol"] == "bgp" + assert route1["selected"] == True + nhop = route1["nexthops"][0] + assert nhop["fib"] == True route2 = donna["10.0.2.0/24"][0] - assert route2['protocol'] == "connected" + assert route2["protocol"] == "connected" route3 = donna["10.0.3.0/24"][0] - assert route3['protocol'] == "bgp" - assert route3['selected'] == True - nhop = route3['nexthops'][0] - assert nhop['fib'] == True + assert route3["protocol"] == "bgp" + assert route3["selected"] == True + nhop = route3["nexthops"][0] + assert nhop["fib"] == True eva = r1.vtysh_cmd("show ip route vrf EVA json", isjson=True) route0 = eva["10.0.0.0/24"][0] - assert route0['protocol'] == "bgp" - assert route0['selected'] == True - nhop = route0['nexthops'][0] - assert nhop['fib'] == True + assert route0["protocol"] == "bgp" + assert route0["selected"] == True + nhop = route0["nexthops"][0] + assert nhop["fib"] == True route1 = eva["10.0.1.0/24"][0] - assert route1['protocol'] == "connected" + assert route1["protocol"] == "connected" route2 = eva["10.0.2.0/24"][0] - assert route2['protocol'] == "bgp" - assert route2['selected'] == True - nhop = route2['nexthops'][0] - assert nhop['fib'] == True + assert route2["protocol"] == "bgp" + assert route2["selected"] == True + nhop = route2["nexthops"][0] + assert nhop["fib"] == True route3 = eva["10.0.3.0/24"][0] - assert route3['protocol'] == "connected" - #tgen.mininet_cli() + assert route3["protocol"] == "connected" + # tgen.mininet_cli() + def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_aggregate-address_origin/test_bgp_aggregate-address_origin.py b/tests/topotests/bgp_aggregate-address_origin/test_bgp_aggregate-address_origin.py index be29d143dd..fa799f8256 100644 --- a/tests/topotests/bgp_aggregate-address_origin/test_bgp_aggregate-address_origin.py +++ b/tests/topotests/bgp_aggregate-address_origin/test_bgp_aggregate-address_origin.py @@ -39,7 +39,7 @@ import pytest import functools CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -47,16 +47,18 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 3): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -66,51 +68,41 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_aggregate_address_origin(): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) - router = tgen.gears['r2'] + router = tgen.gears["r2"] def _bgp_converge(router): output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) expected = { - '192.168.255.1': { - 'bgpState': 'Established', - 'addressFamilyInfo': { - 'ipv4Unicast': { - 'acceptedPrefixCounter': 3 - } - } + "192.168.255.1": { + "bgpState": "Established", + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 3}}, } } return topotest.json_cmp(output, expected) def _bgp_aggregate_address_has_metric(router): output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.0/24 json")) - expected = { - 'paths': [ - { - 'origin': 'IGP' - } - ] - } + expected = {"paths": [{"origin": "IGP"}]} return topotest.json_cmp(output, expected) test_func = functools.partial(_bgp_converge, router) @@ -121,8 +113,11 @@ def test_bgp_aggregate_address_origin(): test_func = functools.partial(_bgp_aggregate_address_has_metric, router) success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) - assert result is None, 'Failed to see applied ORIGIN (igp) for aggregated prefix in "{}"'.format(router) + assert ( + result is None + ), 'Failed to see applied ORIGIN (igp) for aggregated prefix in "{}"'.format(router) -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py b/tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py index 053f928810..9c06c9d382 100644 --- a/tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py +++ b/tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py @@ -42,7 +42,7 @@ import pytest import functools CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -50,16 +50,18 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 3): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -69,51 +71,41 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_maximum_prefix_invalid(): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) - router = tgen.gears['r2'] + router = tgen.gears["r2"] def _bgp_converge(router): output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) expected = { - '192.168.255.1': { - 'bgpState': 'Established', - 'addressFamilyInfo': { - 'ipv4Unicast': { - 'acceptedPrefixCounter': 3 - } - } + "192.168.255.1": { + "bgpState": "Established", + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 3}}, } } return topotest.json_cmp(output, expected) def _bgp_aggregate_address_has_metric(router): output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.0/24 json")) - expected = { - 'paths': [ - { - 'metric': 123 - } - ] - } + expected = {"paths": [{"metric": 123}]} return topotest.json_cmp(output, expected) test_func = functools.partial(_bgp_converge, router) @@ -124,8 +116,11 @@ def test_bgp_maximum_prefix_invalid(): test_func = functools.partial(_bgp_aggregate_address_has_metric, router) success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) - assert result is None, 'Failed to see applied metric for aggregated prefix in "{}"'.format(router) + assert ( + result is None + ), 'Failed to see applied metric for aggregated prefix in "{}"'.format(router) -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py b/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py index 55021aaa09..ebd6075b52 100644 --- a/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py +++ b/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py @@ -37,7 +37,7 @@ import pytest import functools CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -45,17 +45,19 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 4): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -65,20 +67,20 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_as_wide_bgp_identifier(): tgen = get_topogen() @@ -87,32 +89,31 @@ def test_bgp_as_wide_bgp_identifier(): def _bgp_converge(router): output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) - expected = { - '192.168.255.1': { - 'bgpState': 'Established' - } - } + expected = {"192.168.255.1": {"bgpState": "Established"}} return topotest.json_cmp(output, expected) def _bgp_failed(router): output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) expected = { - '192.168.255.1': { - 'lastNotificationReason': 'OPEN Message Error/Bad BGP Identifier' + "192.168.255.1": { + "lastNotificationReason": "OPEN Message Error/Bad BGP Identifier" } } return topotest.json_cmp(output, expected) - test_func = functools.partial(_bgp_converge, tgen.gears['r1']) + test_func = functools.partial(_bgp_converge, tgen.gears["r1"]) success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) - assert result is None, 'Failed to converge: "{}"'.format(tgen.gears['r1']) + assert result is None, 'Failed to converge: "{}"'.format(tgen.gears["r1"]) - test_func = functools.partial(_bgp_failed, tgen.gears['r3']) + test_func = functools.partial(_bgp_failed, tgen.gears["r3"]) success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) - assert result is None, 'Bad BGP Identifier notification not sent: "{}"'.format(tgen.gears['r3']) + assert result is None, 'Bad BGP Identifier notification not sent: "{}"'.format( + tgen.gears["r3"] + ) -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_comm-list_delete/test_bgp_comm-list_delete.py b/tests/topotests/bgp_comm-list_delete/test_bgp_comm-list_delete.py index ed350ebfeb..314ad12a6d 100644 --- a/tests/topotests/bgp_comm-list_delete/test_bgp_comm-list_delete.py +++ b/tests/topotests/bgp_comm-list_delete/test_bgp_comm-list_delete.py @@ -37,7 +37,7 @@ import time import pytest CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -45,16 +45,18 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 3): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -64,20 +66,20 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_maximum_prefix_invalid(): tgen = get_topogen() @@ -86,20 +88,30 @@ def test_bgp_maximum_prefix_invalid(): def _bgp_converge(router): while True: - output = json.loads(tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) - if output['192.168.255.1']['bgpState'] == 'Established': - if output['192.168.255.1']['addressFamilyInfo']['ipv4Unicast']['acceptedPrefixCounter'] == 2: + output = json.loads( + tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json") + ) + if output["192.168.255.1"]["bgpState"] == "Established": + if ( + output["192.168.255.1"]["addressFamilyInfo"]["ipv4Unicast"][ + "acceptedPrefixCounter" + ] + == 2 + ): return True def _bgp_comm_list_delete(router): - output = json.loads(tgen.gears[router].vtysh_cmd("show ip bgp 172.16.255.254/32 json")) - if '333:333' in output['paths'][0]['community']['list']: + output = json.loads( + tgen.gears[router].vtysh_cmd("show ip bgp 172.16.255.254/32 json") + ) + if "333:333" in output["paths"][0]["community"]["list"]: return False return True - if _bgp_converge('r2'): - assert _bgp_comm_list_delete('r2') == True + if _bgp_converge("r2"): + assert _bgp_comm_list_delete("r2") == True -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_default-route_route-map/test_bgp_default-originate_route-map.py b/tests/topotests/bgp_default-route_route-map/test_bgp_default-originate_route-map.py index 04a04cce37..ba9a6dffb5 100644 --- a/tests/topotests/bgp_default-route_route-map/test_bgp_default-originate_route-map.py +++ b/tests/topotests/bgp_default-route_route-map/test_bgp_default-originate_route-map.py @@ -42,7 +42,7 @@ import pytest import functools CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -50,16 +50,18 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 3): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -69,51 +71,41 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_default_originate_route_map(): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) - router = tgen.gears['r2'] + router = tgen.gears["r2"] def _bgp_converge(router): output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) expected = { - '192.168.255.1': { - 'bgpState': 'Established', - 'addressFamilyInfo': { - 'ipv4Unicast': { - 'acceptedPrefixCounter': 1 - } - } + "192.168.255.1": { + "bgpState": "Established", + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 1}}, } } return topotest.json_cmp(output, expected) def _bgp_default_route_has_metric(router): output = json.loads(router.vtysh_cmd("show ip bgp 0.0.0.0/0 json")) - expected = { - 'paths': [ - { - 'metric': 123 - } - ] - } + expected = {"paths": [{"metric": 123}]} return topotest.json_cmp(output, expected) test_func = functools.partial(_bgp_converge, router) @@ -124,8 +116,11 @@ def test_bgp_default_originate_route_map(): test_func = functools.partial(_bgp_default_route_has_metric, router) success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) - assert result is None, 'Failed to see applied metric for default route in "{}"'.format(router) + assert ( + result is None + ), 'Failed to see applied metric for default route in "{}"'.format(router) -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_distance_change/test_bgp_distance_change.py b/tests/topotests/bgp_distance_change/test_bgp_distance_change.py index cf95aec098..6d09cd2e8c 100644 --- a/tests/topotests/bgp_distance_change/test_bgp_distance_change.py +++ b/tests/topotests/bgp_distance_change/test_bgp_distance_change.py @@ -41,7 +41,7 @@ import pytest import functools CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -49,16 +49,18 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 3): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -68,60 +70,51 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_maximum_prefix_invalid(): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) - router = tgen.gears['r1'] + router = tgen.gears["r1"] def _bgp_converge(router): output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json")) expected = { - '192.168.255.2': { - 'bgpState': 'Established', - 'addressFamilyInfo': { - 'ipv4Unicast': { - 'acceptedPrefixCounter': 2 - } - } + "192.168.255.2": { + "bgpState": "Established", + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}}, } } return topotest.json_cmp(output, expected) def _bgp_distance_change(router): - router.vtysh_cmd(""" + router.vtysh_cmd( + """ configure terminal router bgp 65000 address-family ipv4 unicast distance bgp 123 123 123 - """) + """ + ) def _bgp_check_distance_change(router): output = json.loads(router.vtysh_cmd("show ip route 172.16.255.254/32 json")) - expected = { - '172.16.255.254/32': [ - { - 'protocol': 'bgp', - 'distance': 123 - } - ] - } + expected = {"172.16.255.254/32": [{"protocol": "bgp", "distance": 123}]} return topotest.json_cmp(output, expected) test_func = functools.partial(_bgp_converge, router) @@ -134,8 +127,11 @@ def test_bgp_maximum_prefix_invalid(): test_func = functools.partial(_bgp_check_distance_change, router) success, result = topotest.run_and_expect(test_func, None, count=15, wait=0.5) - assert result is None, 'Failed to see applied BGP distance in RIB "{}"'.format(router) + assert result is None, 'Failed to see applied BGP distance in RIB "{}"'.format( + router + ) -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py b/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py index 6660b4e866..bdacff3a9c 100644 --- a/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py +++ b/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py @@ -37,7 +37,7 @@ import pytest import functools CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -45,24 +45,26 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 7): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r3']) - switch.add_link(tgen.gears['r4']) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) + + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r5"]) + switch.add_link(tgen.gears["r6"]) - switch = tgen.add_switch('s3') - switch.add_link(tgen.gears['r5']) - switch.add_link(tgen.gears['r6']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -72,20 +74,20 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_ebgp_requires_policy(): tgen = get_topogen() @@ -93,51 +95,46 @@ def test_ebgp_requires_policy(): pytest.skip(tgen.errors) def _bgp_converge(router): - output = json.loads(tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) - expected = { - '192.168.255.1': { - 'bgpState': 'Established' - } - } + output = json.loads( + tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json") + ) + expected = {"192.168.255.1": {"bgpState": "Established"}} return topotest.json_cmp(output, expected) def _bgp_has_routes(router): - output = json.loads(tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 routes json")) - expected = { - 'routes': { - '172.16.255.254/32': [ - { - 'valid': True - } - ] - } - } + output = json.loads( + tgen.gears[router].vtysh_cmd( + "show ip bgp neighbor 192.168.255.1 routes json" + ) + ) + expected = {"routes": {"172.16.255.254/32": [{"valid": True}]}} return topotest.json_cmp(output, expected) - test_func = functools.partial(_bgp_converge, 'r2') + test_func = functools.partial(_bgp_converge, "r2") success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) assert success is True, 'Failed bgp convergence (r2) in "{}"'.format(router) - test_func = functools.partial(_bgp_has_routes, 'r2') + test_func = functools.partial(_bgp_has_routes, "r2") success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) assert success is True, 'eBGP policy is not working (r2) in "{}"'.format(router) - test_func = functools.partial(_bgp_converge, 'r4') + test_func = functools.partial(_bgp_converge, "r4") success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) assert success is True, 'Failed bgp convergence (r4) in "{}"'.format(router) - test_func = functools.partial(_bgp_has_routes, 'r4') + test_func = functools.partial(_bgp_has_routes, "r4") success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) assert success is False, 'eBGP policy is not working (r4) in "{}"'.format(router) - test_func = functools.partial(_bgp_converge, 'r6') + test_func = functools.partial(_bgp_converge, "r6") success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) assert success is True, 'Failed bgp convergence (r6) in "{}"'.format(router) - test_func = functools.partial(_bgp_has_routes, 'r6') + test_func = functools.partial(_bgp_has_routes, "r6") success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) assert success is True, 'eBGP policy is not working (r6) in "{}"'.format(router) -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_instance_del_test/test_bgp_instance_del_test.py b/tests/topotests/bgp_instance_del_test/test_bgp_instance_del_test.py index 115c7793ad..47cc0eb39d 100755 --- a/tests/topotests/bgp_instance_del_test/test_bgp_instance_del_test.py +++ b/tests/topotests/bgp_instance_del_test/test_bgp_instance_del_test.py @@ -25,65 +25,72 @@ import os import sys import pytest -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../')) +sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")) from lib.ltemplate import * + def test_check_linux_vrf(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\', iproute2=\'4.9\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest('scripts/check_linux_vrf.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' + ltemplateTest("scripts/check_linux_vrf.py", False, CliOnFail, CheckFunc) + def test_adjacencies(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' - ltemplateTest('scripts/adjacencies.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' + ltemplateTest("scripts/adjacencies.py", False, CliOnFail, CheckFunc) + def SKIP_test_add_routes(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' - ltemplateTest('scripts/add_routes.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' + ltemplateTest("scripts/add_routes.py", False, CliOnFail, CheckFunc) + def test_check_routes(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' - ltemplateTest('scripts/check_routes.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' + ltemplateTest("scripts/check_routes.py", False, CliOnFail, CheckFunc) -#manual data path setup test - remove once have bgp/zebra vrf path working + +# manual data path setup test - remove once have bgp/zebra vrf path working def test_check_linux_mpls(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\', iproute2=\'4.9\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest('scripts/check_linux_mpls.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' + ltemplateTest("scripts/check_linux_mpls.py", False, CliOnFail, CheckFunc) + def test_del_bgp_instances(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' - ltemplateTest('scripts/del_bgp_instances.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' + ltemplateTest("scripts/del_bgp_instances.py", False, CliOnFail, CheckFunc) -if __name__ == '__main__': + +if __name__ == "__main__": retval = pytest.main(["-s"]) sys.exit(retval) diff --git a/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py b/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py index 6cf223af42..10b2f3595f 100644 --- a/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py +++ b/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py @@ -34,7 +34,7 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -48,17 +48,19 @@ from mininet.topo import Topo class BGPIPV6RTADVTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) # Create 2 routers. - tgen.add_router('r1') - tgen.add_router('r2') + tgen.add_router("r1") + tgen.add_router("r2") + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) def setup_module(mod): "Sets up the pytest environment" @@ -69,17 +71,16 @@ def setup_module(mod): for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) # Initialize all routers. tgen.start_router() + def teardown_module(_mod): "Teardown the pytest environment" tgen = get_topogen() @@ -99,44 +100,51 @@ def test_protocols_convergence(): # Check IPv4 routing tables. logger.info("Checking IPv4 routes for convergence") for router in tgen.routers().values(): - json_file = '{}/{}/ipv4_routes.json'.format(CWD, router.name) + json_file = "{}/{}/ipv4_routes.json".format(CWD, router.name) if not os.path.isfile(json_file): - logger.info('skipping file {}'.format(json_file)) + logger.info("skipping file {}".format(json_file)) continue expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show ip route json'.format(router.name), expected) - _, result = topotest.run_and_expect(test_func, None, count=160, - wait=0.5) + test_func = partial( + topotest.router_json_cmp, + router, + "show ip route json".format(router.name), + expected, + ) + _, result = topotest.run_and_expect(test_func, None, count=160, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg # Check IPv6 routing tables. logger.info("Checking IPv6 routes for convergence") for router in tgen.routers().values(): - json_file = '{}/{}/ipv6_routes.json'.format(CWD, router.name) + json_file = "{}/{}/ipv6_routes.json".format(CWD, router.name) if not os.path.isfile(json_file): - logger.info('skipping file {}'.format(json_file)) + logger.info("skipping file {}".format(json_file)) continue expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show ipv6 route json'.format(router.name), expected) - _, result = topotest.run_and_expect(test_func, None, count=160, - wait=0.5) + test_func = partial( + topotest.router_json_cmp, + router, + "show ipv6 route json".format(router.name), + expected, + ) + _, result = topotest.run_and_expect(test_func, None, count=160, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg + def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py index b4649059bc..05db9ab14b 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py @@ -88,12 +88,15 @@ from lib.ltemplate import ltemplateRtrCmd from mininet.topo import Topo import shutil + CWD = os.path.dirname(os.path.realpath(__file__)) # test name based on directory TEST = os.path.basename(CWD) + class ThisTestTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) @@ -102,68 +105,71 @@ class ThisTestTopo(Topo): # between routers, switches and hosts. # # Create P/PE routers - tgen.add_router('r1') - #check for mpls + tgen.add_router("r1") + # check for mpls if tgen.hasmpls != True: - logger.info('MPLS not available, tests will be skipped') + logger.info("MPLS not available, tests will be skipped") return for routern in range(2, 5): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) # Create CE routers for routern in range(1, 4): - tgen.add_router('ce{}'.format(routern)) + tgen.add_router("ce{}".format(routern)) - #CE/PE links - tgen.add_link(tgen.gears['ce1'], tgen.gears['r1'], 'ce1-eth0', 'r1-eth4') - tgen.add_link(tgen.gears['ce2'], tgen.gears['r3'], 'ce2-eth0', 'r3-eth4') - tgen.add_link(tgen.gears['ce3'], tgen.gears['r4'], 'ce3-eth0', 'r4-eth4') + # CE/PE links + tgen.add_link(tgen.gears["ce1"], tgen.gears["r1"], "ce1-eth0", "r1-eth4") + tgen.add_link(tgen.gears["ce2"], tgen.gears["r3"], "ce2-eth0", "r3-eth4") + tgen.add_link(tgen.gears["ce3"], tgen.gears["r4"], "ce3-eth0", "r4-eth4") # Create a switch with just one router connected to it to simulate a # empty network. switch = {} - switch[0] = tgen.add_switch('sw0') - switch[0].add_link(tgen.gears['r1'], nodeif='r1-eth0') - switch[0].add_link(tgen.gears['r2'], nodeif='r2-eth0') + switch[0] = tgen.add_switch("sw0") + switch[0].add_link(tgen.gears["r1"], nodeif="r1-eth0") + switch[0].add_link(tgen.gears["r2"], nodeif="r2-eth0") - switch[1] = tgen.add_switch('sw1') - switch[1].add_link(tgen.gears['r2'], nodeif='r2-eth1') - switch[1].add_link(tgen.gears['r3'], nodeif='r3-eth0') - switch[1].add_link(tgen.gears['r4'], nodeif='r4-eth0') + switch[1] = tgen.add_switch("sw1") + switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth1") + switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth0") + switch[1].add_link(tgen.gears["r4"], nodeif="r4-eth0") + + switch[1] = tgen.add_switch("sw2") + switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth2") + switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth1") - switch[1] = tgen.add_switch('sw2') - switch[1].add_link(tgen.gears['r2'], nodeif='r2-eth2') - switch[1].add_link(tgen.gears['r3'], nodeif='r3-eth1') def ltemplatePreRouterStartHook(): cc = ltemplateRtrCmd() tgen = get_topogen() - logger.info('pre router-start hook') - #check for mpls + logger.info("pre router-start hook") + # check for mpls if tgen.hasmpls != True: - logger.info('MPLS not available, skipping setup') + logger.info("MPLS not available, skipping setup") return False - #check for normal init + # check for normal init if len(tgen.net) == 1: - logger.info('Topology not configured, skipping setup') + logger.info("Topology not configured, skipping setup") return False - #configure r2 mpls interfaces - intfs = ['lo', 'r2-eth0', 'r2-eth1', 'r2-eth2'] + # configure r2 mpls interfaces + intfs = ["lo", "r2-eth0", "r2-eth1", "r2-eth2"] for intf in intfs: - cc.doCmd(tgen, 'r2', 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf)) - #configure MPLS - rtrs = ['r1', 'r3', 'r4'] - cmds = ['echo 1 > /proc/sys/net/mpls/conf/lo/input'] + cc.doCmd(tgen, "r2", "echo 1 > /proc/sys/net/mpls/conf/{}/input".format(intf)) + # configure MPLS + rtrs = ["r1", "r3", "r4"] + cmds = ["echo 1 > /proc/sys/net/mpls/conf/lo/input"] for rtr in rtrs: router = tgen.gears[rtr] for cmd in cmds: cc.doCmd(tgen, rtr, cmd) - intfs = ['lo', rtr+'-eth0', rtr+'-eth4'] + intfs = ["lo", rtr + "-eth0", rtr + "-eth4"] for intf in intfs: - cc.doCmd(tgen, rtr, 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf)) - logger.info('setup mpls input') + cc.doCmd( + tgen, rtr, "echo 1 > /proc/sys/net/mpls/conf/{}/input".format(intf) + ) + logger.info("setup mpls input") return True + def ltemplatePostRouterStartHook(): - logger.info('post router-start hook') + logger.info("post router-start hook") return True - diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/add_routes.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/add_routes.py index 3a24367a56..3f1157ad72 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/add_routes.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/add_routes.py @@ -1,51 +1,193 @@ from lutil import luCommand -luCommand('r1','vtysh -c "show bgp next"','99.0.0.. valid', 'wait', 'See CE static NH') -luCommand('r3','vtysh -c "show bgp next"','99.0.0.. valid', 'wait', 'See CE static NH') -luCommand('r4','vtysh -c "show bgp next"','99.0.0.. valid', 'wait', 'See CE static NH') -luCommand('r1','vtysh -c "show bgp ipv4 uni"','i5.*i5','wait','See CE routes') -luCommand('r3','vtysh -c "show bgp ipv4 uni"','i5.*i5','wait','See CE routes') -luCommand('r4','vtysh -c "show bgp ipv4 uni"','i5.*i5','wait','See CE routes') -luCommand('ce1','vtysh -c "show bgp ipv4 uni 5.1.0.0/24"','','none','See CE routes') -luCommand('r1','vtysh -c "show bgp ipv4 uni 5.1.0.0/24"','','none','See CE routes') -luCommand('ce2','vtysh -c "show bgp ipv4 uni 5.1.0.0/24"','','none','See CE routes') -luCommand('r3','vtysh -c "show bgp ipv4 uni 5.1.0.0/24"','','none','See CE routes') -luCommand('ce3','vtysh -c "show bgp ipv4 uni 5.1.2.0/24"','','none','See CE routes') -luCommand('r4','vtysh -c "show bgp ipv4 uni 5.1.2.0/24"','','none','See CE routes') -luCommand('r1','vtysh -c "add vrf cust1 prefix 99.0.0.1/32"','.','none','IP Address') -luCommand('r1','vtysh -c "show vnc registrations local"','99.0.0.1','wait','Local Registration') -luCommand('r1','vtysh -c "show vnc registrations imported"','2 out of 2 imported','wait','Imported Registrations') -luCommand('r3','vtysh -c "show bgp ipv4 vpn"','i99.0.0.1/32','wait','See R1s static address') -luCommand('r4','vtysh -c "show bgp ipv4 vpn"','i99.0.0.1/32','wait','See R1s static address') -luCommand('r3','vtysh -c "show bgp ipv4 vpn rd 10:1"','i5.*i5','wait','See R1s imports') -luCommand('r4','vtysh -c "show bgp ipv4 vpn rd 10:1"','i5.*i5','wait','See R1s imports') +luCommand( + "r1", 'vtysh -c "show bgp next"', "99.0.0.. valid", "wait", "See CE static NH" +) +luCommand( + "r3", 'vtysh -c "show bgp next"', "99.0.0.. valid", "wait", "See CE static NH" +) +luCommand( + "r4", 'vtysh -c "show bgp next"', "99.0.0.. valid", "wait", "See CE static NH" +) +luCommand("r1", 'vtysh -c "show bgp ipv4 uni"', "i5.*i5", "wait", "See CE routes") +luCommand("r3", 'vtysh -c "show bgp ipv4 uni"', "i5.*i5", "wait", "See CE routes") +luCommand("r4", 'vtysh -c "show bgp ipv4 uni"', "i5.*i5", "wait", "See CE routes") +luCommand("ce1", 'vtysh -c "show bgp ipv4 uni 5.1.0.0/24"', "", "none", "See CE routes") +luCommand("r1", 'vtysh -c "show bgp ipv4 uni 5.1.0.0/24"', "", "none", "See CE routes") +luCommand("ce2", 'vtysh -c "show bgp ipv4 uni 5.1.0.0/24"', "", "none", "See CE routes") +luCommand("r3", 'vtysh -c "show bgp ipv4 uni 5.1.0.0/24"', "", "none", "See CE routes") +luCommand("ce3", 'vtysh -c "show bgp ipv4 uni 5.1.2.0/24"', "", "none", "See CE routes") +luCommand("r4", 'vtysh -c "show bgp ipv4 uni 5.1.2.0/24"', "", "none", "See CE routes") -luCommand('r3','vtysh -c "add vrf cust1 prefix 99.0.0.2/32"','.','none','IP Address') -luCommand('r3','vtysh -c "show vnc registrations local"','99.0.0.2','wait','Local Registration') -have2ndImports = luCommand('r3','vtysh -c "show vnc registrations imported"','2 out of 2 imported','none','Imported Registrations',2) +luCommand( + "r1", 'vtysh -c "add vrf cust1 prefix 99.0.0.1/32"', ".", "none", "IP Address" +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations local"', + "99.0.0.1", + "wait", + "Local Registration", +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations imported"', + "2 out of 2 imported", + "wait", + "Imported Registrations", +) +luCommand( + "r3", + 'vtysh -c "show bgp ipv4 vpn"', + "i99.0.0.1/32", + "wait", + "See R1s static address", +) +luCommand( + "r4", + 'vtysh -c "show bgp ipv4 vpn"', + "i99.0.0.1/32", + "wait", + "See R1s static address", +) +luCommand( + "r3", 'vtysh -c "show bgp ipv4 vpn rd 10:1"', "i5.*i5", "wait", "See R1s imports" +) +luCommand( + "r4", 'vtysh -c "show bgp ipv4 vpn rd 10:1"', "i5.*i5", "wait", "See R1s imports" +) + +luCommand( + "r3", 'vtysh -c "add vrf cust1 prefix 99.0.0.2/32"', ".", "none", "IP Address" +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations local"', + "99.0.0.2", + "wait", + "Local Registration", +) +have2ndImports = luCommand( + "r3", + 'vtysh -c "show vnc registrations imported"', + "2 out of 2 imported", + "none", + "Imported Registrations", + 2, +) if have2ndImports: - luCommand('r3','vtysh -c "show vnc registrations imported"','2 out of 2 imported','pass','Imported Registrations') -luCommand('r1','vtysh -c "show bgp ipv4 vpn"','i99.0.0.2/32','wait','See R3s static address') -luCommand('r4','vtysh -c "show bgp ipv4 vpn"','i99.0.0.2/32','wait','See R3s static address') + luCommand( + "r3", + 'vtysh -c "show vnc registrations imported"', + "2 out of 2 imported", + "pass", + "Imported Registrations", + ) +luCommand( + "r1", + 'vtysh -c "show bgp ipv4 vpn"', + "i99.0.0.2/32", + "wait", + "See R3s static address", +) +luCommand( + "r4", + 'vtysh -c "show bgp ipv4 vpn"', + "i99.0.0.2/32", + "wait", + "See R3s static address", +) if have2ndImports: - luCommand('r1','vtysh -c "show bgp ipv4 vpn rd 10:3"','i5.*i5','none','See R3s imports') - luCommand('r4','vtysh -c "show bgp ipv4 vpn rd 10:3"','i5.*i5','none','See R3s imports') + luCommand( + "r1", + 'vtysh -c "show bgp ipv4 vpn rd 10:3"', + "i5.*i5", + "none", + "See R3s imports", + ) + luCommand( + "r4", + 'vtysh -c "show bgp ipv4 vpn rd 10:3"', + "i5.*i5", + "none", + "See R3s imports", + ) -luCommand('r4','vtysh -c "add vrf cust1 prefix 99.0.0.3/32"','.','none','IP Address') -luCommand('r4','vtysh -c "show vnc registrations local"','99.0.0.3','wait','Local Registration') -luCommand('r4','vtysh -c "show vnc registrations imported"','2 out of 2 imported','wait','Imported Registrations') -luCommand('r1','vtysh -c "show bgp ipv4 vpn"','i99.0.0.3/32','wait','See R4s static address') -luCommand('r3','vtysh -c "show bgp ipv4 vpn"','i99.0.0.3/32','wait','See R4s static address') -luCommand('r1','vtysh -c "show bgp ipv4 vpn rd 10:4"','i5.*i5','wait','See R4s imports') -luCommand('r3','vtysh -c "show bgp ipv4 vpn rd 10:4"','i5.*i5','wait','See R4s imports') +luCommand( + "r4", 'vtysh -c "add vrf cust1 prefix 99.0.0.3/32"', ".", "none", "IP Address" +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations local"', + "99.0.0.3", + "wait", + "Local Registration", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations imported"', + "2 out of 2 imported", + "wait", + "Imported Registrations", +) +luCommand( + "r1", + 'vtysh -c "show bgp ipv4 vpn"', + "i99.0.0.3/32", + "wait", + "See R4s static address", +) +luCommand( + "r3", + 'vtysh -c "show bgp ipv4 vpn"', + "i99.0.0.3/32", + "wait", + "See R4s static address", +) +luCommand( + "r1", 'vtysh -c "show bgp ipv4 vpn rd 10:4"', "i5.*i5", "wait", "See R4s imports" +) +luCommand( + "r3", 'vtysh -c "show bgp ipv4 vpn rd 10:4"', "i5.*i5", "wait", "See R4s imports" +) -luCommand('r1','vtysh -c "show vnc registrations remote"','5.1.2.0/24 .*5.1.3.0/24','wait','R4s registrations') -luCommand('r3','vtysh -c "show vnc registrations remote"','5.1.2.0/24 .*5.1.3.0/24','wait','R4s registrations') +luCommand( + "r1", + 'vtysh -c "show vnc registrations remote"', + "5.1.2.0/24 .*5.1.3.0/24", + "wait", + "R4s registrations", +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations remote"', + "5.1.2.0/24 .*5.1.3.0/24", + "wait", + "R4s registrations", +) if have2ndImports: - luCommand('r1','vtysh -c "show vnc registrations remote"','5.1.0.0/24 .*5.1.1.0/24','wait','Remote registrations') - luCommand('r3','vtysh -c "show vnc registrations remote"','5.1.0.0/24 .*5.1.1.0/24','wait','Remote registrations') -luCommand('r4','vtysh -c "show vnc registrations remote"','5.1.0.0/24 .*5.1.1.0/24','wait','Remote registrations') -luCommand('r1','vtysh -c "show vnc registrations"','.','none') -luCommand('r3','vtysh -c "show vnc registrations"','.','none') -luCommand('r4','vtysh -c "show vnc registrations"','.','none') + luCommand( + "r1", + 'vtysh -c "show vnc registrations remote"', + "5.1.0.0/24 .*5.1.1.0/24", + "wait", + "Remote registrations", + ) + luCommand( + "r3", + 'vtysh -c "show vnc registrations remote"', + "5.1.0.0/24 .*5.1.1.0/24", + "wait", + "Remote registrations", + ) +luCommand( + "r4", + 'vtysh -c "show vnc registrations remote"', + "5.1.0.0/24 .*5.1.1.0/24", + "wait", + "Remote registrations", +) +luCommand("r1", 'vtysh -c "show vnc registrations"', ".", "none") +luCommand("r3", 'vtysh -c "show vnc registrations"', ".", "none") +luCommand("r4", 'vtysh -c "show vnc registrations"', ".", "none") diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/adjacencies.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/adjacencies.py index 1317a510d1..ea059c576e 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/adjacencies.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/adjacencies.py @@ -1,20 +1,64 @@ from lutil import luCommand -luCommand('ce1','ping 192.168.1.1 -c 1',' 0. packet loss','pass','CE->PE ping') -luCommand('ce2','ping 192.168.1.1 -c 1',' 0. packet loss','pass','CE->PE ping') -luCommand('ce3','ping 192.168.1.1 -c 1',' 0. packet loss','pass','CE->PE ping') -luCommand('ce1','vtysh -c "show bgp summary"',' 00:0','wait','Adjacencies up',180) -luCommand('ce2','vtysh -c "show bgp summary"',' 00:0','wait','Adjacencies up',180) -luCommand('ce3','vtysh -c "show bgp summary"',' 00:0','wait','Adjacencies up',180) -luCommand('r1','ping 2.2.2.2 -c 1',' 0. packet loss','wait','PE->P2 (loopback) ping',60) -luCommand('r3','ping 2.2.2.2 -c 1',' 0. packet loss','wait','PE->P2 (loopback) ping',60) -luCommand('r4','ping 2.2.2.2 -c 1',' 0. packet loss','wait','PE->P2 (loopback) ping',60) -luCommand('r2','vtysh -c "show bgp summary"',' 00:0.* 00:0.* 00:0','wait','Core adjacencies up',180) -luCommand('r1','vtysh -c "show bgp summary"',' 00:0','wait','Core adjacencies up',180) -luCommand('r3','vtysh -c "show bgp summary"',' 00:0','wait','Core adjacencies up',180) -luCommand('r4','vtysh -c "show bgp summary"',' 00:0','wait','Core adjacencies up',180) -luCommand('r1','vtysh -c "show bgp vrf all summary"',' 00:0.* 00:0','pass','All adjacencies up') -luCommand('r3','vtysh -c "show bgp vrf all summary"',' 00:0.* 00:0','pass','All adjacencies up') -luCommand('r4','vtysh -c "show bgp vrf all summary"',' 00:0.* 00:0','pass','All adjacencies up') -luCommand('r1','ping 3.3.3.3 -c 1',' 0. packet loss','wait','PE->PE3 (loopback) ping') -luCommand('r1','ping 4.4.4.4 -c 1',' 0. packet loss','wait','PE->PE4 (loopback) ping') -luCommand('r4','ping 3.3.3.3 -c 1',' 0. packet loss','wait','PE->PE3 (loopback) ping') + +luCommand("ce1", "ping 192.168.1.1 -c 1", " 0. packet loss", "pass", "CE->PE ping") +luCommand("ce2", "ping 192.168.1.1 -c 1", " 0. packet loss", "pass", "CE->PE ping") +luCommand("ce3", "ping 192.168.1.1 -c 1", " 0. packet loss", "pass", "CE->PE ping") +luCommand("ce1", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180) +luCommand("ce2", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180) +luCommand("ce3", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180) +luCommand( + "r1", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 +) +luCommand( + "r3", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 +) +luCommand( + "r4", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 +) +luCommand( + "r2", + 'vtysh -c "show bgp summary"', + " 00:0.* 00:0.* 00:0", + "wait", + "Core adjacencies up", + 180, +) +luCommand( + "r1", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Core adjacencies up", 180 +) +luCommand( + "r3", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Core adjacencies up", 180 +) +luCommand( + "r4", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Core adjacencies up", 180 +) +luCommand( + "r1", + 'vtysh -c "show bgp vrf all summary"', + " 00:0.* 00:0", + "pass", + "All adjacencies up", +) +luCommand( + "r3", + 'vtysh -c "show bgp vrf all summary"', + " 00:0.* 00:0", + "pass", + "All adjacencies up", +) +luCommand( + "r4", + 'vtysh -c "show bgp vrf all summary"', + " 00:0.* 00:0", + "pass", + "All adjacencies up", +) +luCommand( + "r1", "ping 3.3.3.3 -c 1", " 0. packet loss", "wait", "PE->PE3 (loopback) ping" +) +luCommand( + "r1", "ping 4.4.4.4 -c 1", " 0. packet loss", "wait", "PE->PE4 (loopback) ping" +) +luCommand( + "r4", "ping 3.3.3.3 -c 1", " 0. packet loss", "wait", "PE->PE3 (loopback) ping" +) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/check_routes.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/check_routes.py index 492be9e4da..96b4978261 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/check_routes.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/check_routes.py @@ -1,17 +1,55 @@ from lutil import luCommand -luCommand('ce1','vtysh -c "show bgp ipv4 uni"','7 routes and 7','wait','Local and remote routes') -luCommand('ce2','vtysh -c "show bgp ipv4 uni"','7 routes and 9','wait','Local and remote routes') -luCommand('ce3','vtysh -c "show bgp ipv4 uni"','7 routes and 7','wait','Local and remote routes') -luCommand('r1','vtysh -c "show bgp ipv4 uni"','7 routes and 9','pass','Unicast SAFI') -luCommand('r2','vtysh -c "show bgp ipv4 uni"','No BGP prefixes displayed','pass','Unicast SAFI') -luCommand('r3','vtysh -c "show bgp ipv4 uni"','7 routes and 9','pass','Unicast SAFI') -luCommand('r4','vtysh -c "show bgp ipv4 uni"','7 routes and 9','pass','Unicast SAFI') -have2ndImports = luCommand('r3','vtysh -c "show vnc registrations imported"','2 out of 2 imported','none','Imported Registrations',2) + +luCommand( + "ce1", + 'vtysh -c "show bgp ipv4 uni"', + "7 routes and 7", + "wait", + "Local and remote routes", +) +luCommand( + "ce2", + 'vtysh -c "show bgp ipv4 uni"', + "7 routes and 9", + "wait", + "Local and remote routes", +) +luCommand( + "ce3", + 'vtysh -c "show bgp ipv4 uni"', + "7 routes and 7", + "wait", + "Local and remote routes", +) +luCommand( + "r1", 'vtysh -c "show bgp ipv4 uni"', "7 routes and 9", "pass", "Unicast SAFI" +) +luCommand( + "r2", + 'vtysh -c "show bgp ipv4 uni"', + "No BGP prefixes displayed", + "pass", + "Unicast SAFI", +) +luCommand( + "r3", 'vtysh -c "show bgp ipv4 uni"', "7 routes and 9", "pass", "Unicast SAFI" +) +luCommand( + "r4", 'vtysh -c "show bgp ipv4 uni"', "7 routes and 9", "pass", "Unicast SAFI" +) +have2ndImports = luCommand( + "r3", + 'vtysh -c "show vnc registrations imported"', + "2 out of 2 imported", + "none", + "Imported Registrations", + 2, +) if have2ndImports: - num = '9 routes and 9' + num = "9 routes and 9" else: - num = '7 routes and 7' -luCommand('r1','vtysh -c "show bgp ipv4 vpn"',num,'pass','VPN SAFI') -luCommand('r2','vtysh -c "show bgp ipv4 vpn"',num,'pass','VPN SAFI') -luCommand('r3','vtysh -c "show bgp ipv4 vpn"',num,'pass','VPN SAFI') -luCommand('r4','vtysh -c "show bgp ipv4 vpn"',num,'pass','VPN SAFI') + num = "7 routes and 7" +luCommand("r1", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI") +luCommand("r2", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI") +luCommand("r3", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI") +luCommand("r4", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI") diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/cleanup_all.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/cleanup_all.py index 3a2f037833..9f21d99913 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/cleanup_all.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/cleanup_all.py @@ -1,17 +1,114 @@ from lutil import luCommand -luCommand('r1','vtysh -c "clear vrf cust1 prefix 99.0.0.1/32"','.','none','Cleared VRF route') -luCommand('r3','vtysh -c "clear vrf cust1 prefix 99.0.0.2/32"','.','none','Cleared VRF route') -luCommand('r4','vtysh -c "clear vrf cust1 prefix 99.0.0.3/32"','.','none','Cleared VRF route') -luCommand('r1','vtysh -c "show vnc registrations local"','99.0.0.1','fail','Local Registration cleared') -luCommand('r3','vtysh -c "show vnc registrations local"','99.0.0.2','fail','Local Registration cleared') -luCommand('r4','vtysh -c "show vnc registrations local"','99.0.0.3','fail','Local Registration cleared') -luCommand('r1','vtysh -c "show bgp ipv4 uni"','2 routes and 2','wait','Unicast SAFI updated') -luCommand('r2','vtysh -c "show bgp ipv4 uni"','No BGP prefixes displayed','pass','Unicast SAFI') -luCommand('r3','vtysh -c "show bgp ipv4 uni"','2 routes and 2','wait','Unicast SAFI updated') -luCommand('r4','vtysh -c "show bgp ipv4 uni"','2 routes and 2','wait','Unicast SAFI updated') -luCommand('ce1','vtysh -c "show bgp ipv4 uni"','2 routes and 2','wait','Local and remote routes') -luCommand('ce2','vtysh -c "show bgp ipv4 uni"','2 routes and 2','wait','Local and remote routes') -luCommand('ce3','vtysh -c "show bgp ipv4 uni"','2 routes and 2','wait','Local and remote routes') -luCommand('r1','vtysh -c "show vnc registrations remote"','Prefix ','fail','Remote Registration cleared') -luCommand('r3','vtysh -c "show vnc registrations remote"','Prefix ','fail','Remote Registration cleared') -luCommand('r4','vtysh -c "show vnc registrations remote"','Prefix ','fail','Remote Registration cleared') + +luCommand( + "r1", + 'vtysh -c "clear vrf cust1 prefix 99.0.0.1/32"', + ".", + "none", + "Cleared VRF route", +) +luCommand( + "r3", + 'vtysh -c "clear vrf cust1 prefix 99.0.0.2/32"', + ".", + "none", + "Cleared VRF route", +) +luCommand( + "r4", + 'vtysh -c "clear vrf cust1 prefix 99.0.0.3/32"', + ".", + "none", + "Cleared VRF route", +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations local"', + "99.0.0.1", + "fail", + "Local Registration cleared", +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations local"', + "99.0.0.2", + "fail", + "Local Registration cleared", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations local"', + "99.0.0.3", + "fail", + "Local Registration cleared", +) +luCommand( + "r1", + 'vtysh -c "show bgp ipv4 uni"', + "2 routes and 2", + "wait", + "Unicast SAFI updated", +) +luCommand( + "r2", + 'vtysh -c "show bgp ipv4 uni"', + "No BGP prefixes displayed", + "pass", + "Unicast SAFI", +) +luCommand( + "r3", + 'vtysh -c "show bgp ipv4 uni"', + "2 routes and 2", + "wait", + "Unicast SAFI updated", +) +luCommand( + "r4", + 'vtysh -c "show bgp ipv4 uni"', + "2 routes and 2", + "wait", + "Unicast SAFI updated", +) +luCommand( + "ce1", + 'vtysh -c "show bgp ipv4 uni"', + "2 routes and 2", + "wait", + "Local and remote routes", +) +luCommand( + "ce2", + 'vtysh -c "show bgp ipv4 uni"', + "2 routes and 2", + "wait", + "Local and remote routes", +) +luCommand( + "ce3", + 'vtysh -c "show bgp ipv4 uni"', + "2 routes and 2", + "wait", + "Local and remote routes", +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations remote"', + "Prefix ", + "fail", + "Remote Registration cleared", +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations remote"', + "Prefix ", + "fail", + "Remote Registration cleared", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations remote"', + "Prefix ", + "fail", + "Remote Registration cleared", +) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/test_bgp_l3vpn_to_bgp_direct.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/test_bgp_l3vpn_to_bgp_direct.py index f710c84c37..d226904102 100755 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/test_bgp_l3vpn_to_bgp_direct.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/test_bgp_l3vpn_to_bgp_direct.py @@ -25,46 +25,51 @@ import os import sys import pytest -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')) +sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from lib.ltemplate import * + def test_adjacencies(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'3.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' - ltemplateTest('scripts/adjacencies.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('3.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' + ltemplateTest("scripts/adjacencies.py", False, CliOnFail, CheckFunc) + def test_add_routes(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'3.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' - ltemplateTest('scripts/add_routes.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('3.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' + ltemplateTest("scripts/add_routes.py", False, CliOnFail, CheckFunc) + def test_check_routes(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'3.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' - ltemplateTest('scripts/check_routes.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('3.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' + ltemplateTest("scripts/check_routes.py", False, CliOnFail, CheckFunc) + def test_cleanup_all(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'3.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' - ltemplateTest('scripts/cleanup_all.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('3.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' + ltemplateTest("scripts/cleanup_all.py", False, CliOnFail, CheckFunc) -if __name__ == '__main__': + +if __name__ == "__main__": retval = pytest.main(["-s"]) sys.exit(retval) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py index e62d139a0c..fb919f02d0 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py @@ -89,12 +89,15 @@ from lib.ltemplate import ltemplateRtrCmd from mininet.topo import Topo import shutil + CWD = os.path.dirname(os.path.realpath(__file__)) # test name based on directory TEST = os.path.basename(CWD) + class ThisTestTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) @@ -103,125 +106,148 @@ class ThisTestTopo(Topo): # between routers, switches and hosts. # # Create P/PE routers - #check for mpls - tgen.add_router('r1') + # check for mpls + tgen.add_router("r1") if tgen.hasmpls != True: - logger.info('MPLS not available, tests will be skipped') + logger.info("MPLS not available, tests will be skipped") return mach = platform.machine() krel = platform.release() - if mach[:1] == 'a' and topotest.version_cmp(krel, '4.11') < 0: - logger.info('Need Kernel version 4.11 to run on arm processor') + if mach[:1] == "a" and topotest.version_cmp(krel, "4.11") < 0: + logger.info("Need Kernel version 4.11 to run on arm processor") return for routern in range(2, 5): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) # Create CE routers for routern in range(1, 5): - tgen.add_router('ce{}'.format(routern)) + tgen.add_router("ce{}".format(routern)) - #CE/PE links - tgen.add_link(tgen.gears['ce1'], tgen.gears['r1'], 'ce1-eth0', 'r1-eth4') - tgen.add_link(tgen.gears['ce2'], tgen.gears['r3'], 'ce2-eth0', 'r3-eth4') - tgen.add_link(tgen.gears['ce3'], tgen.gears['r4'], 'ce3-eth0', 'r4-eth4') - tgen.add_link(tgen.gears['ce4'], tgen.gears['r4'], 'ce4-eth0', 'r4-eth5') + # CE/PE links + tgen.add_link(tgen.gears["ce1"], tgen.gears["r1"], "ce1-eth0", "r1-eth4") + tgen.add_link(tgen.gears["ce2"], tgen.gears["r3"], "ce2-eth0", "r3-eth4") + tgen.add_link(tgen.gears["ce3"], tgen.gears["r4"], "ce3-eth0", "r4-eth4") + tgen.add_link(tgen.gears["ce4"], tgen.gears["r4"], "ce4-eth0", "r4-eth5") # Create a switch with just one router connected to it to simulate a # empty network. switch = {} - switch[0] = tgen.add_switch('sw0') - switch[0].add_link(tgen.gears['r1'], nodeif='r1-eth0') - switch[0].add_link(tgen.gears['r2'], nodeif='r2-eth0') + switch[0] = tgen.add_switch("sw0") + switch[0].add_link(tgen.gears["r1"], nodeif="r1-eth0") + switch[0].add_link(tgen.gears["r2"], nodeif="r2-eth0") - switch[1] = tgen.add_switch('sw1') - switch[1].add_link(tgen.gears['r2'], nodeif='r2-eth1') - switch[1].add_link(tgen.gears['r3'], nodeif='r3-eth0') - switch[1].add_link(tgen.gears['r4'], nodeif='r4-eth0') + switch[1] = tgen.add_switch("sw1") + switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth1") + switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth0") + switch[1].add_link(tgen.gears["r4"], nodeif="r4-eth0") + + switch[1] = tgen.add_switch("sw2") + switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth2") + switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth1") - switch[1] = tgen.add_switch('sw2') - switch[1].add_link(tgen.gears['r2'], nodeif='r2-eth2') - switch[1].add_link(tgen.gears['r3'], nodeif='r3-eth1') l3mdev_accept = 0 + def ltemplatePreRouterStartHook(): global l3mdev_accept cc = ltemplateRtrCmd() krel = platform.release() tgen = get_topogen() - logger.info('pre router-start hook, kernel=' + krel) + logger.info("pre router-start hook, kernel=" + krel) - if topotest.version_cmp(krel, '4.15') >= 0 and \ - topotest.version_cmp(krel, '4.18') <= 0: + if ( + topotest.version_cmp(krel, "4.15") >= 0 + and topotest.version_cmp(krel, "4.18") <= 0 + ): l3mdev_accept = 1 - if topotest.version_cmp(krel, '5.0') >= 0: + if topotest.version_cmp(krel, "5.0") >= 0: l3mdev_accept = 1 - logger.info('setting net.ipv4.tcp_l3mdev_accept={}'.format(l3mdev_accept)) - #check for mpls + logger.info("setting net.ipv4.tcp_l3mdev_accept={}".format(l3mdev_accept)) + # check for mpls if tgen.hasmpls != True: - logger.info('MPLS not available, skipping setup') + logger.info("MPLS not available, skipping setup") return False - #check for normal init + # check for normal init if len(tgen.net) == 1: - logger.info('Topology not configured, skipping setup') + logger.info("Topology not configured, skipping setup") return False - #trace errors/unexpected output + # trace errors/unexpected output cc.resetCounts() - #configure r2 mpls interfaces - intfs = ['lo', 'r2-eth0', 'r2-eth1', 'r2-eth2'] + # configure r2 mpls interfaces + intfs = ["lo", "r2-eth0", "r2-eth1", "r2-eth2"] for intf in intfs: - cc.doCmd(tgen, 'r2', 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf)) + cc.doCmd(tgen, "r2", "echo 1 > /proc/sys/net/mpls/conf/{}/input".format(intf)) - #configure cust1 VRFs & MPLS - rtrs = ['r1', 'r3', 'r4'] - cmds = ['ip link add {0}-cust1 type vrf table 10', - 'ip ru add oif {0}-cust1 table 10', - 'ip ru add iif {0}-cust1 table 10', - 'ip link set dev {0}-cust1 up', - 'sysctl -w net.ipv4.tcp_l3mdev_accept={}'.format(l3mdev_accept)] + # configure cust1 VRFs & MPLS + rtrs = ["r1", "r3", "r4"] + cmds = [ + "ip link add {0}-cust1 type vrf table 10", + "ip ru add oif {0}-cust1 table 10", + "ip ru add iif {0}-cust1 table 10", + "ip link set dev {0}-cust1 up", + "sysctl -w net.ipv4.tcp_l3mdev_accept={}".format(l3mdev_accept), + ] for rtr in rtrs: router = tgen.gears[rtr] for cmd in cmds: cc.doCmd(tgen, rtr, cmd.format(rtr)) - cc.doCmd(tgen, rtr, 'ip link set dev {0}-eth4 master {0}-cust1'.format(rtr)) - intfs = [rtr+'-cust1', 'lo', rtr+'-eth0', rtr+'-eth4'] + cc.doCmd(tgen, rtr, "ip link set dev {0}-eth4 master {0}-cust1".format(rtr)) + intfs = [rtr + "-cust1", "lo", rtr + "-eth0", rtr + "-eth4"] for intf in intfs: - cc.doCmd(tgen, rtr, 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf)) - logger.info('setup {0} vrf {0}-cust1, {0}-eth4. enabled mpls input.'.format(rtr)) - #configure cust2 VRFs & MPLS - rtrs = ['r4'] - cmds = ['ip link add {0}-cust2 type vrf table 20', - 'ip ru add oif {0}-cust2 table 20', - 'ip ru add iif {0}-cust2 table 20', - 'ip link set dev {0}-cust2 up'] + cc.doCmd( + tgen, rtr, "echo 1 > /proc/sys/net/mpls/conf/{}/input".format(intf) + ) + logger.info( + "setup {0} vrf {0}-cust1, {0}-eth4. enabled mpls input.".format(rtr) + ) + # configure cust2 VRFs & MPLS + rtrs = ["r4"] + cmds = [ + "ip link add {0}-cust2 type vrf table 20", + "ip ru add oif {0}-cust2 table 20", + "ip ru add iif {0}-cust2 table 20", + "ip link set dev {0}-cust2 up", + ] for rtr in rtrs: for cmd in cmds: cc.doCmd(tgen, rtr, cmd.format(rtr)) - cc.doCmd(tgen, rtr, 'ip link set dev {0}-eth5 master {0}-cust2'.format(rtr)) - intfs = [rtr+'-cust2', rtr+'-eth5'] + cc.doCmd(tgen, rtr, "ip link set dev {0}-eth5 master {0}-cust2".format(rtr)) + intfs = [rtr + "-cust2", rtr + "-eth5"] for intf in intfs: - cc.doCmd(tgen, rtr, 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf)) - logger.info('setup {0} vrf {0}-cust2, {0}-eth5. enabled mpls input.'.format(rtr)) - #put ce4-eth0 into a VRF (no default instance!) - rtrs = ['ce4'] - cmds = ['ip link add {0}-cust2 type vrf table 20', - 'ip ru add oif {0}-cust2 table 20', - 'ip ru add iif {0}-cust2 table 20', - 'ip link set dev {0}-cust2 up', - 'sysctl -w net.ipv4.tcp_l3mdev_accept={}'.format(l3mdev_accept)] + cc.doCmd( + tgen, rtr, "echo 1 > /proc/sys/net/mpls/conf/{}/input".format(intf) + ) + logger.info( + "setup {0} vrf {0}-cust2, {0}-eth5. enabled mpls input.".format(rtr) + ) + # put ce4-eth0 into a VRF (no default instance!) + rtrs = ["ce4"] + cmds = [ + "ip link add {0}-cust2 type vrf table 20", + "ip ru add oif {0}-cust2 table 20", + "ip ru add iif {0}-cust2 table 20", + "ip link set dev {0}-cust2 up", + "sysctl -w net.ipv4.tcp_l3mdev_accept={}".format(l3mdev_accept), + ] for rtr in rtrs: for cmd in cmds: cc.doCmd(tgen, rtr, cmd.format(rtr)) - cc.doCmd(tgen, rtr, 'ip link set dev {0}-eth0 master {0}-cust2'.format(rtr)) + cc.doCmd(tgen, rtr, "ip link set dev {0}-eth0 master {0}-cust2".format(rtr)) if cc.getOutput() != 4: InitSuccess = False - logger.info('Unexpected output seen ({} times, tests will be skipped'.format(cc.getOutput())) + logger.info( + "Unexpected output seen ({} times, tests will be skipped".format( + cc.getOutput() + ) + ) else: InitSuccess = True - logger.info('VRF config successful!') + logger.info("VRF config successful!") return InitSuccess + def ltemplatePostRouterStartHook(): - logger.info('post router-start hook') + logger.info("post router-start hook") return True diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/add_routes.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/add_routes.py index 19b73d2057..5c7427763d 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/add_routes.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/add_routes.py @@ -1,13 +1,59 @@ from lutil import luCommand -luCommand('r1','vtysh -c "add vrf r1-cust1 prefix 99.0.0.1/32"','.','none','IP Address') -luCommand('r3','vtysh -c "add vrf r3-cust1 prefix 99.0.0.2/32"','.','none','IP Address') -luCommand('r4','vtysh -c "add vrf r4-cust1 prefix 99.0.0.3/32"','.','none','IP Address') -luCommand('r1','vtysh -c "show vnc registrations local"','99.0.0.1','pass','Local Registration') -luCommand('r3','vtysh -c "show vnc registrations local"','99.0.0.2','pass','Local Registration') -luCommand('r4','vtysh -c "show vnc registrations local"','99.0.0.3','pass','Local Registration') -luCommand('r1','vtysh -c "show vnc registrations remote"','4 out of 4','wait','Remote Registration', 10) -luCommand('r3','vtysh -c "show vnc registrations remote"','6 out of 6','wait','Remote Registration', 10) -luCommand('r4','vtysh -c "show vnc registrations remote"','4 out of 4','wait','Remote Registration', 10) -luCommand('r1','vtysh -c "show vnc registrations"','.','none') -luCommand('r3','vtysh -c "show vnc registrations"','.','none') -luCommand('r4','vtysh -c "show vnc registrations"','.','none') + +luCommand( + "r1", 'vtysh -c "add vrf r1-cust1 prefix 99.0.0.1/32"', ".", "none", "IP Address" +) +luCommand( + "r3", 'vtysh -c "add vrf r3-cust1 prefix 99.0.0.2/32"', ".", "none", "IP Address" +) +luCommand( + "r4", 'vtysh -c "add vrf r4-cust1 prefix 99.0.0.3/32"', ".", "none", "IP Address" +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations local"', + "99.0.0.1", + "pass", + "Local Registration", +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations local"', + "99.0.0.2", + "pass", + "Local Registration", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations local"', + "99.0.0.3", + "pass", + "Local Registration", +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations remote"', + "4 out of 4", + "wait", + "Remote Registration", + 10, +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations remote"', + "6 out of 6", + "wait", + "Remote Registration", + 10, +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations remote"', + "4 out of 4", + "wait", + "Remote Registration", + 10, +) +luCommand("r1", 'vtysh -c "show vnc registrations"', ".", "none") +luCommand("r3", 'vtysh -c "show vnc registrations"', ".", "none") +luCommand("r4", 'vtysh -c "show vnc registrations"', ".", "none") diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/adjacencies.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/adjacencies.py index c2b0cf9e7a..53cf353fa0 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/adjacencies.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/adjacencies.py @@ -1,18 +1,64 @@ from lutil import luCommand -luCommand('ce1','vtysh -c "show bgp summary"',' 00:0','wait','Adjacencies up',180) -luCommand('ce2','vtysh -c "show bgp summary"',' 00:0','wait','Adjacencies up',180) -luCommand('ce3','vtysh -c "show bgp summary"',' 00:0','wait','Adjacencies up',180) -luCommand('ce4','vtysh -c "show bgp vrf all summary"',' 00:0','wait','Adjacencies up',180) -luCommand('r1','ping 2.2.2.2 -c 1',' 0. packet loss','wait','PE->P2 (loopback) ping',60) -luCommand('r3','ping 2.2.2.2 -c 1',' 0. packet loss','wait','PE->P2 (loopback) ping',60) -luCommand('r4','ping 2.2.2.2 -c 1',' 0. packet loss','wait','PE->P2 (loopback) ping',60) -luCommand('r2','vtysh -c "show bgp summary"',' 00:0.* 00:0.* 00:0','wait','Core adjacencies up',180) -luCommand('r1','vtysh -c "show bgp summary"',' 00:0','wait','Core adjacencies up', 180) -luCommand('r3','vtysh -c "show bgp summary"',' 00:0','wait','Core adjacencies up', 180) -luCommand('r4','vtysh -c "show bgp summary"',' 00:0','wait','Core adjacencies up', 180) -luCommand('r1','vtysh -c "show bgp vrf all summary"',' 00:0.* 00:0','pass','All adjacencies up') -luCommand('r3','vtysh -c "show bgp vrf all summary"',' 00:0.* 00:0','pass','All adjacencies up') -luCommand('r4','vtysh -c "show bgp vrf all summary"',' 00:0.* 00:0.* 00:0','pass','All adjacencies up') -luCommand('r1','ping 3.3.3.3 -c 1',' 0. packet loss','wait','PE->PE3 (loopback) ping') -luCommand('r1','ping 4.4.4.4 -c 1',' 0. packet loss','wait','PE->PE4 (loopback) ping') -luCommand('r4','ping 3.3.3.3 -c 1',' 0. packet loss','wait','PE->PE3 (loopback) ping') + +luCommand("ce1", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180) +luCommand("ce2", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180) +luCommand("ce3", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180) +luCommand( + "ce4", 'vtysh -c "show bgp vrf all summary"', " 00:0", "wait", "Adjacencies up", 180 +) +luCommand( + "r1", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 +) +luCommand( + "r3", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 +) +luCommand( + "r4", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 +) +luCommand( + "r2", + 'vtysh -c "show bgp summary"', + " 00:0.* 00:0.* 00:0", + "wait", + "Core adjacencies up", + 180, +) +luCommand( + "r1", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Core adjacencies up", 180 +) +luCommand( + "r3", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Core adjacencies up", 180 +) +luCommand( + "r4", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Core adjacencies up", 180 +) +luCommand( + "r1", + 'vtysh -c "show bgp vrf all summary"', + " 00:0.* 00:0", + "pass", + "All adjacencies up", +) +luCommand( + "r3", + 'vtysh -c "show bgp vrf all summary"', + " 00:0.* 00:0", + "pass", + "All adjacencies up", +) +luCommand( + "r4", + 'vtysh -c "show bgp vrf all summary"', + " 00:0.* 00:0.* 00:0", + "pass", + "All adjacencies up", +) +luCommand( + "r1", "ping 3.3.3.3 -c 1", " 0. packet loss", "wait", "PE->PE3 (loopback) ping" +) +luCommand( + "r1", "ping 4.4.4.4 -c 1", " 0. packet loss", "wait", "PE->PE4 (loopback) ping" +) +luCommand( + "r4", "ping 3.3.3.3 -c 1", " 0. packet loss", "wait", "PE->PE3 (loopback) ping" +) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_mpls.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_mpls.py index 9827a9e2c1..20113b1058 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_mpls.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_mpls.py @@ -1,47 +1,83 @@ from lutil import luCommand, luLast from lib import topotest -ret = luCommand('r2', 'ip -M route show', - '\d*(?= via inet 10.0.2.4 dev r2-eth1)','wait','See mpls route to r4') +ret = luCommand( + "r2", + "ip -M route show", + "\d*(?= via inet 10.0.2.4 dev r2-eth1)", + "wait", + "See mpls route to r4", +) found = luLast() if ret != False and found != None: label4r4 = found.group(0) - luCommand('r2', 'ip -M route show', - '.', 'pass', - 'See %s as label to r4' % label4r4) - ret = luCommand('r2', 'ip -M route show', - '\d*(?= via inet 10.0.1.1 dev r2-eth0)', 'wait', - 'See mpls route to r1') + luCommand("r2", "ip -M route show", ".", "pass", "See %s as label to r4" % label4r4) + ret = luCommand( + "r2", + "ip -M route show", + "\d*(?= via inet 10.0.1.1 dev r2-eth0)", + "wait", + "See mpls route to r1", + ) found = luLast() if ret != False and found != None: label4r1 = found.group(0) - luCommand('r2', 'ip -M route show', - '.', 'pass', 'See %s as label to r1' % label4r1) + luCommand("r2", "ip -M route show", ".", "pass", "See %s as label to r1" % label4r1) - luCommand('r1', 'ip route show vrf r1-cust1', - '99.0.0.4', 'pass', 'VRF->MPLS PHP route installed') - luCommand('r4', 'ip route show vrf r4-cust2', - '99.0.0.1','pass', 'VRF->MPLS PHP route installed') + luCommand( + "r1", + "ip route show vrf r1-cust1", + "99.0.0.4", + "pass", + "VRF->MPLS PHP route installed", + ) + luCommand( + "r4", + "ip route show vrf r4-cust2", + "99.0.0.1", + "pass", + "VRF->MPLS PHP route installed", + ) - luCommand('r1', 'ip -M route show', '101', 'pass', 'MPLS->VRF route installed') - luCommand('r4', 'ip -M route show', '1041', 'pass', 'MPLS->VRF1 route installed') - luCommand('r4', 'ip -M route show', '1042', 'pass', 'MPLS->VRF2 route installed') + luCommand("r1", "ip -M route show", "101", "pass", "MPLS->VRF route installed") + luCommand("r4", "ip -M route show", "1041", "pass", "MPLS->VRF1 route installed") + luCommand("r4", "ip -M route show", "1042", "pass", "MPLS->VRF2 route installed") - luCommand('ce1', 'ping 99.0.0.4 -I 99.0.0.1 -c 1', - ' 0. packet loss','wait','CE->CE (loopback) ping - l3vpn+zebra case') - #skip due to VRF weirdness - #luCommand('ce4', 'ping 99.0.0.1 -I 99.0.0.4 -c 1', + luCommand( + "ce1", + "ping 99.0.0.4 -I 99.0.0.1 -c 1", + " 0. packet loss", + "wait", + "CE->CE (loopback) ping - l3vpn+zebra case", + ) + # skip due to VRF weirdness + # luCommand('ce4', 'ping 99.0.0.1 -I 99.0.0.4 -c 1', # ' 0. packet loss','wait','CE->CE (loopback) ping - l3vpn+zebra case') - luCommand('ce1', 'ping 99.0.0.4 -I 99.0.0.1 -c 1', - ' 0. packet loss','wait','CE->CE (loopback) ping') - #luCommand('ce4', 'ping 99.0.0.1 -I 99.0.0.4 -c 1', + luCommand( + "ce1", + "ping 99.0.0.4 -I 99.0.0.1 -c 1", + " 0. packet loss", + "wait", + "CE->CE (loopback) ping", + ) + # luCommand('ce4', 'ping 99.0.0.1 -I 99.0.0.4 -c 1', # ' 0. packet loss','wait','CE->CE (loopback) ping') - luCommand('r3', 'ip -M route show', '103', 'pass', 'MPLS->VRF route installed') - luCommand('ce2', 'ping 99.0.0.3 -I 99.0.0.2 -c 1', - ' 0. packet loss','wait','CE2->CE3 (loopback) ping') - luCommand('ce3', 'ping 99.0.0.4 -I 99.0.0.3 -c 1', - ' 0. packet loss','wait','CE3->CE4 (loopback) ping') + luCommand("r3", "ip -M route show", "103", "pass", "MPLS->VRF route installed") + luCommand( + "ce2", + "ping 99.0.0.3 -I 99.0.0.2 -c 1", + " 0. packet loss", + "wait", + "CE2->CE3 (loopback) ping", + ) + luCommand( + "ce3", + "ping 99.0.0.4 -I 99.0.0.3 -c 1", + " 0. packet loss", + "wait", + "CE3->CE4 (loopback) ping", + ) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_vrf.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_vrf.py index 547a5949a3..b552ea0406 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_vrf.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_vrf.py @@ -1,27 +1,93 @@ from lutil import luCommand from customize import l3mdev_accept -l3mdev_rtrs = ['r1', 'r3', 'r4', 'ce4'] +l3mdev_rtrs = ["r1", "r3", "r4", "ce4"] for rtr in l3mdev_rtrs: - luCommand(rtr,'sysctl net.ipv4.tcp_l3mdev_accept',' = \d*','none','') + luCommand(rtr, "sysctl net.ipv4.tcp_l3mdev_accept", " = \d*", "none", "") found = luLast() - luCommand(rtr,'ss -naep',':179','pass','IPv4:bgp, l3mdev{}'.format(found.group(0))) - luCommand(rtr,'ss -naep',':.*:179','pass','IPv6:bgp') - luCommand(rtr,'sysctl net.ipv4.tcp_l3mdev_accept',' = {}'.format(l3mdev_accept),'pass','l3mdev matches expected (real/expected{}/{})'.format(found.group(0),l3mdev_accept)) + luCommand( + rtr, "ss -naep", ":179", "pass", "IPv4:bgp, l3mdev{}".format(found.group(0)) + ) + luCommand(rtr, "ss -naep", ":.*:179", "pass", "IPv6:bgp") + luCommand( + rtr, + "sysctl net.ipv4.tcp_l3mdev_accept", + " = {}".format(l3mdev_accept), + "pass", + "l3mdev matches expected (real/expected{}/{})".format( + found.group(0), l3mdev_accept + ), + ) -rtrs = ['r1', 'r3', 'r4'] +rtrs = ["r1", "r3", "r4"] for rtr in rtrs: - luCommand(rtr, 'ip link show type vrf {}-cust1'.format(rtr),'cust1: .*UP','pass','VRF cust1 intf up') - luCommand(rtr, 'ip add show vrf {}-cust1'.format(rtr),'r..eth4.*UP','pass','VRF cust1 IP intf up') - luCommand(rtr, 'ip add show vrf {}-cust1'.format(rtr),'192.168','pass','VRF cust1 IP config') - luCommand(rtr, 'ip route show vrf {}-cust1'.format(rtr),'192.168...0/24 dev r.-eth','pass','VRF cust1 interface route') -luCommand('r4', 'ip link show type vrf r4-cust2','cust2: .*UP','pass','VRF cust2 up') -luCommand('r4', 'ip add show vrf r4-cust2','r..eth5.*UP.* 192.168','pass','VRF cust1 IP config') -luCommand(rtr, 'ip route show vrf r4-cust2'.format(rtr),'192.168...0/24 dev r.-eth','pass','VRF cust2 interface route') -rtrs = ['ce1', 'ce2', 'ce3'] + luCommand( + rtr, + "ip link show type vrf {}-cust1".format(rtr), + "cust1: .*UP", + "pass", + "VRF cust1 intf up", + ) + luCommand( + rtr, + "ip add show vrf {}-cust1".format(rtr), + "r..eth4.*UP", + "pass", + "VRF cust1 IP intf up", + ) + luCommand( + rtr, + "ip add show vrf {}-cust1".format(rtr), + "192.168", + "pass", + "VRF cust1 IP config", + ) + luCommand( + rtr, + "ip route show vrf {}-cust1".format(rtr), + "192.168...0/24 dev r.-eth", + "pass", + "VRF cust1 interface route", + ) +luCommand("r4", "ip link show type vrf r4-cust2", "cust2: .*UP", "pass", "VRF cust2 up") +luCommand( + "r4", + "ip add show vrf r4-cust2", + "r..eth5.*UP.* 192.168", + "pass", + "VRF cust1 IP config", +) +luCommand( + rtr, + "ip route show vrf r4-cust2".format(rtr), + "192.168...0/24 dev r.-eth", + "pass", + "VRF cust2 interface route", +) +rtrs = ["ce1", "ce2", "ce3"] for rtr in rtrs: - luCommand(rtr, 'ip route show','192.168...0/24 dev ce.-eth0','pass','CE interface route') - luCommand(rtr,'ping 192.168.1.1 -c 1',' 0. packet loss','wait','CE->PE ping') -luCommand('ce4', 'ip link show type vrf ce4-cust2','cust2: .*UP','pass','VRF cust2 up') -luCommand('ce4', 'ip route show vrf ce4-cust2','192.168...0/24 dev ce.-eth0','pass','CE interface route') -luCommand('ce4','ping 192.168.2.1 -c 1 -I ce4-cust2',' 0. packet loss','wait','CE4->PE4 ping') + luCommand( + rtr, + "ip route show", + "192.168...0/24 dev ce.-eth0", + "pass", + "CE interface route", + ) + luCommand(rtr, "ping 192.168.1.1 -c 1", " 0. packet loss", "wait", "CE->PE ping") +luCommand( + "ce4", "ip link show type vrf ce4-cust2", "cust2: .*UP", "pass", "VRF cust2 up" +) +luCommand( + "ce4", + "ip route show vrf ce4-cust2", + "192.168...0/24 dev ce.-eth0", + "pass", + "CE interface route", +) +luCommand( + "ce4", + "ping 192.168.2.1 -c 1 -I ce4-cust2", + " 0. packet loss", + "wait", + "CE4->PE4 ping", +) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py index e47ea5f2cd..f5a29b95c9 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py @@ -1,5 +1,5 @@ from lutil import luCommand -from bgprib import bgpribRequireVpnRoutes,bgpribRequireUnicastRoutes +from bgprib import bgpribRequireVpnRoutes, bgpribRequireUnicastRoutes ######################################################################## # CE routers: contain routes they originate @@ -12,32 +12,32 @@ from bgprib import bgpribRequireVpnRoutes,bgpribRequireUnicastRoutes # ce4 vtysh -c "show bgp ipv4 uni" want = [ - {'p':'5.1.0.0/24', 'n':'99.0.0.1'}, - {'p':'5.1.1.0/24', 'n':'99.0.0.1'}, - {'p':'99.0.0.1/32', 'n':'0.0.0.0'}, + {"p": "5.1.0.0/24", "n": "99.0.0.1"}, + {"p": "5.1.1.0/24", "n": "99.0.0.1"}, + {"p": "99.0.0.1/32", "n": "0.0.0.0"}, ] -bgpribRequireUnicastRoutes('ce1','ipv4','','Cust 1 routes in ce1',want) +bgpribRequireUnicastRoutes("ce1", "ipv4", "", "Cust 1 routes in ce1", want) want = [ - {'p':'5.1.0.0/24', 'n':'99.0.0.2'}, - {'p':'5.1.1.0/24', 'n':'99.0.0.2'}, - {'p':'99.0.0.2/32', 'n':'0.0.0.0'}, + {"p": "5.1.0.0/24", "n": "99.0.0.2"}, + {"p": "5.1.1.0/24", "n": "99.0.0.2"}, + {"p": "99.0.0.2/32", "n": "0.0.0.0"}, ] -bgpribRequireUnicastRoutes('ce2','ipv4','','Cust 2 routes in ce1',want) +bgpribRequireUnicastRoutes("ce2", "ipv4", "", "Cust 2 routes in ce1", want) want = [ - {'p':'5.1.2.0/24', 'n':'99.0.0.3'}, - {'p':'5.1.3.0/24', 'n':'99.0.0.3'}, - {'p':'99.0.0.3/32', 'n':'0.0.0.0'}, + {"p": "5.1.2.0/24", "n": "99.0.0.3"}, + {"p": "5.1.3.0/24", "n": "99.0.0.3"}, + {"p": "99.0.0.3/32", "n": "0.0.0.0"}, ] -bgpribRequireUnicastRoutes('ce3','ipv4','','Cust 3 routes in ce1',want) +bgpribRequireUnicastRoutes("ce3", "ipv4", "", "Cust 3 routes in ce1", want) want = [ - {'p':'5.4.2.0/24', 'n':'99.0.0.4'}, - {'p':'5.4.3.0/24', 'n':'99.0.0.4'}, - {'p':'99.0.0.4/32', 'n':'0.0.0.0'}, + {"p": "5.4.2.0/24", "n": "99.0.0.4"}, + {"p": "5.4.3.0/24", "n": "99.0.0.4"}, + {"p": "99.0.0.4/32", "n": "0.0.0.0"}, ] -bgpribRequireUnicastRoutes('ce4','ipv4','ce4-cust2','Cust 4 routes in ce1',want) +bgpribRequireUnicastRoutes("ce4", "ipv4", "ce4-cust2", "Cust 4 routes in ce1", want) ######################################################################## @@ -47,116 +47,169 @@ bgpribRequireUnicastRoutes('ce4','ipv4','ce4-cust2','Cust 4 routes in ce1',want) # r1 vtysh -c "show bgp vrf r1-cust1 ipv4" # want_r1_cust1_routes = [ - {'p':'5.1.0.0/24', 'n':'99.0.0.1'}, - {'p':'5.1.1.0/24', 'n':'99.0.0.1'}, - {'p':'99.0.0.1/32', 'n':'192.168.1.2'}, + {"p": "5.1.0.0/24", "n": "99.0.0.1"}, + {"p": "5.1.1.0/24", "n": "99.0.0.1"}, + {"p": "99.0.0.1/32", "n": "192.168.1.2"}, ] -bgpribRequireUnicastRoutes('r1','ipv4','r1-cust1','Customer 1 routes in r1 vrf',want_r1_cust1_routes) +bgpribRequireUnicastRoutes( + "r1", "ipv4", "r1-cust1", "Customer 1 routes in r1 vrf", want_r1_cust1_routes +) want_r3_cust1_routes = [ - {'p':'5.1.0.0/24', 'n':'99.0.0.2'}, - {'p':'5.1.1.0/24', 'n':'99.0.0.2'}, - {'p':'99.0.0.2/32', 'n':'192.168.1.2'}, + {"p": "5.1.0.0/24", "n": "99.0.0.2"}, + {"p": "5.1.1.0/24", "n": "99.0.0.2"}, + {"p": "99.0.0.2/32", "n": "192.168.1.2"}, ] -bgpribRequireUnicastRoutes('r3','ipv4','r3-cust1','Customer 1 routes in r3 vrf',want_r3_cust1_routes) +bgpribRequireUnicastRoutes( + "r3", "ipv4", "r3-cust1", "Customer 1 routes in r3 vrf", want_r3_cust1_routes +) want_r4_cust1_routes = [ - {'p':'5.1.2.0/24', 'n':'99.0.0.3'}, - {'p':'5.1.3.0/24', 'n':'99.0.0.3'}, - {'p':'99.0.0.3/32', 'n':'192.168.1.2'}, + {"p": "5.1.2.0/24", "n": "99.0.0.3"}, + {"p": "5.1.3.0/24", "n": "99.0.0.3"}, + {"p": "99.0.0.3/32", "n": "192.168.1.2"}, ] -bgpribRequireUnicastRoutes('r4','ipv4','r4-cust1','Customer 1 routes in r4 vrf',want_r4_cust1_routes) +bgpribRequireUnicastRoutes( + "r4", "ipv4", "r4-cust1", "Customer 1 routes in r4 vrf", want_r4_cust1_routes +) want_r4_cust2_routes = [ - {'p':'5.4.2.0/24', 'n':'99.0.0.4'}, - {'p':'5.4.3.0/24', 'n':'99.0.0.4'}, - {'p':'99.0.0.4/32', 'n':'192.168.2.2'}, + {"p": "5.4.2.0/24", "n": "99.0.0.4"}, + {"p": "5.4.3.0/24", "n": "99.0.0.4"}, + {"p": "99.0.0.4/32", "n": "192.168.2.2"}, ] -bgpribRequireUnicastRoutes('r4','ipv4','r4-cust2','Customer 2 routes in r4 vrf',want_r4_cust2_routes) +bgpribRequireUnicastRoutes( + "r4", "ipv4", "r4-cust2", "Customer 2 routes in r4 vrf", want_r4_cust2_routes +) ######################################################################## # PE routers: core unicast routes are empty ######################################################################## -luCommand('r1','vtysh -c "show bgp ipv4 uni"','No BGP prefixes displayed','pass','Core Unicast SAFI clean') -luCommand('r2','vtysh -c "show bgp ipv4 uni"','No BGP prefixes displayed','pass','Core Unicast SAFI clean') -luCommand('r3','vtysh -c "show bgp ipv4 uni"','No BGP prefixes displayed','pass','Core Unicast SAFI clean') -luCommand('r4','vtysh -c "show bgp ipv4 uni"','No BGP prefixes displayed','pass','Core Unicast SAFI clean') +luCommand( + "r1", + 'vtysh -c "show bgp ipv4 uni"', + "No BGP prefixes displayed", + "pass", + "Core Unicast SAFI clean", +) +luCommand( + "r2", + 'vtysh -c "show bgp ipv4 uni"', + "No BGP prefixes displayed", + "pass", + "Core Unicast SAFI clean", +) +luCommand( + "r3", + 'vtysh -c "show bgp ipv4 uni"', + "No BGP prefixes displayed", + "pass", + "Core Unicast SAFI clean", +) +luCommand( + "r4", + 'vtysh -c "show bgp ipv4 uni"', + "No BGP prefixes displayed", + "pass", + "Core Unicast SAFI clean", +) ######################################################################## # PE routers: local ce-originated routes are leaked to vpn ######################################################################## # nhzero is for the new code that sets nh of locally-leaked routes to 0 -#nhzero = 1 +# nhzero = 1 nhzero = 0 if nhzero: - luCommand('r1','vtysh -c "show bgp ipv4 vpn"', - 'Distinguisher: *10:1.*5.1.0.0/24 *0.0.0.0 .*5.1.1.0/24 *0.0.0.0 .*99.0.0.1/32 *0.0.0.0 ', - 'pass','vrf->vpn routes') - luCommand('r3','vtysh -c "show bgp ipv4 vpn"', - 'Distinguisher: *10:3.*5.1.0.0/24 *0.0.0.0 .*5.1.1.0/24 *0.0.0.0 .*99.0.0.2/32 *0.0.0.0 ', - 'pass','vrf->vpn routes') + luCommand( + "r1", + 'vtysh -c "show bgp ipv4 vpn"', + "Distinguisher: *10:1.*5.1.0.0/24 *0.0.0.0 .*5.1.1.0/24 *0.0.0.0 .*99.0.0.1/32 *0.0.0.0 ", + "pass", + "vrf->vpn routes", + ) + luCommand( + "r3", + 'vtysh -c "show bgp ipv4 vpn"', + "Distinguisher: *10:3.*5.1.0.0/24 *0.0.0.0 .*5.1.1.0/24 *0.0.0.0 .*99.0.0.2/32 *0.0.0.0 ", + "pass", + "vrf->vpn routes", + ) want = [ - {'rd':'10:41', 'p':'5.1.2.0/24', 'n':'0.0.0.0'}, - {'rd':'10:41', 'p':'5.1.3.0/24', 'n':'0.0.0.0'}, - {'rd':'10:41', 'p':'99.0.0.3/32', 'n':'0.0.0.0'}, - - {'rd':'10:42', 'p':'5.4.2.0/24', 'n':'0.0.0.0'}, - {'rd':'10:42', 'p':'5.4.3.0/24', 'n':'0.0.0.0'}, - {'rd':'10:42', 'p':'99.0.0.4/32', 'n':'0.0.0.0'}, + {"rd": "10:41", "p": "5.1.2.0/24", "n": "0.0.0.0"}, + {"rd": "10:41", "p": "5.1.3.0/24", "n": "0.0.0.0"}, + {"rd": "10:41", "p": "99.0.0.3/32", "n": "0.0.0.0"}, + {"rd": "10:42", "p": "5.4.2.0/24", "n": "0.0.0.0"}, + {"rd": "10:42", "p": "5.4.3.0/24", "n": "0.0.0.0"}, + {"rd": "10:42", "p": "99.0.0.4/32", "n": "0.0.0.0"}, ] - bgpribRequireVpnRoutes('r4','vrf->vpn routes',want) + bgpribRequireVpnRoutes("r4", "vrf->vpn routes", want) else: - luCommand('r1','vtysh -c "show bgp ipv4 vpn"', - r'Distinguisher: *10:1.*5.1.0.0/24 *99.0.0.1\b.*5.1.1.0/24 *99.0.0.1\b.*99.0.0.1/32 *192.168.1.2\b', - 'pass','vrf->vpn routes') - luCommand('r3','vtysh -c "show bgp ipv4 vpn"', - r'Distinguisher: *10:3.*5.1.0.0/24 *99.0.0.2\b.*5.1.1.0/24 *99.0.0.2\b.*99.0.0.2/32 *192.168.1.2\b', - 'pass','vrf->vpn routes') + luCommand( + "r1", + 'vtysh -c "show bgp ipv4 vpn"', + r"Distinguisher: *10:1.*5.1.0.0/24 *99.0.0.1\b.*5.1.1.0/24 *99.0.0.1\b.*99.0.0.1/32 *192.168.1.2\b", + "pass", + "vrf->vpn routes", + ) + luCommand( + "r3", + 'vtysh -c "show bgp ipv4 vpn"', + r"Distinguisher: *10:3.*5.1.0.0/24 *99.0.0.2\b.*5.1.1.0/24 *99.0.0.2\b.*99.0.0.2/32 *192.168.1.2\b", + "pass", + "vrf->vpn routes", + ) want = [ - {'rd':'10:41', 'p':'5.1.2.0/24', 'n':'99.0.0.3'}, - {'rd':'10:41', 'p':'5.1.3.0/24', 'n':'99.0.0.3'}, - {'rd':'10:41', 'p':'99.0.0.3/32', 'n':'192.168.1.2'}, - - {'rd':'10:42', 'p':'5.4.2.0/24', 'n':'99.0.0.4'}, - {'rd':'10:42', 'p':'5.4.3.0/24', 'n':'99.0.0.4'}, - {'rd':'10:42', 'p':'99.0.0.4/32', 'n':'192.168.2.2'}, + {"rd": "10:41", "p": "5.1.2.0/24", "n": "99.0.0.3"}, + {"rd": "10:41", "p": "5.1.3.0/24", "n": "99.0.0.3"}, + {"rd": "10:41", "p": "99.0.0.3/32", "n": "192.168.1.2"}, + {"rd": "10:42", "p": "5.4.2.0/24", "n": "99.0.0.4"}, + {"rd": "10:42", "p": "5.4.3.0/24", "n": "99.0.0.4"}, + {"rd": "10:42", "p": "99.0.0.4/32", "n": "192.168.2.2"}, ] - bgpribRequireVpnRoutes('r4','vrf->vpn routes',want) + bgpribRequireVpnRoutes("r4", "vrf->vpn routes", want) ######################################################################## # PE routers: exporting vrfs set MPLS vrf labels in kernel ######################################################################## -luCommand('r1','vtysh -c "show mpls table"',' 101 *BGP *r1-cust1','pass','vrf labels') -luCommand('r3','vtysh -c "show mpls table"',' 103 *BGP *r3-cust1','pass','vrf labels') -luCommand('r4','vtysh -c "show mpls table"',' 1041 *BGP *r4-cust1 .*1042 *BGP *r4-cust2','pass','vrf labels') +luCommand( + "r1", 'vtysh -c "show mpls table"', " 101 *BGP *r1-cust1", "pass", "vrf labels" +) +luCommand( + "r3", 'vtysh -c "show mpls table"', " 103 *BGP *r3-cust1", "pass", "vrf labels" +) +luCommand( + "r4", + 'vtysh -c "show mpls table"', + " 1041 *BGP *r4-cust1 .*1042 *BGP *r4-cust2", + "pass", + "vrf labels", +) ######################################################################## # Core VPN router: all customer routes ######################################################################## want_rd_routes = [ - {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1'}, - {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1'}, - {'rd':'10:1', 'p':'99.0.0.1/32', 'n':'1.1.1.1'}, - - {'rd':'10:3', 'p':'5.1.0.0/24', 'n':'3.3.3.3'}, - {'rd':'10:3', 'p':'5.1.0.0/24', 'n':'3.3.3.3'}, - {'rd':'10:3', 'p':'99.0.0.2/32', 'n':'3.3.3.3'}, - - {'rd':'10:41', 'p':'5.1.2.0/24', 'n':'4.4.4.4'}, - {'rd':'10:41', 'p':'5.1.3.0/24', 'n':'4.4.4.4'}, - {'rd':'10:41', 'p':'99.0.0.3/32', 'n':'4.4.4.4'}, - - {'rd':'10:42', 'p':'5.4.2.0/24', 'n':'4.4.4.4'}, - {'rd':'10:42', 'p':'5.4.3.0/24', 'n':'4.4.4.4'}, - {'rd':'10:42', 'p':'99.0.0.4/32', 'n':'4.4.4.4'}, + {"rd": "10:1", "p": "5.1.0.0/24", "n": "1.1.1.1"}, + {"rd": "10:1", "p": "5.1.0.0/24", "n": "1.1.1.1"}, + {"rd": "10:1", "p": "99.0.0.1/32", "n": "1.1.1.1"}, + {"rd": "10:3", "p": "5.1.0.0/24", "n": "3.3.3.3"}, + {"rd": "10:3", "p": "5.1.0.0/24", "n": "3.3.3.3"}, + {"rd": "10:3", "p": "99.0.0.2/32", "n": "3.3.3.3"}, + {"rd": "10:41", "p": "5.1.2.0/24", "n": "4.4.4.4"}, + {"rd": "10:41", "p": "5.1.3.0/24", "n": "4.4.4.4"}, + {"rd": "10:41", "p": "99.0.0.3/32", "n": "4.4.4.4"}, + {"rd": "10:42", "p": "5.4.2.0/24", "n": "4.4.4.4"}, + {"rd": "10:42", "p": "5.4.3.0/24", "n": "4.4.4.4"}, + {"rd": "10:42", "p": "99.0.0.4/32", "n": "4.4.4.4"}, ] -bgpribRequireVpnRoutes('r2','Customer routes in provider vpn core',want_rd_routes) +bgpribRequireVpnRoutes("r2", "Customer routes in provider vpn core", want_rd_routes) ######################################################################## # PE routers: VPN routes from remote customers @@ -165,46 +218,46 @@ bgpribRequireVpnRoutes('r2','Customer routes in provider vpn core',want_rd_route # r1 vtysh -c "show bgp ipv4 vpn" # want_r1_remote_vpn_routes = [ - {'rd':'10:3', 'p':'5.1.0.0/24', 'n':'3.3.3.3'}, - {'rd':'10:3', 'p':'5.1.1.0/24', 'n':'3.3.3.3'}, - {'rd':'10:3', 'p':'99.0.0.2/32', 'n':'3.3.3.3'}, - - {'rd':'10:41', 'p':'5.1.2.0/24', 'n':'4.4.4.4'}, - {'rd':'10:41', 'p':'5.1.3.0/24', 'n':'4.4.4.4'}, - {'rd':'10:41', 'p':'99.0.0.3/32', 'n':'4.4.4.4'}, - - {'rd':'10:42', 'p':'5.4.2.0/24', 'n':'4.4.4.4'}, - {'rd':'10:42', 'p':'5.4.3.0/24', 'n':'4.4.4.4'}, - {'rd':'10:42', 'p':'99.0.0.4/32', 'n':'4.4.4.4'}, + {"rd": "10:3", "p": "5.1.0.0/24", "n": "3.3.3.3"}, + {"rd": "10:3", "p": "5.1.1.0/24", "n": "3.3.3.3"}, + {"rd": "10:3", "p": "99.0.0.2/32", "n": "3.3.3.3"}, + {"rd": "10:41", "p": "5.1.2.0/24", "n": "4.4.4.4"}, + {"rd": "10:41", "p": "5.1.3.0/24", "n": "4.4.4.4"}, + {"rd": "10:41", "p": "99.0.0.3/32", "n": "4.4.4.4"}, + {"rd": "10:42", "p": "5.4.2.0/24", "n": "4.4.4.4"}, + {"rd": "10:42", "p": "5.4.3.0/24", "n": "4.4.4.4"}, + {"rd": "10:42", "p": "99.0.0.4/32", "n": "4.4.4.4"}, ] -bgpribRequireVpnRoutes('r1','Remote Customer routes in R1 vpn',want_r1_remote_vpn_routes) +bgpribRequireVpnRoutes( + "r1", "Remote Customer routes in R1 vpn", want_r1_remote_vpn_routes +) want_r3_remote_vpn_routes = [ - {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1'}, - {'rd':'10:1', 'p':'5.1.1.0/24', 'n':'1.1.1.1'}, - {'rd':'10:1', 'p':'99.0.0.1/32', 'n':'1.1.1.1'}, - - {'rd':'10:41', 'p':'5.1.2.0/24', 'n':'4.4.4.4'}, - {'rd':'10:41', 'p':'5.1.3.0/24', 'n':'4.4.4.4'}, - {'rd':'10:41', 'p':'99.0.0.3/32', 'n':'4.4.4.4'}, - - {'rd':'10:42', 'p':'5.4.2.0/24', 'n':'4.4.4.4'}, - {'rd':'10:42', 'p':'5.4.3.0/24', 'n':'4.4.4.4'}, - {'rd':'10:42', 'p':'99.0.0.4/32', 'n':'4.4.4.4'}, + {"rd": "10:1", "p": "5.1.0.0/24", "n": "1.1.1.1"}, + {"rd": "10:1", "p": "5.1.1.0/24", "n": "1.1.1.1"}, + {"rd": "10:1", "p": "99.0.0.1/32", "n": "1.1.1.1"}, + {"rd": "10:41", "p": "5.1.2.0/24", "n": "4.4.4.4"}, + {"rd": "10:41", "p": "5.1.3.0/24", "n": "4.4.4.4"}, + {"rd": "10:41", "p": "99.0.0.3/32", "n": "4.4.4.4"}, + {"rd": "10:42", "p": "5.4.2.0/24", "n": "4.4.4.4"}, + {"rd": "10:42", "p": "5.4.3.0/24", "n": "4.4.4.4"}, + {"rd": "10:42", "p": "99.0.0.4/32", "n": "4.4.4.4"}, ] -bgpribRequireVpnRoutes('r3','Remote Customer routes in R3 vpn',want_r3_remote_vpn_routes) +bgpribRequireVpnRoutes( + "r3", "Remote Customer routes in R3 vpn", want_r3_remote_vpn_routes +) want_r4_remote_vpn_routes = [ - {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1'}, - {'rd':'10:1', 'p':'5.1.1.0/24', 'n':'1.1.1.1'}, - {'rd':'10:1', 'p':'99.0.0.1/32', 'n':'1.1.1.1'}, - - {'rd':'10:3', 'p':'5.1.0.0/24', 'n':'3.3.3.3'}, - {'rd':'10:3', 'p':'5.1.1.0/24', 'n':'3.3.3.3'}, - {'rd':'10:3', 'p':'99.0.0.2/32', 'n':'3.3.3.3'}, + {"rd": "10:1", "p": "5.1.0.0/24", "n": "1.1.1.1"}, + {"rd": "10:1", "p": "5.1.1.0/24", "n": "1.1.1.1"}, + {"rd": "10:1", "p": "99.0.0.1/32", "n": "1.1.1.1"}, + {"rd": "10:3", "p": "5.1.0.0/24", "n": "3.3.3.3"}, + {"rd": "10:3", "p": "5.1.1.0/24", "n": "3.3.3.3"}, + {"rd": "10:3", "p": "99.0.0.2/32", "n": "3.3.3.3"}, ] -bgpribRequireVpnRoutes('r4','Remote Customer routes in R4 vpn',want_r4_remote_vpn_routes) - +bgpribRequireVpnRoutes( + "r4", "Remote Customer routes in R4 vpn", want_r4_remote_vpn_routes +) # r1 vtysh -c "show bgp vrf r1-cust1 ipv4" @@ -213,54 +266,58 @@ bgpribRequireVpnRoutes('r4','Remote Customer routes in R4 vpn',want_r4_remote_vp # PE routers: VRFs contain routes from remote customer nets ######################################################################## want_r1_remote_cust1_routes = [ - {'p':'5.1.0.0/24', 'n':'3.3.3.3'}, - {'p':'5.1.1.0/24', 'n':'3.3.3.3'}, - {'p':'99.0.0.2/32', 'n':'3.3.3.3'}, - - {'p':'5.1.2.0/24', 'n':'4.4.4.4'}, - {'p':'5.1.3.0/24', 'n':'4.4.4.4'}, - {'p':'99.0.0.3/32', 'n':'4.4.4.4'}, - - {'p':'5.4.2.0/24', 'n':'4.4.4.4'}, - {'p':'5.4.3.0/24', 'n':'4.4.4.4'}, - {'p':'99.0.0.3/32', 'n':'4.4.4.4'}, + {"p": "5.1.0.0/24", "n": "3.3.3.3"}, + {"p": "5.1.1.0/24", "n": "3.3.3.3"}, + {"p": "99.0.0.2/32", "n": "3.3.3.3"}, + {"p": "5.1.2.0/24", "n": "4.4.4.4"}, + {"p": "5.1.3.0/24", "n": "4.4.4.4"}, + {"p": "99.0.0.3/32", "n": "4.4.4.4"}, + {"p": "5.4.2.0/24", "n": "4.4.4.4"}, + {"p": "5.4.3.0/24", "n": "4.4.4.4"}, + {"p": "99.0.0.3/32", "n": "4.4.4.4"}, ] -bgpribRequireUnicastRoutes('r1','ipv4','r1-cust1','Customer 1 routes in r1 vrf',want_r1_remote_cust1_routes) +bgpribRequireUnicastRoutes( + "r1", "ipv4", "r1-cust1", "Customer 1 routes in r1 vrf", want_r1_remote_cust1_routes +) want_r3_remote_cust1_routes = [ - {'p':'5.1.0.0/24', 'n':'1.1.1.1'}, - {'p':'5.1.1.0/24', 'n':'1.1.1.1'}, - {'p':'99.0.0.1/32', 'n':'1.1.1.1'}, - - {'p':'5.1.2.0/24', 'n':'4.4.4.4'}, - {'p':'5.1.3.0/24', 'n':'4.4.4.4'}, - {'p':'99.0.0.3/32', 'n':'4.4.4.4'}, - - {'p':'5.4.2.0/24', 'n':'4.4.4.4'}, - {'p':'5.4.3.0/24', 'n':'4.4.4.4'}, - {'p':'99.0.0.3/32', 'n':'4.4.4.4'}, + {"p": "5.1.0.0/24", "n": "1.1.1.1"}, + {"p": "5.1.1.0/24", "n": "1.1.1.1"}, + {"p": "99.0.0.1/32", "n": "1.1.1.1"}, + {"p": "5.1.2.0/24", "n": "4.4.4.4"}, + {"p": "5.1.3.0/24", "n": "4.4.4.4"}, + {"p": "99.0.0.3/32", "n": "4.4.4.4"}, + {"p": "5.4.2.0/24", "n": "4.4.4.4"}, + {"p": "5.4.3.0/24", "n": "4.4.4.4"}, + {"p": "99.0.0.3/32", "n": "4.4.4.4"}, ] -bgpribRequireUnicastRoutes('r3','ipv4','r3-cust1','Customer 1 routes in r3 vrf',want_r3_remote_cust1_routes) +bgpribRequireUnicastRoutes( + "r3", "ipv4", "r3-cust1", "Customer 1 routes in r3 vrf", want_r3_remote_cust1_routes +) want_r4_remote_cust1_routes = [ - {'p':'5.1.0.0/24', 'n':'1.1.1.1'}, - {'p':'5.1.1.0/24', 'n':'1.1.1.1'}, - {'p':'5.1.0.0/24', 'n':'3.3.3.3'}, - {'p':'5.1.1.0/24', 'n':'3.3.3.3'}, - {'p':'99.0.0.1/32', 'n':'1.1.1.1'}, - {'p':'99.0.0.2/32', 'n':'3.3.3.3'}, + {"p": "5.1.0.0/24", "n": "1.1.1.1"}, + {"p": "5.1.1.0/24", "n": "1.1.1.1"}, + {"p": "5.1.0.0/24", "n": "3.3.3.3"}, + {"p": "5.1.1.0/24", "n": "3.3.3.3"}, + {"p": "99.0.0.1/32", "n": "1.1.1.1"}, + {"p": "99.0.0.2/32", "n": "3.3.3.3"}, ] -bgpribRequireUnicastRoutes('r4','ipv4','r4-cust1','Customer 1 routes in r4 vrf',want_r4_remote_cust1_routes) +bgpribRequireUnicastRoutes( + "r4", "ipv4", "r4-cust1", "Customer 1 routes in r4 vrf", want_r4_remote_cust1_routes +) want_r4_remote_cust2_routes = [ - {'p':'5.1.0.0/24', 'n':'1.1.1.1'}, - {'p':'5.1.1.0/24', 'n':'1.1.1.1'}, - {'p':'5.1.0.0/24', 'n':'3.3.3.3'}, - {'p':'5.1.1.0/24', 'n':'3.3.3.3'}, - {'p':'99.0.0.1/32', 'n':'1.1.1.1'}, - {'p':'99.0.0.2/32', 'n':'3.3.3.3'}, + {"p": "5.1.0.0/24", "n": "1.1.1.1"}, + {"p": "5.1.1.0/24", "n": "1.1.1.1"}, + {"p": "5.1.0.0/24", "n": "3.3.3.3"}, + {"p": "5.1.1.0/24", "n": "3.3.3.3"}, + {"p": "99.0.0.1/32", "n": "1.1.1.1"}, + {"p": "99.0.0.2/32", "n": "3.3.3.3"}, ] -bgpribRequireUnicastRoutes('r4','ipv4','r4-cust2','Customer 2 routes in r4 vrf',want_r4_remote_cust2_routes) +bgpribRequireUnicastRoutes( + "r4", "ipv4", "r4-cust2", "Customer 2 routes in r4 vrf", want_r4_remote_cust2_routes +) ######################################################################### @@ -270,49 +327,78 @@ bgpribRequireUnicastRoutes('r4','ipv4','r4-cust2','Customer 2 routes in r4 vrf', # r1 vtysh -c "show bgp vrf r1-cust1 ipv4" # r1 vtysh -c "show bgp vrf r1-cust1 ipv4 5.1.2.0/24" -luCommand('ce1','vtysh -c "show bgp ipv4 uni"','10 routes and 10','wait','Local and remote routes', 10) +luCommand( + "ce1", + 'vtysh -c "show bgp ipv4 uni"', + "10 routes and 10", + "wait", + "Local and remote routes", + 10, +) want = [ - {'p':'5.1.2.0/24', 'n':'192.168.1.1'}, - {'p':'5.1.3.0/24', 'n':'192.168.1.1'}, - {'p':'5.4.2.0/24', 'n':'192.168.1.1'}, - {'p':'5.4.3.0/24', 'n':'192.168.1.1'}, + {"p": "5.1.2.0/24", "n": "192.168.1.1"}, + {"p": "5.1.3.0/24", "n": "192.168.1.1"}, + {"p": "5.4.2.0/24", "n": "192.168.1.1"}, + {"p": "5.4.3.0/24", "n": "192.168.1.1"}, ] -bgpribRequireUnicastRoutes('ce1','ipv4','','Cust 1 routes from remote',want) +bgpribRequireUnicastRoutes("ce1", "ipv4", "", "Cust 1 routes from remote", want) -luCommand('ce2','vtysh -c "show bgp ipv4 uni"','10 routes and 12','wait','Local and remote routes', 10) +luCommand( + "ce2", + 'vtysh -c "show bgp ipv4 uni"', + "10 routes and 12", + "wait", + "Local and remote routes", + 10, +) want = [ - {'p':'5.1.0.0/24', 'n':'192.168.1.1'}, - {'p':'5.1.1.0/24', 'n':'192.168.1.1'}, - {'p':'5.1.2.0/24', 'n':'192.168.1.1'}, - {'p':'5.1.3.0/24', 'n':'192.168.1.1'}, - {'p':'5.4.2.0/24', 'n':'192.168.1.1'}, - {'p':'5.4.3.0/24', 'n':'192.168.1.1'}, + {"p": "5.1.0.0/24", "n": "192.168.1.1"}, + {"p": "5.1.1.0/24", "n": "192.168.1.1"}, + {"p": "5.1.2.0/24", "n": "192.168.1.1"}, + {"p": "5.1.3.0/24", "n": "192.168.1.1"}, + {"p": "5.4.2.0/24", "n": "192.168.1.1"}, + {"p": "5.4.3.0/24", "n": "192.168.1.1"}, ] -bgpribRequireUnicastRoutes('ce2','ipv4','','Cust 1 routes from remote',want) +bgpribRequireUnicastRoutes("ce2", "ipv4", "", "Cust 1 routes from remote", want) # human readable output for debugging -luCommand('r4','vtysh -c "show bgp vrf r4-cust1 ipv4 uni"') -luCommand('r4','vtysh -c "show bgp vrf r4-cust2 ipv4 uni"') -luCommand('r4','vtysh -c "show bgp ipv4 vpn"') -luCommand('r4','vtysh -c "show ip route vrf r4-cust1"') -luCommand('r4','vtysh -c "show ip route vrf r4-cust2"') +luCommand("r4", 'vtysh -c "show bgp vrf r4-cust1 ipv4 uni"') +luCommand("r4", 'vtysh -c "show bgp vrf r4-cust2 ipv4 uni"') +luCommand("r4", 'vtysh -c "show bgp ipv4 vpn"') +luCommand("r4", 'vtysh -c "show ip route vrf r4-cust1"') +luCommand("r4", 'vtysh -c "show ip route vrf r4-cust2"') -luCommand('ce3','vtysh -c "show bgp ipv4 uni"','10 routes and 10','wait','Local and remote routes', 10) +luCommand( + "ce3", + 'vtysh -c "show bgp ipv4 uni"', + "10 routes and 10", + "wait", + "Local and remote routes", + 10, +) # Requires bvl-bug-degenerate-no-label fix (FRR PR #2053) want = [ - {'p':'5.1.0.0/24', 'n':'192.168.1.1'}, - {'p':'5.1.1.0/24', 'n':'192.168.1.1'}, - {'p':'5.4.2.0/24', 'n':'192.168.1.1'}, - {'p':'5.4.3.0/24', 'n':'192.168.1.1'}, + {"p": "5.1.0.0/24", "n": "192.168.1.1"}, + {"p": "5.1.1.0/24", "n": "192.168.1.1"}, + {"p": "5.4.2.0/24", "n": "192.168.1.1"}, + {"p": "5.4.3.0/24", "n": "192.168.1.1"}, ] -bgpribRequireUnicastRoutes('ce3','ipv4','','Cust 1 routes from remote',want) +bgpribRequireUnicastRoutes("ce3", "ipv4", "", "Cust 1 routes from remote", want) -luCommand('ce4','vtysh -c "show bgp vrf ce4-cust2 ipv4 uni"','10 routes and 10','wait','Local and remote routes', 10) +luCommand( + "ce4", + 'vtysh -c "show bgp vrf ce4-cust2 ipv4 uni"', + "10 routes and 10", + "wait", + "Local and remote routes", + 10, +) want = [ - {'p':'5.1.0.0/24', 'n':'192.168.2.1'}, - {'p':'5.1.1.0/24', 'n':'192.168.2.1'}, - {'p':'5.1.2.0/24', 'n':'192.168.2.1'}, - {'p':'5.1.3.0/24', 'n':'192.168.2.1'}, + {"p": "5.1.0.0/24", "n": "192.168.2.1"}, + {"p": "5.1.1.0/24", "n": "192.168.2.1"}, + {"p": "5.1.2.0/24", "n": "192.168.2.1"}, + {"p": "5.1.3.0/24", "n": "192.168.2.1"}, ] -bgpribRequireUnicastRoutes('ce4','ipv4','ce4-cust2','Cust 2 routes from remote',want) - +bgpribRequireUnicastRoutes( + "ce4", "ipv4", "ce4-cust2", "Cust 2 routes from remote", want +) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/cleanup_all.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/cleanup_all.py index a721cf21bd..af77ab01c1 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/cleanup_all.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/cleanup_all.py @@ -1,17 +1,120 @@ from lutil import luCommand -luCommand('r1','vtysh -c "clear vrf r1-cust1 prefix 99.0.0.1/32"','.','none','Cleared VRF route') -luCommand('r3','vtysh -c "clear vrf r3-cust1 prefix 99.0.0.2/32"','.','none','Cleared VRF route') -luCommand('r4','vtysh -c "clear vrf r3-cust1 prefix 99.0.0.3/32"','.','none','Cleared VRF route') -luCommand('r1','vtysh -c "show vnc registrations local"','99.0.0.1','fail','Local Registration cleared') -luCommand('r3','vtysh -c "show vnc registrations local"','99.0.0.2','fail','Local Registration cleared') -luCommand('r4','vtysh -c "show vnc registrations local"','99.0.0.3','fail','Local Registration cleared') -luCommand('r1','vtysh -c "show bgp ipv4 uni"','2 routes and 2','wait','Unicast SAFI updated', 10) -luCommand('r2','vtysh -c "show bgp ipv4 uni"','No BGP prefixes displayed','pass','Unicast SAFI') -luCommand('r3','vtysh -c "show bgp ipv4 uni"','2 routes and 2','wait','Unicast SAFI updated', 10) -luCommand('r4','vtysh -c "show bgp ipv4 uni"','2 routes and 2','wait','Unicast SAFI updated', 10) -luCommand('ce1','vtysh -c "show bgp ipv4 uni"','2 routes and 2','wait','Local and remote routes', 10) -luCommand('ce2','vtysh -c "show bgp ipv4 uni"','2 routes and 2','wait','Local and remote routes', 10) -luCommand('ce3','vtysh -c "show bgp ipv4 uni"','2 routes and 2','wait','Local and remote routes', 10) -luCommand('r1','vtysh -c "show vnc registrations remote"','Prefix ','fail','Remote Registration cleared') -luCommand('r3','vtysh -c "show vnc registrations remote"','Prefix ','fail','Remote Registration cleared') -luCommand('r4','vtysh -c "show vnc registrations remote"','Prefix ','fail','Remote Registration cleared') + +luCommand( + "r1", + 'vtysh -c "clear vrf r1-cust1 prefix 99.0.0.1/32"', + ".", + "none", + "Cleared VRF route", +) +luCommand( + "r3", + 'vtysh -c "clear vrf r3-cust1 prefix 99.0.0.2/32"', + ".", + "none", + "Cleared VRF route", +) +luCommand( + "r4", + 'vtysh -c "clear vrf r3-cust1 prefix 99.0.0.3/32"', + ".", + "none", + "Cleared VRF route", +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations local"', + "99.0.0.1", + "fail", + "Local Registration cleared", +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations local"', + "99.0.0.2", + "fail", + "Local Registration cleared", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations local"', + "99.0.0.3", + "fail", + "Local Registration cleared", +) +luCommand( + "r1", + 'vtysh -c "show bgp ipv4 uni"', + "2 routes and 2", + "wait", + "Unicast SAFI updated", + 10, +) +luCommand( + "r2", + 'vtysh -c "show bgp ipv4 uni"', + "No BGP prefixes displayed", + "pass", + "Unicast SAFI", +) +luCommand( + "r3", + 'vtysh -c "show bgp ipv4 uni"', + "2 routes and 2", + "wait", + "Unicast SAFI updated", + 10, +) +luCommand( + "r4", + 'vtysh -c "show bgp ipv4 uni"', + "2 routes and 2", + "wait", + "Unicast SAFI updated", + 10, +) +luCommand( + "ce1", + 'vtysh -c "show bgp ipv4 uni"', + "2 routes and 2", + "wait", + "Local and remote routes", + 10, +) +luCommand( + "ce2", + 'vtysh -c "show bgp ipv4 uni"', + "2 routes and 2", + "wait", + "Local and remote routes", + 10, +) +luCommand( + "ce3", + 'vtysh -c "show bgp ipv4 uni"', + "2 routes and 2", + "wait", + "Local and remote routes", + 10, +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations remote"', + "Prefix ", + "fail", + "Remote Registration cleared", +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations remote"', + "Prefix ", + "fail", + "Remote Registration cleared", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations remote"', + "Prefix ", + "fail", + "Remote Registration cleared", +) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/del_bgp_instances.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/del_bgp_instances.py index c25c2d9ec5..477578bdbd 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/del_bgp_instances.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/del_bgp_instances.py @@ -1,7 +1,30 @@ from lutil import luCommand -luCommand('r1','/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5227 vrf r1-cust1" -c "no router bgp 5226"','.','none','Cleared bgp instances') -luCommand('r2','/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5226"','.','none','Cleared bgp instances') -luCommand('r3','/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5227 vrf r3-cust1" -c "no router bgp 5226"','.','none','Cleared bgp instances') -luCommand('r4','/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5228 vrf r4-cust2" -c "no router bgp 5227 vrf r4-cust1" -c "no router bgp 5226"','.','none','Cleared bgp instances') - +luCommand( + "r1", + '/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5227 vrf r1-cust1" -c "no router bgp 5226"', + ".", + "none", + "Cleared bgp instances", +) +luCommand( + "r2", + '/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5226"', + ".", + "none", + "Cleared bgp instances", +) +luCommand( + "r3", + '/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5227 vrf r3-cust1" -c "no router bgp 5226"', + ".", + "none", + "Cleared bgp instances", +) +luCommand( + "r4", + '/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5228 vrf r4-cust2" -c "no router bgp 5227 vrf r4-cust1" -c "no router bgp 5226"', + ".", + "none", + "Cleared bgp instances", +) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py index d447548783..2b0a85a91a 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py @@ -1,9 +1,22 @@ from lutil import luCommand -rtrs = ['ce1', 'ce2', 'ce3', 'r1', 'r2', 'r3', 'r4'] + +rtrs = ["ce1", "ce2", "ce3", "r1", "r2", "r3", "r4"] for rtr in rtrs: - ret = luCommand(rtr, 'vtysh -c "show bgp neigh"', 'Notification received .([A-Za-z0-9/ ]*)', 'none', 'collect neighbor stats') + ret = luCommand( + rtr, + 'vtysh -c "show bgp neigh"', + "Notification received .([A-Za-z0-9/ ]*)", + "none", + "collect neighbor stats", + ) found = luLast() if ret != False and found != None: val = found.group(1) - ret = luCommand(rtr, 'vtysh -c "show bgp neigh"', 'Notification received', 'fail', 'Notify RXed! {}'.format(val)) -#done + ret = luCommand( + rtr, + 'vtysh -c "show bgp neigh"', + "Notification received", + "fail", + "Notify RXed! {}".format(val), + ) +# done diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py index 0279e482ff..b4fa240495 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py @@ -1,25 +1,87 @@ from lutil import luCommand -ret = luCommand('ce1', 'vtysh -c "show ip route" | grep -c \\ 10\\.\\*/32','(.*)','pass', 'Looking for sharp routes') + +ret = luCommand( + "ce1", + 'vtysh -c "show ip route" | grep -c \\ 10\\.\\*/32', + "(.*)", + "pass", + "Looking for sharp routes", +) found = luLast() if ret != False and found != None: num = int(found.group()) - luCommand('ce3', 'vtysh -c "show bgp sum"', - '.', 'pass', 'See %s sharp routes' % num) + luCommand( + "ce3", 'vtysh -c "show bgp sum"', ".", "pass", "See %s sharp routes" % num + ) if num > 0: - rtrs = ['ce1', 'ce2', 'ce3'] + rtrs = ["ce1", "ce2", "ce3"] for rtr in rtrs: - luCommand(rtr, 'vtysh -c "show bgp ipv4 uni" | grep Display','.', 'none', 'BGP routes pre remove') - luCommand(rtr, 'ip route show | cat -n | tail','.', 'none', 'Linux routes pre remove') - wait = 2*num/500 - luCommand('ce1', 'vtysh -c "sharp remove routes 10.0.0.0 {}"'.format(num),'.','none','Removing {} routes'.format(num)) - luCommand('ce2', 'vtysh -c "sharp remove routes 10.0.0.0 {}"'.format(num),'.','none','Removing {} routes'.format(num)) + luCommand( + rtr, + 'vtysh -c "show bgp ipv4 uni" | grep Display', + ".", + "none", + "BGP routes pre remove", + ) + luCommand( + rtr, + "ip route show | cat -n | tail", + ".", + "none", + "Linux routes pre remove", + ) + wait = 2 * num / 500 + luCommand( + "ce1", + 'vtysh -c "sharp remove routes 10.0.0.0 {}"'.format(num), + ".", + "none", + "Removing {} routes".format(num), + ) + luCommand( + "ce2", + 'vtysh -c "sharp remove routes 10.0.0.0 {}"'.format(num), + ".", + "none", + "Removing {} routes".format(num), + ) for rtr in rtrs: - luCommand(rtr, 'vtysh -c "show bgp ipv4 uni" | grep Display',' 10 route', 'wait', 'BGP routes removed', wait, wait_time=10) - luCommand(rtr, 'vtysh -c "show bgp ipv4 uni"','.', 'none', 'BGP routes post remove') + luCommand( + rtr, + 'vtysh -c "show bgp ipv4 uni" | grep Display', + " 10 route", + "wait", + "BGP routes removed", + wait, + wait_time=10, + ) + luCommand( + rtr, + 'vtysh -c "show bgp ipv4 uni"', + ".", + "none", + "BGP routes post remove", + ) for rtr in rtrs: - luCommand(rtr, 'ip route show | grep -c \\^10\\.','^0$', 'wait', 'Linux routes removed', wait, wait_time=10) - luCommand(rtr, 'ip route show','.', 'none', 'Linux routes post remove') - rtrs = ['r1', 'r3', 'r4'] + luCommand( + rtr, + "ip route show | grep -c \\^10\\.", + "^0$", + "wait", + "Linux routes removed", + wait, + wait_time=10, + ) + luCommand(rtr, "ip route show", ".", "none", "Linux routes post remove") + rtrs = ["r1", "r3", "r4"] for rtr in rtrs: - luCommand(rtr, 'ip route show vrf {}-cust1 | grep -c \\^10\\.'.format(rtr),'^0$','wait','VRF route removed',wait, wait_time=10) -#done + luCommand( + rtr, + "ip route show vrf {}-cust1 | grep -c \\^10\\.".format(rtr), + "^0$", + "wait", + "VRF route removed", + wait, + wait_time=10, + ) +# done diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py index 4ecaa4c026..3c768640a1 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py @@ -1,29 +1,38 @@ from lutil import luCommand + num = 50000 -b = int(num/(256*256)) +b = int(num / (256 * 256)) if b > 0: - r = num - b * (256*256) + r = num - b * (256 * 256) else: r = num -c = int(r/256) +c = int(r / 256) if c > 0: - d = r - c * 256 - 1 + d = r - c * 256 - 1 else: d = r -wait = 2*num/1000 +wait = 2 * num / 1000 mem_z = {} mem_b = {} -rtrs = ['ce1', 'ce2', 'ce3', 'r1', 'r2', 'r3', 'r4'] +rtrs = ["ce1", "ce2", "ce3", "r1", "r2", "r3", "r4"] for rtr in rtrs: - mem_z[rtr] = {'value': 0, 'units': 'unknown'} - mem_b[rtr] = {'value': 0, 'units': 'unknown'} - ret = luCommand(rtr, 'vtysh -c "show memory"', 'zebra: System allocator statistics: Total heap allocated: *(\d*) ([A-Za-z]*) .*bgpd: System allocator statistics: Total heap allocated: *(\d*) ([A-Za-z]*)', 'none', 'collect bgpd memory stats') + mem_z[rtr] = {"value": 0, "units": "unknown"} + mem_b[rtr] = {"value": 0, "units": "unknown"} + ret = luCommand( + rtr, + 'vtysh -c "show memory"', + "zebra: System allocator statistics: Total heap allocated: *(\d*) ([A-Za-z]*) .*bgpd: System allocator statistics: Total heap allocated: *(\d*) ([A-Za-z]*)", + "none", + "collect bgpd memory stats", + ) found = luLast() if ret != False and found != None: - mem_z[rtr] = {'value': int(found.group(1)), 'units': found.group(2)} - mem_b[rtr] = {'value': int(found.group(3)), 'units': found.group(4)} + mem_z[rtr] = {"value": int(found.group(1)), "units": found.group(2)} + mem_b[rtr] = {"value": int(found.group(3)), "units": found.group(4)} -luCommand('ce1', 'vtysh -c "show mem"', 'qmem sharpd', 'none','check if sharpd running') +luCommand( + "ce1", 'vtysh -c "show mem"', "qmem sharpd", "none", "check if sharpd running" +) doSharp = False found = luLast() if ret != False and found != None: @@ -31,47 +40,195 @@ if ret != False and found != None: doSharp = True if doSharp != True: - luCommand('ce1', 'vtysh -c "sharp data nexthop"', '.', 'pass','sharpd NOT running, skipping test') + luCommand( + "ce1", + 'vtysh -c "sharp data nexthop"', + ".", + "pass", + "sharpd NOT running, skipping test", + ) else: - luCommand('ce1', 'vtysh -c "sharp install routes 10.0.0.0 nexthop 99.0.0.1 {}"'.format(num),'','pass','Adding {} routes'.format(num)) - luCommand('ce2', 'vtysh -c "sharp install routes 10.0.0.0 nexthop 99.0.0.2 {}"'.format(num),'','pass','Adding {} routes'.format(num)) - rtrs = ['ce1', 'ce2', 'ce3'] + luCommand( + "ce1", + 'vtysh -c "sharp install routes 10.0.0.0 nexthop 99.0.0.1 {}"'.format(num), + "", + "pass", + "Adding {} routes".format(num), + ) + luCommand( + "ce2", + 'vtysh -c "sharp install routes 10.0.0.0 nexthop 99.0.0.2 {}"'.format(num), + "", + "pass", + "Adding {} routes".format(num), + ) + rtrs = ["ce1", "ce2", "ce3"] for rtr in rtrs: - luCommand(rtr, 'vtysh -c "show bgp ipv4 uni 10.{}.{}.{}"'.format(b,c,d), 'Last update:', 'wait', 'RXed last route, 10.{}.{}.{}'.format(b,c,d), wait, wait_time=10) - luCommand(rtr, 'vtysh -c "show bgp ipv4 uni" | grep -c 10\\.\\*/32', str(num), 'wait', 'See all sharp routes in BGP', wait, wait_time=10) - luCommand('r1', 'vtysh -c "show bgp vrf r1-cust1 ipv4 uni 10.{}.{}.{}"'.format(b,c,d),'99.0.0.1','wait','RXed -> 10.{}.{}.{} from CE1'.format(b,c,d), wait, wait_time=10) - luCommand('r3', 'vtysh -c "show bgp vrf r3-cust1 ipv4 uni 10.{}.{}.{}"'.format(b,c,d),'99.0.0.2','wait','RXed -> 10.{}.{}.{} from CE2'.format(b,c,d), wait, wait_time=10) - luCommand('r1', 'vtysh -c "show bgp ipv4 vpn 10.{}.{}.{}"'.format(b,c,d),'99.0.0.1','wait','see VPN safi -> 10.{}.{}.{} from CE1'.format(b,c,d)) - luCommand('r3', 'vtysh -c "show bgp ipv4 vpn 10.{}.{}.{}"'.format(b,c,d),'99.0.0.2','wait','see VPN safi -> 10.{}.{}.{} from CE2'.format(b,c,d)) - luCommand('r3', 'vtysh -c "show bgp ipv4 vpn 10.{}.{}.{}"'.format(b,c,d),'1.1.1.1','wait','see VPN safi -> 10.{}.{}.{} from CE1'.format(b,c,d)) - luCommand('r1', 'vtysh -c "show bgp ipv4 vpn 10.{}.{}.{}"'.format(b,c,d),'3.3.3.3','wait','see VPN safi -> 10.{}.{}.{} from CE2'.format(b,c,d)) - luCommand('r4', 'vtysh -c "show bgp ipv4 vpn 10.{}.{}.{}"'.format(b,c,d),'1.1.1.1','wait','see VPN safi -> 10.{}.{}.{} from CE1'.format(b,c,d)) - luCommand('r4', 'vtysh -c "show bgp ipv4 vpn 10.{}.{}.{}"'.format(b,c,d),'3.3.3.3','wait','see VPN safi -> 10.{}.{}.{} from CE2'.format(b,c,d)) - rtrs = ['ce1', 'ce2', 'ce3'] + luCommand( + rtr, + 'vtysh -c "show bgp ipv4 uni 10.{}.{}.{}"'.format(b, c, d), + "Last update:", + "wait", + "RXed last route, 10.{}.{}.{}".format(b, c, d), + wait, + wait_time=10, + ) + luCommand( + rtr, + 'vtysh -c "show bgp ipv4 uni" | grep -c 10\\.\\*/32', + str(num), + "wait", + "See all sharp routes in BGP", + wait, + wait_time=10, + ) + luCommand( + "r1", + 'vtysh -c "show bgp vrf r1-cust1 ipv4 uni 10.{}.{}.{}"'.format(b, c, d), + "99.0.0.1", + "wait", + "RXed -> 10.{}.{}.{} from CE1".format(b, c, d), + wait, + wait_time=10, + ) + luCommand( + "r3", + 'vtysh -c "show bgp vrf r3-cust1 ipv4 uni 10.{}.{}.{}"'.format(b, c, d), + "99.0.0.2", + "wait", + "RXed -> 10.{}.{}.{} from CE2".format(b, c, d), + wait, + wait_time=10, + ) + luCommand( + "r1", + 'vtysh -c "show bgp ipv4 vpn 10.{}.{}.{}"'.format(b, c, d), + "99.0.0.1", + "wait", + "see VPN safi -> 10.{}.{}.{} from CE1".format(b, c, d), + ) + luCommand( + "r3", + 'vtysh -c "show bgp ipv4 vpn 10.{}.{}.{}"'.format(b, c, d), + "99.0.0.2", + "wait", + "see VPN safi -> 10.{}.{}.{} from CE2".format(b, c, d), + ) + luCommand( + "r3", + 'vtysh -c "show bgp ipv4 vpn 10.{}.{}.{}"'.format(b, c, d), + "1.1.1.1", + "wait", + "see VPN safi -> 10.{}.{}.{} from CE1".format(b, c, d), + ) + luCommand( + "r1", + 'vtysh -c "show bgp ipv4 vpn 10.{}.{}.{}"'.format(b, c, d), + "3.3.3.3", + "wait", + "see VPN safi -> 10.{}.{}.{} from CE2".format(b, c, d), + ) + luCommand( + "r4", + 'vtysh -c "show bgp ipv4 vpn 10.{}.{}.{}"'.format(b, c, d), + "1.1.1.1", + "wait", + "see VPN safi -> 10.{}.{}.{} from CE1".format(b, c, d), + ) + luCommand( + "r4", + 'vtysh -c "show bgp ipv4 vpn 10.{}.{}.{}"'.format(b, c, d), + "3.3.3.3", + "wait", + "see VPN safi -> 10.{}.{}.{} from CE2".format(b, c, d), + ) + rtrs = ["ce1", "ce2", "ce3"] for rtr in rtrs: - luCommand(rtr, 'ip route get 10.{}.{}.{}'.format(b,c,d),'dev','wait','Route to 10.{}.{}.{} available'.format(b,c,d), wait, wait_time=10) - luCommand(rtr, 'ip route show | grep -c \\^10\\.', str(num), 'wait', 'See {} linux routes'.format(num), wait, wait_time=10) + luCommand( + rtr, + "ip route get 10.{}.{}.{}".format(b, c, d), + "dev", + "wait", + "Route to 10.{}.{}.{} available".format(b, c, d), + wait, + wait_time=10, + ) + luCommand( + rtr, + "ip route show | grep -c \\^10\\.", + str(num), + "wait", + "See {} linux routes".format(num), + wait, + wait_time=10, + ) - rtrs = ['r1', 'r3', 'r4'] + rtrs = ["r1", "r3", "r4"] for rtr in rtrs: - luCommand(rtr, 'ip route get vrf {}-cust1 10.{}.{}.{}'.format(rtr,b,c,d),'dev','wait','VRF route available',wait, wait_time=10) - luCommand(rtr, 'ip route show vrf {}-cust1 | grep -c \\^10\\.'.format(rtr), str(num), 'wait','See {} linux routes'.format(num), wait, wait_time=10) - rtrs = ['ce1', 'ce2', 'ce3', 'r1', 'r2', 'r3', 'r4'] + luCommand( + rtr, + "ip route get vrf {}-cust1 10.{}.{}.{}".format(rtr, b, c, d), + "dev", + "wait", + "VRF route available", + wait, + wait_time=10, + ) + luCommand( + rtr, + "ip route show vrf {}-cust1 | grep -c \\^10\\.".format(rtr), + str(num), + "wait", + "See {} linux routes".format(num), + wait, + wait_time=10, + ) + rtrs = ["ce1", "ce2", "ce3", "r1", "r2", "r3", "r4"] for rtr in rtrs: - ret = luCommand(rtr, 'vtysh -c "show memory"', 'zebra: System allocator statistics: Total heap allocated: *(\d*) ([A-Za-z]*) .*bgpd: System allocator statistics: Total heap allocated: *(\d*) ([A-Za-z]*)', 'none', 'collect bgpd memory stats') + ret = luCommand( + rtr, + 'vtysh -c "show memory"', + "zebra: System allocator statistics: Total heap allocated: *(\d*) ([A-Za-z]*) .*bgpd: System allocator statistics: Total heap allocated: *(\d*) ([A-Za-z]*)", + "none", + "collect bgpd memory stats", + ) found = luLast() if ret != False and found != None: val_z = int(found.group(1)) - if mem_z[rtr]['units'] != found.group(2): + if mem_z[rtr]["units"] != found.group(2): val_z *= 1000 - delta_z = val_z - int(mem_z[rtr]['value']) - ave_z = float(delta_z)/float(num) + delta_z = val_z - int(mem_z[rtr]["value"]) + ave_z = float(delta_z) / float(num) val_b = int(found.group(3)) - if mem_b[rtr]['units'] != found.group(4): + if mem_b[rtr]["units"] != found.group(4): val_b *= 1000 - delta_b = val_b - int(mem_b[rtr]['value']) - ave_b = float(delta_b)/float(num) - luCommand(rtr, 'vtysh -c "show thread cpu"', '.', 'pass', 'BGPd heap: {0} {1} --> {2} {3} ({4} {1}/vpn route)'.format(mem_b[rtr]['value'], mem_b[rtr]['units'], found.group(3), found.group(4), round(ave_b,4))) - luCommand(rtr, 'vtysh -c "show thread cpu"', '.', 'pass', 'Zebra heap: {0} {1} --> {2} {3} ({4} {1}/vpn route)'.format(mem_z[rtr]['value'], mem_z[rtr]['units'], found.group(1), found.group(2), round(ave_z,4))) -#done + delta_b = val_b - int(mem_b[rtr]["value"]) + ave_b = float(delta_b) / float(num) + luCommand( + rtr, + 'vtysh -c "show thread cpu"', + ".", + "pass", + "BGPd heap: {0} {1} --> {2} {3} ({4} {1}/vpn route)".format( + mem_b[rtr]["value"], + mem_b[rtr]["units"], + found.group(3), + found.group(4), + round(ave_b, 4), + ), + ) + luCommand( + rtr, + 'vtysh -c "show thread cpu"', + ".", + "pass", + "Zebra heap: {0} {1} --> {2} {3} ({4} {1}/vpn route)".format( + mem_z[rtr]["value"], + mem_z[rtr]["units"], + found.group(1), + found.group(2), + round(ave_z, 4), + ), + ) +# done diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/test_bgp_l3vpn_to_bgp_vrf.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/test_bgp_l3vpn_to_bgp_vrf.py index 7e36398298..b537735c65 100755 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/test_bgp_l3vpn_to_bgp_vrf.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/test_bgp_l3vpn_to_bgp_vrf.py @@ -25,119 +25,132 @@ import os import sys import pytest -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../')) +sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")) from lib.ltemplate import * + def test_check_linux_vrf(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\', iproute2=\'4.9\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest('scripts/check_linux_vrf.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' + ltemplateTest("scripts/check_linux_vrf.py", False, CliOnFail, CheckFunc) + def test_adjacencies(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' - ltemplateTest('scripts/adjacencies.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' + ltemplateTest("scripts/adjacencies.py", False, CliOnFail, CheckFunc) + def test_notification_check(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\', iproute2=\'4.9\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest('scripts/notification_check.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' + ltemplateTest("scripts/notification_check.py", False, CliOnFail, CheckFunc) + def SKIP_test_add_routes(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' - ltemplateTest('scripts/add_routes.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' + ltemplateTest("scripts/add_routes.py", False, CliOnFail, CheckFunc) + def test_check_routes(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' - ltemplateTest('scripts/check_routes.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' + ltemplateTest("scripts/check_routes.py", False, CliOnFail, CheckFunc) -#manual data path setup test - remove once have bgp/zebra vrf path working + +# manual data path setup test - remove once have bgp/zebra vrf path working def test_check_linux_mpls(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\', iproute2=\'4.9\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest('scripts/check_linux_mpls.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' + ltemplateTest("scripts/check_linux_mpls.py", False, CliOnFail, CheckFunc) + def test_notification_check(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\', iproute2=\'4.9\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest('scripts/notification_check.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' + ltemplateTest("scripts/notification_check.py", False, CliOnFail, CheckFunc) + def test_check_scale_up(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\', iproute2=\'4.9\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest('scripts/scale_up.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' + ltemplateTest("scripts/scale_up.py", False, CliOnFail, CheckFunc) + def test_notification_check(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\', iproute2=\'4.9\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest('scripts/notification_check.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' + ltemplateTest("scripts/notification_check.py", False, CliOnFail, CheckFunc) + def test_check_scale_down(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\', iproute2=\'4.9\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest('scripts/scale_down.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' + ltemplateTest("scripts/scale_down.py", False, CliOnFail, CheckFunc) + def test_notification_check(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\', iproute2=\'4.9\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest('scripts/notification_check.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' + ltemplateTest("scripts/notification_check.py", False, CliOnFail, CheckFunc) + def SKIP_test_cleanup_all(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'4.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' - ltemplateTest('scripts/cleanup_all.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('4.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)' + ltemplateTest("scripts/cleanup_all.py", False, CliOnFail, CheckFunc) -if __name__ == '__main__': + +if __name__ == "__main__": retval = pytest.main(["-s"]) sys.exit(retval) diff --git a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py index fcea958a93..334aaebb4b 100755 --- a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py +++ b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py @@ -57,17 +57,19 @@ from lib.topogen import Topogen, get_topogen from mininet.topo import Topo from lib.common_config import ( - start_topology, write_test_header, - write_test_footer, reset_config_on_routers, - create_route_maps, create_bgp_community_lists, - create_prefix_lists, verify_bgp_community, step, - check_address_types + start_topology, + write_test_header, + write_test_footer, + reset_config_on_routers, + create_route_maps, + create_bgp_community_lists, + create_prefix_lists, + verify_bgp_community, + step, + check_address_types, ) from lib.topolog import logger -from lib.bgp import ( - verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify -) +from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify from lib.topojson import build_topo_from_json, build_config_from_json # Save the Current Working Directory to find configuration files. @@ -87,7 +89,7 @@ except IOError: bgp_convergence = False NETWORK = { "ipv4": ["200.50.2.0", "200.50.2.1", "200.50.2.0"], - "ipv6": ["1::1", "1::2", "1::0"] + "ipv6": ["1::1", "1::2", "1::0"], } MASK = {"ipv4": "32", "ipv6": "128"} NET_MASK = {"ipv4": "24", "ipv6": "120"} @@ -104,9 +106,8 @@ LARGE_COMM = { "pf_list_1": "0:0:1 0:0:10 0:0:100", "pf_list_2": "0:0:2 0:0:20 0:0:200", "agg_1": "0:0:1 0:0:2 0:0:10 0:0:20 0:0:100 0:0:200 2:1:1 " - "2:2:1 2:3:1 2:4:1 2:5:1", - "agg_2": "0:0:2 0:0:20 0:0:200 2:1:1 " - "2:2:1 2:3:1 2:4:1 2:5:1" + "2:2:1 2:3:1 2:4:1 2:5:1", + "agg_2": "0:0:2 0:0:20 0:0:200 2:1:1 " "2:2:1 2:3:1 2:4:1 2:5:1", } STANDARD_COMM = { "r1": "1:1 1:2 1:3 1:4 1:5", @@ -115,7 +116,7 @@ STANDARD_COMM = { "pf_list_1": "0:1 0:10 0:100", "pf_list_2": "0:2 0:20 0:200", "agg_1": "0:1 0:2 0:10 0:20 0:100 0:200 2:1 2:2 2:3 2:4 2:5", - "agg_2": "0:2 0:20 0:200 2:1 2:2 2:3 2:4 2:5" + "agg_2": "0:2 0:20 0:200 2:1 2:2 2:3 2:4 2:5", } @@ -169,8 +170,9 @@ def setup_module(mod): ##tgen.mininet_cli() # Api call verify whether BGP is converged bgp_convergence = verify_bgp_convergence(tgen, topo) - assert bgp_convergence is True, ("setup_module :Failed \n Error:" - " {}".format(bgp_convergence)) + assert bgp_convergence is True, "setup_module :Failed \n Error:" " {}".format( + bgp_convergence + ) ADDR_TYPES = check_address_types() logger.info("Running setup_module() done") @@ -190,8 +192,9 @@ def teardown_module(): # Stop toplogy and Remove tmp files tgen.stop_topology() - logger.info("Testsuite end time: {}". - format(time.asctime(time.localtime(time.time())))) + logger.info( + "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) + ) logger.info("=" * 40) @@ -206,13 +209,9 @@ def config_router_r1(tgen, topo, tc_name): "action": "permit", "seq_id": "10", "set": { - "large_community": { - "num": LARGE_COMM["r1"] - }, - "community": { - "num": STANDARD_COMM["r1"] - } - } + "large_community": {"num": LARGE_COMM["r1"]}, + "community": {"num": STANDARD_COMM["r1"]}, + }, } ] } @@ -221,8 +220,7 @@ def config_router_r1(tgen, topo, tc_name): step("Configuring LC1 on r1") result = create_route_maps(tgen, input_dict_1) - assert result is True, "Test case {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) # Configure neighbor for route map input_dict_2 = { @@ -233,68 +231,64 @@ def config_router_r1(tgen, topo, tc_name): "unicast": { "advertise_networks": [ { - "network": "%s/%s" % ( - NETWORK["ipv4"][0], MASK["ipv4"]), - "no_of_network": 4 + "network": "%s/%s" + % (NETWORK["ipv4"][0], MASK["ipv4"]), + "no_of_network": 4, } ], "neighbor": { "r2": { "dest_link": { "r1-link1": { - "route_maps": [{ - "name": "LC1", - "direction": "out" - }] + "route_maps": [ + {"name": "LC1", "direction": "out"} + ] } } }, "r3": { "dest_link": { "r1-link1": { - "route_maps": [{ - "name": "LC1", - "direction": "out" - }] + "route_maps": [ + {"name": "LC1", "direction": "out"} + ] } } - } - } + }, + }, } }, "ipv6": { "unicast": { "advertise_networks": [ { - "network": "%s/%s" % ( - NETWORK["ipv6"][0], MASK["ipv6"]), - "no_of_network": 4 + "network": "%s/%s" + % (NETWORK["ipv6"][0], MASK["ipv6"]), + "no_of_network": 4, } ], "neighbor": { "r2": { "dest_link": { "r1-link1": { - "route_maps": [{ - "name": "LC1", - "direction": "out" - }] + "route_maps": [ + {"name": "LC1", "direction": "out"} + ] } } }, "r3": { "dest_link": { "r1-link1": { - "route_maps": [{ - "name": "LC1", - "direction": "out" - }] + "route_maps": [ + {"name": "LC1", "direction": "out"} + ] } } - } - } + }, + }, } - } + }, } } } @@ -302,8 +296,7 @@ def config_router_r1(tgen, topo, tc_name): step("Applying LC1 on r1 neighbors and advertising networks") result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Test case {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) CONFIG_ROUTER_R1 = True @@ -319,13 +312,9 @@ def config_router_r2(tgen, topo, tc_name): "action": "permit", "seq_id": "10", "set": { - "large_community": { - "num": LARGE_COMM["r2"] - }, - "community": { - "num": STANDARD_COMM["r2"] - } - } + "large_community": {"num": LARGE_COMM["r2"]}, + "community": {"num": STANDARD_COMM["r2"]}, + }, } ] } @@ -334,8 +323,7 @@ def config_router_r2(tgen, topo, tc_name): step("Configuring route-maps LC2 on r2") result = create_route_maps(tgen, input_dict) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_1 = { "r2": { @@ -347,10 +335,9 @@ def config_router_r2(tgen, topo, tc_name): "r4": { "dest_link": { "r2-link1": { - "route_maps": [{ - "name": "LC2", - "direction": "out" - }] + "route_maps": [ + {"name": "LC2", "direction": "out"} + ] } } } @@ -363,16 +350,15 @@ def config_router_r2(tgen, topo, tc_name): "r4": { "dest_link": { "r2-link1": { - "route_maps": [{ - "name": "LC2", - "direction": "out" - }] + "route_maps": [ + {"name": "LC2", "direction": "out"} + ] } } } } } - } + }, } } } @@ -380,8 +366,7 @@ def config_router_r2(tgen, topo, tc_name): step("Applying LC2 on r2 neighbors in out direction") result = create_router_bgp(tgen, topo, input_dict_1) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) CONFIG_ROUTER_R2 = True @@ -399,13 +384,13 @@ def config_router_additive(tgen, topo, tc_name): "set": { "large_community": { "num": LARGE_COMM["r2"], - "action": "additive" + "action": "additive", }, "community": { "num": STANDARD_COMM["r2"], - "action": "additive" - } - } + "action": "additive", + }, + }, } ] } @@ -414,8 +399,7 @@ def config_router_additive(tgen, topo, tc_name): step("Configuring LC2 with community attributes as additive") result = create_route_maps(tgen, input_dict) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) # tgen.mininet_cli() CONFIG_ROUTER_ADDITIVE = True @@ -434,47 +418,41 @@ def config_for_as_path(tgen, topo, tc_name): "pf_list_1": [ { "seqid": "10", - "network": "%s/%s" % (NETWORK["ipv4"][0], - MASK["ipv4"]), - "action": "permit" + "network": "%s/%s" % (NETWORK["ipv4"][0], MASK["ipv4"]), + "action": "permit", } ], "pf_list_2": [ { "seqid": "10", - "network": "%s/%s" % (NETWORK["ipv4"][1], - MASK["ipv4"]), - "action": "permit" + "network": "%s/%s" % (NETWORK["ipv4"][1], MASK["ipv4"]), + "action": "permit", } - ] + ], }, "ipv6": { "pf_list_3": [ { "seqid": "10", - "network": "%s/%s" % (NETWORK["ipv6"][0], - MASK["ipv6"]), - "action": "permit" + "network": "%s/%s" % (NETWORK["ipv6"][0], MASK["ipv6"]), + "action": "permit", } ], "pf_list_4": [ { "seqid": "10", - "network": "%s/%s" % (NETWORK["ipv6"][1], - MASK["ipv6"]), - "action": "permit" + "network": "%s/%s" % (NETWORK["ipv6"][1], MASK["ipv6"]), + "action": "permit", } - ] - } - + ], + }, } } } step("Configuring prefix-lists on r1 to filter networks") result = create_prefix_lists(tgen, input_dict_1) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_2 = { "r1": { @@ -483,81 +461,50 @@ def config_for_as_path(tgen, topo, tc_name): { "action": "permit", "seq_id": 10, - "match": { - "ipv4": { - "prefix_lists": "pf_list_1" - } - }, + "match": {"ipv4": {"prefix_lists": "pf_list_1"}}, "set": { - "large_community": { - "num": LARGE_COMM["pf_list_1"] - }, - "community": { - "num": STANDARD_COMM["pf_list_1"] - } - } + "large_community": {"num": LARGE_COMM["pf_list_1"]}, + "community": {"num": STANDARD_COMM["pf_list_1"]}, + }, }, { "action": "permit", "seq_id": 20, - "match": { - "ipv6": { - "prefix_lists": "pf_list_3" - } - }, + "match": {"ipv6": {"prefix_lists": "pf_list_3"}}, "set": { - "large_community": { - "num": LARGE_COMM["pf_list_1"] - }, - "community": { - "num": STANDARD_COMM["pf_list_1"] - } - } + "large_community": {"num": LARGE_COMM["pf_list_1"]}, + "community": {"num": STANDARD_COMM["pf_list_1"]}, + }, }, { "action": "permit", "seq_id": 30, - "match": { - "ipv4": { - "prefix_lists": "pf_list_2" - } - }, + "match": {"ipv4": {"prefix_lists": "pf_list_2"}}, "set": { - "large_community": { - "num": LARGE_COMM["pf_list_2"] - }, - "community": { - "num": STANDARD_COMM["pf_list_2"] - } - } + "large_community": {"num": LARGE_COMM["pf_list_2"]}, + "community": {"num": STANDARD_COMM["pf_list_2"]}, + }, }, { "action": "permit", "seq_id": 40, - "match": { - "ipv6": { - "prefix_lists": "pf_list_4" - } - }, + "match": {"ipv6": {"prefix_lists": "pf_list_4"}}, "set": { - "large_community": { - "num": LARGE_COMM["pf_list_2"] - }, - "community": { - "num": STANDARD_COMM["pf_list_2"] - } - } - } + "large_community": {"num": LARGE_COMM["pf_list_2"]}, + "community": {"num": STANDARD_COMM["pf_list_2"]}, + }, + }, ] } } } - step("Applying prefix-lists match in route-map LC1 on r1. Setting" - " community attritbute for filtered networks") + step( + "Applying prefix-lists match in route-map LC1 on r1. Setting" + " community attritbute for filtered networks" + ) result = create_route_maps(tgen, input_dict_2) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) config_router_additive(tgen, topo, tc_name) @@ -569,22 +516,21 @@ def config_for_as_path(tgen, topo, tc_name): "action": "permit", "name": "ANY", "value": LARGE_COMM["pf_list_1"], - "large": True + "large": True, }, { "community_type": "standard", "action": "permit", "name": "ANY", "value": STANDARD_COMM["pf_list_1"], - } + }, ] } } step("Configuring bgp community lists on r4") result = create_bgp_community_lists(tgen, input_dict_3) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_4 = { "r4": { @@ -595,14 +541,9 @@ def config_for_as_path(tgen, topo, tc_name): "seq_id": "10", "match": { "large_community_list": {"id": "ANY"}, - "community_list": {"id": "ANY"} + "community_list": {"id": "ANY"}, }, - "set": { - "path": { - "as_num": "4000000", - "as_action": "prepend" - } - } + "set": {"path": {"as_num": "4000000", "as_action": "prepend"}}, } ] } @@ -611,8 +552,7 @@ def config_for_as_path(tgen, topo, tc_name): step("Applying community list on route-map on r4") result = create_route_maps(tgen, input_dict_4) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_5 = { "r4": { @@ -624,10 +564,9 @@ def config_for_as_path(tgen, topo, tc_name): "r5": { "dest_link": { "r4-link1": { - "route_maps": [{ - "name": "LC4", - "direction": "out" - }] + "route_maps": [ + {"name": "LC4", "direction": "out"} + ] } } } @@ -640,16 +579,15 @@ def config_for_as_path(tgen, topo, tc_name): "r5": { "dest_link": { "r4-link1": { - "route_maps": [{ - "name": "LC4", - "direction": "out" - }] + "route_maps": [ + {"name": "LC4", "direction": "out"} + ] } } } } } - } + }, } } } @@ -657,8 +595,7 @@ def config_for_as_path(tgen, topo, tc_name): step("Applying route-map LC4 out from r4 to r5 ") result = create_router_bgp(tgen, topo, input_dict_5) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) ##################################################### @@ -690,8 +627,8 @@ def test_large_community_set(request): "seq_id": "10", "set": { "large_community": {"num": LARGE_COMM["r1"]}, - "community": {"num": STANDARD_COMM["r1"]} - } + "community": {"num": STANDARD_COMM["r1"]}, + }, } ] } @@ -700,8 +637,7 @@ def test_large_community_set(request): step("Trying to set bgp communities") result = create_route_maps(tgen, input_dict) - assert result is True, "Test case {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -728,15 +664,15 @@ def test_large_community_advertise(request): } for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, "r2", [NETWORK[adt][0]], - input_dict) + result = verify_bgp_community(tgen, adt, "r2", [NETWORK[adt][0]], input_dict) assert result is True, "Test case {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) - result = verify_bgp_community(tgen, adt, "r3", [NETWORK[adt][0]], - input_dict) + result = verify_bgp_community(tgen, adt, "r3", [NETWORK[adt][0]], input_dict) assert result is True, "Test case {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -759,14 +695,14 @@ def test_large_community_transitive(request): input_dict_1 = { "largeCommunity": LARGE_COMM["r1"], - "community": STANDARD_COMM["r1"] + "community": STANDARD_COMM["r1"], } for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], - input_dict_1) + result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], input_dict_1) assert result is True, "Test case {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -790,14 +726,14 @@ def test_large_community_override(request): input_dict_3 = { "largeCommunity": LARGE_COMM["r2"], - "community": STANDARD_COMM["r2"] + "community": STANDARD_COMM["r2"], } for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][1]], - input_dict_3) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][1]], input_dict_3) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) write_test_footer(tc_name) @@ -823,14 +759,14 @@ def test_large_community_additive(request): input_dict_1 = { "largeCommunity": "%s %s" % (LARGE_COMM["r1"], LARGE_COMM["r2"]), - "community": "%s %s" % (STANDARD_COMM["r1"], STANDARD_COMM["r2"]) + "community": "%s %s" % (STANDARD_COMM["r1"], STANDARD_COMM["r2"]), } for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], - input_dict_1) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], input_dict_1) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) write_test_footer(tc_name) @@ -853,30 +789,28 @@ def test_large_community_match_as_path(request): config_for_as_path(tgen, topo, tc_name) input_dict = { - "largeCommunity": "%s %s" % ( - LARGE_COMM["pf_list_1"], LARGE_COMM["r2"]), - "community": "%s %s" % ( - STANDARD_COMM["pf_list_1"], STANDARD_COMM["r2"]), + "largeCommunity": "%s %s" % (LARGE_COMM["pf_list_1"], LARGE_COMM["r2"]), + "community": "%s %s" % (STANDARD_COMM["pf_list_1"], STANDARD_COMM["r2"]), } input_dict_1 = { - "largeCommunity": "%s %s" % ( - LARGE_COMM["pf_list_2"], LARGE_COMM["r2"]), - "community": "%s %s" % ( - STANDARD_COMM["pf_list_2"], STANDARD_COMM["r2"]), + "largeCommunity": "%s %s" % (LARGE_COMM["pf_list_2"], LARGE_COMM["r2"]), + "community": "%s %s" % (STANDARD_COMM["pf_list_2"], STANDARD_COMM["r2"]), } for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, "r5", [NETWORK[adt][0]], - input_dict) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_community(tgen, adt, "r5", [NETWORK[adt][0]], input_dict) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) - result = verify_bgp_community(tgen, adt, "r5", [NETWORK[adt][1]], - input_dict_1, expected=False) + result = verify_bgp_community( + tgen, adt, "r5", [NETWORK[adt][1]], input_dict_1, expected=False + ) - assert result is not True, "Test case {} : Should fail \n Error: {}". \ - format(tc_name, result) + assert result is not True, "Test case {} : Should fail \n Error: {}".format( + tc_name, result + ) write_test_footer(tc_name) @@ -909,22 +843,22 @@ def test_large_community_match_all(request): "action": "permit", "name": "ANY", "value": "1:1:1", - "large": True + "large": True, }, { "community_type": "standard", "action": "permit", "name": "ALL", "value": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1 2:1:1 2:2:1", - "large": True + "large": True, }, { "community_type": "expanded", "action": "permit", "name": "EXP_ALL", "value": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1 2:[1-5]:1", - "large": True - } + "large": True, + }, ] } } @@ -932,8 +866,7 @@ def test_large_community_match_all(request): step("Create bgp community lists for ANY, EXACT and EXP_ALL match") result = create_bgp_community_lists(tgen, input_dict_1) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_2 = { "r4": { @@ -942,18 +875,18 @@ def test_large_community_match_all(request): { "action": "permit", "seq_id": "10", - "match": {"large-community-list": {"id": "ANY"}} + "match": {"large-community-list": {"id": "ANY"}}, }, { "action": "permit", "seq_id": "20", - "match": {"large-community-list": {"id": "EXACT"}} + "match": {"large-community-list": {"id": "EXACT"}}, }, { "action": "permit", "seq_id": "30", - "match": {"large-community-list": {"id": "EXP_ALL"}} - } + "match": {"large-community-list": {"id": "EXP_ALL"}}, + }, ] } } @@ -961,8 +894,7 @@ def test_large_community_match_all(request): step("Applying bgp community lits on LC4 route-map") result = create_route_maps(tgen, input_dict_2) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_3 = { "r4": { @@ -974,10 +906,9 @@ def test_large_community_match_all(request): "r5": { "dest_link": { "r4-link1": { - "route_maps": [{ - "name": "LC4", - "direction": "in" - }] + "route_maps": [ + {"name": "LC4", "direction": "in"} + ] } } } @@ -990,16 +921,15 @@ def test_large_community_match_all(request): "r5": { "dest_link": { "r4-link1": { - "route_maps": [{ - "name": "LC4", - "direction": "in" - }] + "route_maps": [ + {"name": "LC4", "direction": "in"} + ] } } } } } - } + }, } } } @@ -1008,24 +938,23 @@ def test_large_community_match_all(request): step("Apply route-mpa LC4 on r4 for r2 neighbor, direction 'in'") result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_4 = { "largeCommunity": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1 2:1:1 2:2:1 2:3:1 " - "2:4:1 2:5:1" + "2:4:1 2:5:1" } for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], - input_dict_4) - assert result is True, "Test case {} : Should fail \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], input_dict_4) + assert result is True, "Test case {} : Should fail \n Error: {}".format( + tc_name, result + ) write_test_footer(tc_name) -#@pytest.mark.skip(reason="as-set not working for ipv6") +# @pytest.mark.skip(reason="as-set not working for ipv6") def test_large_community_aggregate_network(request): """ Restart router and check if large community and community @@ -1047,7 +976,7 @@ def test_large_community_aggregate_network(request): input_dict = { "community": STANDARD_COMM["agg_1"], - "largeCommunity": LARGE_COMM["agg_1"] + "largeCommunity": LARGE_COMM["agg_1"], } input_dict_1 = { @@ -1058,9 +987,9 @@ def test_large_community_aggregate_network(request): "unicast": { "aggregate_address": [ { - "network": "%s/%s" % ( - NETWORK["ipv4"][2], NET_MASK["ipv4"]), - "as_set": True + "network": "%s/%s" + % (NETWORK["ipv4"][2], NET_MASK["ipv4"]), + "as_set": True, } ] } @@ -1069,13 +998,13 @@ def test_large_community_aggregate_network(request): "unicast": { "aggregate_address": [ { - "network": "%s/%s" % ( - NETWORK["ipv6"][2], NET_MASK["ipv6"]), - "as_set": True + "network": "%s/%s" + % (NETWORK["ipv6"][2], NET_MASK["ipv6"]), + "as_set": True, } ] } - } + }, } } } @@ -1083,16 +1012,15 @@ def test_large_community_aggregate_network(request): step("Configuring aggregate address as-set on r2") result = create_router_bgp(tgen, topo, input_dict_1) - assert result is True, "Test case {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, "r4", - ["%s/%s" % (NETWORK[adt][2], - NET_MASK[adt])], - input_dict) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_community( + tgen, adt, "r4", ["%s/%s" % (NETWORK[adt][2], NET_MASK[adt])], input_dict + ) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) input_dict_2 = { "r1": { @@ -1102,10 +1030,10 @@ def test_large_community_aggregate_network(request): "unicast": { "advertise_networks": [ { - "network": "%s/%s" % ( - NETWORK["ipv4"][0], MASK["ipv4"]), + "network": "%s/%s" + % (NETWORK["ipv4"][0], MASK["ipv4"]), "no_of_network": 1, - "delete": True + "delete": True, } ] } @@ -1114,14 +1042,14 @@ def test_large_community_aggregate_network(request): "unicast": { "advertise_networks": [ { - "network": "%s/%s" % ( - NETWORK["ipv6"][0], MASK["ipv6"]), + "network": "%s/%s" + % (NETWORK["ipv6"][0], MASK["ipv6"]), "no_of_network": 1, - "delete": True + "delete": True, } ] } - } + }, } } } @@ -1129,22 +1057,21 @@ def test_large_community_aggregate_network(request): step("Stop advertising one of the networks") result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Test case {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_3 = { "community": STANDARD_COMM["agg_2"], - "largeCommunity": LARGE_COMM["agg_2"] + "largeCommunity": LARGE_COMM["agg_2"], } for adt in ADDR_TYPES: step("Verifying bgp community values on r5 is also modified") - result = verify_bgp_community(tgen, adt, "r4", - ["%s/%s" % (NETWORK[adt][2], - NET_MASK[adt])], - input_dict_3) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_community( + tgen, adt, "r4", ["%s/%s" % (NETWORK[adt][2], NET_MASK[adt])], input_dict_3 + ) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) write_test_footer(tc_name) @@ -1168,7 +1095,7 @@ def test_large_community_boundary_values(request): "community_type": "standard", "action": "permit", "name": "ANY", - "value": "0:-1" + "value": "0:-1", } ] } @@ -1176,8 +1103,9 @@ def test_large_community_boundary_values(request): step("Checking boundary value for community 0:-1") result = create_bgp_community_lists(tgen, input_dict) - assert result is not True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is not True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) step("Checking community attribute 0:65536") input_dict_2 = { @@ -1187,7 +1115,7 @@ def test_large_community_boundary_values(request): "community_type": "standard", "action": "permit", "name": "ANY", - "value": "0:65536" + "value": "0:65536", } ] } @@ -1195,8 +1123,9 @@ def test_large_community_boundary_values(request): step("Checking boundary value for community 0:65536") result = create_bgp_community_lists(tgen, input_dict_2) - assert result is not True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is not True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) step("Checking boundary value for community 0:4294967296") input_dict_3 = { @@ -1207,15 +1136,16 @@ def test_large_community_boundary_values(request): "action": "permit", "name": "ANY", "value": "0:4294967296", - "large": True + "large": True, } ] } } result = create_bgp_community_lists(tgen, input_dict_3) - assert result is not True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is not True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) step("Checking boundary value for community 0:-1:1") input_dict_4 = { @@ -1226,15 +1156,16 @@ def test_large_community_boundary_values(request): "action": "permit", "name": "ANY", "value": "0:-1:1", - "large": True + "large": True, } ] } } result = create_bgp_community_lists(tgen, input_dict_4) - assert result is not True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + assert result is not True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) def test_large_community_after_clear_bgp(request): @@ -1253,25 +1184,22 @@ def test_large_community_after_clear_bgp(request): reset_config_on_routers(tgen) config_router_r1(tgen, topo, tc_name) - input_dict = { - "largeCommunity": LARGE_COMM["r1"], - "community": STANDARD_COMM["r1"] - } + input_dict = {"largeCommunity": LARGE_COMM["r1"], "community": STANDARD_COMM["r1"]} for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, "r2", [NETWORK[adt][0]], - input_dict) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_community(tgen, adt, "r2", [NETWORK[adt][0]], input_dict) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) step("Clearing BGP on r1") clear_bgp_and_verify(tgen, topo, "r1") for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, "r2", [NETWORK[adt][0]], - input_dict) - assert result is True, "Test case {} : Failed \n Error: {}". \ - format(tc_name, result) + result = verify_bgp_community(tgen, adt, "r2", [NETWORK[adt][0]], input_dict) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) write_test_footer(tc_name) diff --git a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py index cba20551cd..502a9a9ec4 100755 --- a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py +++ b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py @@ -3,7 +3,7 @@ # # Copyright (c) 2019 by VMware, Inc. ("VMware") # Used Copyright (c) 2018 by Network Device Education Foundation, -#Inc. ("NetDEF") in this file. +# Inc. ("NetDEF") in this file. # # Permission to use, copy, modify, and/or distribute this software # for any purpose with or without fee is hereby granted, provided @@ -77,19 +77,23 @@ from lib.topogen import Topogen, get_topogen from mininet.topo import Topo from lib.common_config import ( - start_topology, write_test_header, - write_test_footer, reset_config_on_routers, - create_route_maps, create_bgp_community_lists, - create_prefix_lists, verify_bgp_community, step, - verify_create_community_list, delete_route_maps, - verify_route_maps, create_static_routes, - check_address_types + start_topology, + write_test_header, + write_test_footer, + reset_config_on_routers, + create_route_maps, + create_bgp_community_lists, + create_prefix_lists, + verify_bgp_community, + step, + verify_create_community_list, + delete_route_maps, + verify_route_maps, + create_static_routes, + check_address_types, ) from lib.topolog import logger -from lib.bgp import ( - verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify -) +from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify from lib.topojson import build_topo_from_json, build_config_from_json # Reading the data from JSON File for topology and configuration creation @@ -121,6 +125,7 @@ class GenerateTopo(Topo): # Building topology from json file build_topo_from_json(tgen, topo) + def setup_module(mod): """ Sets up the pytest environment @@ -130,7 +135,7 @@ def setup_module(mod): testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) - logger.info("="*40) + logger.info("=" * 40) logger.info("Running setup_module to create topology") @@ -155,8 +160,9 @@ def setup_module(mod): # Api call verify whether BGP is converged # Ipv4 bgp_convergence = verify_bgp_convergence(tgen, topo) - assert bgp_convergence is True, ("setup_module :Failed \n Error:" - " {}".format(bgp_convergence)) + assert bgp_convergence is True, "setup_module :Failed \n Error:" " {}".format( + bgp_convergence + ) ADDR_TYPES = check_address_types() logger.info("Running setup_module() done") @@ -176,9 +182,11 @@ def teardown_module(mod): # Stop toplogy and Remove tmp files tgen.stop_topology() - logger.info("Testsuite end time: {}".\ - format(time.asctime(time.localtime(time.time())))) - logger.info("="*40) + logger.info( + "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) + ) + logger.info("=" * 40) + ##################################################### # @@ -213,26 +221,24 @@ def test_create_bgp_standard_large_community_list(request): "action": "permit", "name": "LC_1_STD", "value": "2:1:1 2:1:2 1:2:3", - "large": True + "large": True, }, { "community_type": "standard", "action": "permit", "name": "LC_2_STD", "value": "3:1:1 3:1:2", - "large": True - } + "large": True, + }, ] } } result = create_bgp_community_lists(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify BGP large community is created") result = verify_create_community_list(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create srtandard large community list with in-correct values") input_dict = { @@ -243,20 +249,18 @@ def test_create_bgp_standard_large_community_list(request): "action": "permit", "name": "LC_1_STD_ERR", "value": "0:0:0", - "large": True + "large": True, } ] } } result = create_bgp_community_lists(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) ## TODO should fail step("Verify BGP large community is created") result = verify_create_community_list(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -288,19 +292,17 @@ def test_create_bgp_expanded_large_community_list(request): "action": "permit", "name": "LC_1_EXP", "value": "1:1:200 1:2:* 3:2:1", - "large": True + "large": True, } ] } } result = create_bgp_community_lists(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify BGP large community is created") result = verify_create_community_list(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) @@ -331,14 +333,13 @@ def test_modify_large_community_lists_referenced_by_rmap(request): "action": "permit", "name": "LC_DEL", "value": "1:2:1 1:3:1 2:1:1 2:2:2 3:3:3", - "large": True + "large": True, } ] } } result = create_bgp_community_lists(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create route map") input_dict_2 = { @@ -351,9 +352,9 @@ def test_modify_large_community_lists_referenced_by_rmap(request): "set": { "large_community": { "num": "1:2:1 1:3:1 2:10:1 3:3:3 4:4:4 5:5:5", - "action": "additive" + "action": "additive", } - } + }, } ] } @@ -364,20 +365,14 @@ def test_modify_large_community_lists_referenced_by_rmap(request): { "action": "permit", "seq_id": "10", - "set": { - "large_comm_list": { - "id": "LC_DEL", - "delete": True - } - } + "set": {"large_comm_list": {"id": "LC_DEL", "delete": True}}, } ] } - } + }, } result = create_route_maps(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map and advertise networks") input_dict_3 = { @@ -386,42 +381,42 @@ def test_modify_large_community_lists_referenced_by_rmap(request): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [ - {"network": "200.50.2.0/32"} - ], + "advertise_networks": [{"network": "200.50.2.0/32"}], "neighbor": { "r2": { "dest_link": { "r1": { - "route_maps": [{ - "name": "RM_R2_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R2_OUT", + "direction": "out", + } + ] } } } - } + }, } }, "ipv6": { "unicast": { - "advertise_networks": [ - {"network": "1::1/128"} - ], + "advertise_networks": [{"network": "1::1/128"}], "neighbor": { "r2": { "dest_link": { "r1": { - "route_maps": [{ - "name": "RM_R2_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R2_OUT", + "direction": "out", + } + ] } } } - } + }, } - } + }, } } }, @@ -434,10 +429,9 @@ def test_modify_large_community_lists_referenced_by_rmap(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } @@ -450,35 +444,31 @@ def test_modify_large_community_lists_referenced_by_rmap(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify Community-list") dut = "r4" - input_dict_4 = { - "largeCommunity": "2:10:1 4:4:4 5:5:5" - } + input_dict_4 = {"largeCommunity": "2:10:1 4:4:4 5:5:5"} for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - input_dict_4) + result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -511,17 +501,16 @@ def test_large_community_lists_with_rmap_apply_and_remove(request): "set": { "large_community": { "num": "200:200:1 200:200:10 200:200:20000", - "action": "additive" + "action": "additive", } - } + }, } ] } } } result = create_route_maps(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map and advertise networks") input_dict_2 = { @@ -530,18 +519,12 @@ def test_large_community_lists_with_rmap_apply_and_remove(request): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [ - {"network": "200.50.2.0/32"} - ] + "advertise_networks": [{"network": "200.50.2.0/32"}] } }, "ipv6": { - "unicast": { - "advertise_networks": [ - {"network": "1::1/128"} - ] - } - } + "unicast": {"advertise_networks": [{"network": "1::1/128"}]} + }, } } }, @@ -554,10 +537,9 @@ def test_large_community_lists_with_rmap_apply_and_remove(request): "r6": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_LC1", - "direction": "out" - }] + "route_maps": [ + {"name": "RM_LC1", "direction": "out"} + ] } } } @@ -570,57 +552,49 @@ def test_large_community_lists_with_rmap_apply_and_remove(request): "r6": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_LC1", - "direction": "out" - }] + "route_maps": [ + {"name": "RM_LC1", "direction": "out"} + ] } } } } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify large-community-list") dut = "r6" - input_dict_4 = { - "largeCommunity": "200:200:1 200:200:10 200:200:20000" - } + input_dict_4 = {"largeCommunity": "200:200:1 200:200:10 200:200:20000"} for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - input_dict_4) + result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) step("Delete route map reference by community-list") - input_dict_3 = { - "r4": { - "route_maps": ["RM_LC1"] - } - } + input_dict_3 = {"r4": {"route_maps": ["RM_LC1"]}} result = delete_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify route map is deleted") result = verify_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify large-community-list") for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - input_dict_4, expected=False) + result = verify_bgp_community( + tgen, adt, dut, NETWORKS[adt], input_dict_4, expected=False + ) assert result is not True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -653,10 +627,10 @@ def test_duplicate_large_community_list_attributes_not_transitive(request): "set": { "large_community": { "num": "0:0:1 0:0:10 0:0:100 2:0:1 2:0:2 2:0:3" - " 2:0:4 2:0:5", - "action": "additive" + " 2:0:4 2:0:5", + "action": "additive", } - } + }, } ], "RM_R4_OUT": [ @@ -666,17 +640,16 @@ def test_duplicate_large_community_list_attributes_not_transitive(request): "set": { "large_community": { "num": "0:0:1 0:0:10 0:0:10000 2:0:1 2:0:2", - "action": "additive" + "action": "additive", } - } + }, } - ] + ], } } } result = create_route_maps(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map and advertise networks") input_dict_2 = { @@ -685,18 +658,12 @@ def test_duplicate_large_community_list_attributes_not_transitive(request): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [ - {"network": "200.50.2.0/32"} - ] + "advertise_networks": [{"network": "200.50.2.0/32"}] } }, "ipv6": { - "unicast": { - "advertise_networks": [ - {"network": "1::1/128"} - ] - } - } + "unicast": {"advertise_networks": [{"network": "1::1/128"}]} + }, } } }, @@ -709,23 +676,24 @@ def test_duplicate_large_community_list_attributes_not_transitive(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } }, "r6": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R4_OUT", + "direction": "out", + } + ] } } - } + }, } } }, @@ -735,45 +703,44 @@ def test_duplicate_large_community_list_attributes_not_transitive(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } }, "r6": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R4_OUT", + "direction": "out", + } + ] } } - } + }, } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify large-community-list") dut = "r6" input_dict_4 = { - "largeCommunity": - "0:0:1 0:0:10 0:0:100 0:0:10000 2:0:1 2:0:2 2:0:3 2:0:4 2:0:5" + "largeCommunity": "0:0:1 0:0:10 0:0:100 0:0:10000 2:0:1 2:0:2 2:0:3 2:0:4 2:0:5" } for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - input_dict_4) + result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -806,10 +773,10 @@ def test_large_community_lists_with_rmap_set_none(request): "set": { "large_community": { "num": "0:0:1 0:0:10 0:0:100 2:0:1 2:0:2 2:0:3" - " 2:0:4", - "action": "additive" + " 2:0:4", + "action": "additive", } - } + }, } ] } @@ -820,19 +787,14 @@ def test_large_community_lists_with_rmap_set_none(request): { "action": "permit", "seq_id": "10", - "set": { - "large_community": { - "num": "none" - } - } + "set": {"large_community": {"num": "none"}}, } ] } - } + }, } result = create_route_maps(tgen, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map") input_dict_2 = { @@ -841,18 +803,12 @@ def test_large_community_lists_with_rmap_set_none(request): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [ - {"network": "200.50.2.0/32"} - ] + "advertise_networks": [{"network": "200.50.2.0/32"}] } }, "ipv6": { - "unicast": { - "advertise_networks": [ - {"network": "1::1/128"} - ] - } - } + "unicast": {"advertise_networks": [{"network": "1::1/128"}]} + }, } } }, @@ -865,10 +821,9 @@ def test_large_community_lists_with_rmap_set_none(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } @@ -881,16 +836,15 @@ def test_large_community_lists_with_rmap_set_none(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } } } - } + }, } } }, @@ -903,10 +857,9 @@ def test_large_community_lists_with_rmap_set_none(request): "r4": { "dest_link": { "r6": { - "route_maps": [{ - "name": "RM_R6_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R6_IN", "direction": "in"} + ] } } } @@ -919,31 +872,29 @@ def test_large_community_lists_with_rmap_set_none(request): "r4": { "dest_link": { "r6": { - "route_maps": [{ - "name": "RM_R6_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R6_IN", "direction": "in"} + ] } } } } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify Community-list") dut = "r6" for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - expected=False) + result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -969,24 +920,17 @@ def test_lcomm_lists_with_redistribute_static_connected_rmap(request): input_dict = { "r1": { "static_routes": [ - { - "network": "200.50.2.0/32", - "next_hop": "10.0.0.6" - }, - { - "network": "1::1/128", - "next_hop": "fd00:0:0:1::2" - } + {"network": "200.50.2.0/32", "next_hop": "10.0.0.6"}, + {"network": "1::1/128", "next_hop": "fd00:0:0:1::2"}, ] } } result = create_static_routes(tgen, input_dict) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("redistribute static routes") input_dict_1 = { - "r1":{ + "r1": { "bgp": { "address_family": { "ipv4": { @@ -994,12 +938,12 @@ def test_lcomm_lists_with_redistribute_static_connected_rmap(request): "redistribute": [ { "redist_type": "static", - "attribute": "route-map RM_R2_OUT" + "attribute": "route-map RM_R2_OUT", }, { "redist_type": "connected", - "attribute": "route-map RM_R2_OUT" - } + "attribute": "route-map RM_R2_OUT", + }, ] } }, @@ -1008,82 +952,74 @@ def test_lcomm_lists_with_redistribute_static_connected_rmap(request): "redistribute": [ { "redist_type": "static", - "attribute": "route-map RM_R2_OUT" + "attribute": "route-map RM_R2_OUT", }, { "redist_type": "connected", - "attribute": "route-map RM_R2_OUT" - } + "attribute": "route-map RM_R2_OUT", + }, ] } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_1) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create route map") input_dict_3 = { "r1": { "route_maps": { - "RM_R2_OUT": [{ - "action": "permit", - "set": { - "large_community": {"num":"55:55:55 555:555:555"} - } - }] + "RM_R2_OUT": [ + { + "action": "permit", + "set": {"large_community": {"num": "55:55:55 555:555:555"}}, + } + ] } - } + } } result = create_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) - step("Verify large-community-list for static and connected ipv4 route on" - " r2") + step("Verify large-community-list for static and connected ipv4 route on" " r2") - input_dict_5 = { - "largeCommunity": "55:55:55 555:555:555" - } + input_dict_5 = {"largeCommunity": "55:55:55 555:555:555"} if "ipv4" in ADDR_TYPES: dut = "r2" networks = ["200.50.2.0/32", "1.0.1.17/32"] - result = verify_bgp_community(tgen, "ipv4", dut, networks, - input_dict_5) + result = verify_bgp_community(tgen, "ipv4", dut, networks, input_dict_5) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) - step("Verify large-community-list for static and connected ipv4 route" - " on r4") + step("Verify large-community-list for static and connected ipv4 route" " on r4") dut = "r4" networks = ["200.50.2.0/32", "1.0.1.17/32"] - result = verify_bgp_community(tgen, "ipv4", dut, networks, - input_dict_5) + result = verify_bgp_community(tgen, "ipv4", dut, networks, input_dict_5) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) if "ipv6" in ADDR_TYPES: - step("Verify large-community-list for static and connected ipv6 route" - " on r2") + step("Verify large-community-list for static and connected ipv6 route" " on r2") dut = "r2" networks = ["1::1/128", "2001:db8:f::1:17/128"] - result = verify_bgp_community(tgen, "ipv6", dut, networks, - input_dict_5) + result = verify_bgp_community(tgen, "ipv6", dut, networks, input_dict_5) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) - step("Verify large-community-list for static and connected ipv6 route" - " on r4") + step("Verify large-community-list for static and connected ipv6 route" " on r4") dut = "r4" networks = ["1::1/128", "2001:db8:f::1:17/128"] - result = verify_bgp_community(tgen, "ipv6", dut, networks, - input_dict_5) + result = verify_bgp_community(tgen, "ipv6", dut, networks, input_dict_5) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -1115,14 +1051,13 @@ def test_large_community_lists_with_rmap_set_delete(request): "action": "permit", "name": "Test", "value": "1:2:1 1:1:10 1:3:100", - "large": True + "large": True, } ] } } result = create_bgp_community_lists(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create route map") input_dict_3 = { @@ -1132,12 +1067,7 @@ def test_large_community_lists_with_rmap_set_delete(request): { "action": "permit", "seq_id": "10", - "set": { - "large_comm_list": { - "id": "Test", - "delete": True - } - } + "set": {"large_comm_list": {"id": "Test", "delete": True}}, } ] } @@ -1151,18 +1081,17 @@ def test_large_community_lists_with_rmap_set_delete(request): "set": { "large_community": { "num": "1:2:1 1:1:10 1:3:100 2:1:1 2:2:2 2:3:3" - " 2:4:4 2:5:5", - "action": "additive" + " 2:4:4 2:5:5", + "action": "additive", } - } + }, } ] } - } + }, } result = create_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map and advertise networks") input_dict_4 = { @@ -1171,18 +1100,12 @@ def test_large_community_lists_with_rmap_set_delete(request): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [ - {"network": "200.50.2.0/32"} - ] + "advertise_networks": [{"network": "200.50.2.0/32"}] } }, "ipv6": { - "unicast": { - "advertise_networks": [ - {"network": "1::1/128"} - ] - } - } + "unicast": {"advertise_networks": [{"network": "1::1/128"}]} + }, } } }, @@ -1195,10 +1118,9 @@ def test_large_community_lists_with_rmap_set_delete(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } @@ -1211,16 +1133,15 @@ def test_large_community_lists_with_rmap_set_delete(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } } } - } + }, } } }, @@ -1233,10 +1154,9 @@ def test_large_community_lists_with_rmap_set_delete(request): "r4": { "dest_link": { "r6": { - "route_maps": [{ - "name": "RM_R6_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R6_IN", "direction": "in"} + ] } } } @@ -1249,34 +1169,30 @@ def test_large_community_lists_with_rmap_set_delete(request): "r4": { "dest_link": { "r6": { - "route_maps": [{ - "name": "RM_R6_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R6_IN", "direction": "in"} + ] } } } } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify large-community-list") dut = "r6" - input_dict_5 = { - "largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5" - } + input_dict_5 = {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - input_dict_5) + result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_5) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -1308,18 +1224,15 @@ def test_large_community_lists_with_no_send_community(request): "action": "permit", "seq_id": "10", "set": { - "large_community": { - "num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5" - } - } + "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} + }, } ] } } } result = create_route_maps(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map and advertise networks") input_dict_3 = { @@ -1328,18 +1241,12 @@ def test_large_community_lists_with_no_send_community(request): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [ - {"network": "200.50.2.0/32"} - ] + "advertise_networks": [{"network": "200.50.2.0/32"}] } }, "ipv6": { - "unicast": { - "advertise_networks": [ - {"network": "1::1/128"} - ] - } - } + "unicast": {"advertise_networks": [{"network": "1::1/128"}]} + }, } } }, @@ -1352,10 +1259,12 @@ def test_large_community_lists_with_no_send_community(request): "r6": { "dest_link": { "r5": { - "route_maps": [{ - "name": "RM_R6_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R6_OUT", + "direction": "out", + } + ] } } } @@ -1368,34 +1277,33 @@ def test_large_community_lists_with_no_send_community(request): "r6": { "dest_link": { "r5": { - "route_maps": [{ - "name": "RM_R6_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R6_OUT", + "direction": "out", + } + ] } } } } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify large-community-list") dut = "r6" - input_dict_4 = { - "largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5" - } + input_dict_4 = {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - input_dict_4) + result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) step("Configure neighbor for no-send-community") input_dict_5 = { @@ -1406,11 +1314,7 @@ def test_large_community_lists_with_no_send_community(request): "unicast": { "neighbor": { "r6": { - "dest_link": { - "r5": { - "no_send_community": "large" - } - } + "dest_link": {"r5": {"no_send_community": "large"}} } } } @@ -1419,29 +1323,26 @@ def test_large_community_lists_with_no_send_community(request): "unicast": { "neighbor": { "r6": { - "dest_link": { - "r5": { - "no_send_community": "large" - } - } + "dest_link": {"r5": {"no_send_community": "large"}} } } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_5) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify Community-list") for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - input_dict_4, expected=False) + result = verify_bgp_community( + tgen, adt, dut, NETWORKS[adt], input_dict_4, expected=False + ) assert result is not True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -1472,14 +1373,15 @@ def test_create_large_community_lists_with_no_attribute_values(request): "community_type": "standard", "action": "permit", "name": "Test1", - "large": True + "large": True, } ] } } result = create_bgp_community_lists(tgen, input_dict_1) assert result is not True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -1512,18 +1414,15 @@ def test_large_community_lists_with_rmap_match_exact(request): "action": "permit", "seq_id": "10", "set": { - "large_community": { - "num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5" - } - } + "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} + }, } ] } } } result = create_route_maps(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map and advertise networks") input_dict_3 = { @@ -1532,18 +1431,12 @@ def test_large_community_lists_with_rmap_match_exact(request): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [ - {"network": "200.50.2.0/32"} - ] + "advertise_networks": [{"network": "200.50.2.0/32"}] } }, "ipv6": { - "unicast": { - "advertise_networks": [ - {"network": "1::1/128"} - ] - } - } + "unicast": {"advertise_networks": [{"network": "1::1/128"}]} + }, } } }, @@ -1556,10 +1449,12 @@ def test_large_community_lists_with_rmap_match_exact(request): "r4": { "dest_link": { "r2": { - "route_maps": [{ - "name": "RM_R4_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R4_OUT", + "direction": "out", + } + ] } } } @@ -1572,24 +1467,25 @@ def test_large_community_lists_with_rmap_match_exact(request): "r4": { "dest_link": { "r2": { - "route_maps": [{ - "name": "RM_R4_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R4_OUT", + "direction": "out", + } + ] } } } } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create standard large commumity-list") input_dict_4 = { @@ -1600,19 +1496,17 @@ def test_large_community_lists_with_rmap_match_exact(request): "action": "permit", "name": "EXACT", "value": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5", - "large": True + "large": True, } ] } } result = create_bgp_community_lists(tgen, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify BGP large community is created") result = verify_create_community_list(tgen, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create route map") input_dict_5 = { @@ -1624,16 +1518,15 @@ def test_large_community_lists_with_rmap_match_exact(request): "seq_id": "10", "match": { "large-community-list": ["EXACT"], - "match_exact": True - } + "match_exact": True, + }, } ] } } } result = create_route_maps(tgen, input_dict_5) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map") input_dict_6 = { @@ -1646,10 +1539,9 @@ def test_large_community_lists_with_rmap_match_exact(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } @@ -1662,34 +1554,30 @@ def test_large_community_lists_with_rmap_match_exact(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_6) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify large-community-list") dut = "r4" - input_dict_4 = { - "largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5" - } + input_dict_4 = {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - input_dict_4) + result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -1718,20 +1606,21 @@ def test_large_community_lists_with_rmap_match_all(request): input_dict_2 = { "r2": { "route_maps": { - "RM_R4_OUT": [{ - "action": "permit", - "set": { - "large_community": { - "num": "1:1:1 1:2:3 2:1:1 2:2:2 2:3:3 2:4:4 2:5:5" - } + "RM_R4_OUT": [ + { + "action": "permit", + "set": { + "large_community": { + "num": "1:1:1 1:2:3 2:1:1 2:2:2 2:3:3 2:4:4 2:5:5" + } + }, } - }] + ] } } } result = create_route_maps(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map") input_dict_3 = { @@ -1740,18 +1629,12 @@ def test_large_community_lists_with_rmap_match_all(request): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [ - {"network": "200.50.2.0/32"} - ] + "advertise_networks": [{"network": "200.50.2.0/32"}] } }, "ipv6": { - "unicast": { - "advertise_networks": [ - {"network": "1::1/128"} - ] - } - } + "unicast": {"advertise_networks": [{"network": "1::1/128"}]} + }, } } }, @@ -1764,10 +1647,12 @@ def test_large_community_lists_with_rmap_match_all(request): "r4": { "dest_link": { "r2": { - "route_maps": [{ - "name": "RM_R4_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R4_OUT", + "direction": "out", + } + ] } } } @@ -1780,23 +1665,24 @@ def test_large_community_lists_with_rmap_match_all(request): "r4": { "dest_link": { "r2": { - "route_maps": [{ - "name": "RM_R4_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R4_OUT", + "direction": "out", + } + ] } } } } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create standard large commumity-list") input_dict_4 = { @@ -1807,19 +1693,17 @@ def test_large_community_lists_with_rmap_match_all(request): "action": "permit", "name": "ALL", "value": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5", - "large": True + "large": True, } ] } } result = create_bgp_community_lists(tgen, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify BGP large community is created") result = verify_create_community_list(tgen, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create route map") input_dict_5 = { @@ -1829,19 +1713,14 @@ def test_large_community_lists_with_rmap_match_all(request): { "action": "permit", "seq_id": "10", - "match": { - "large-community-list": { - "id": "ALL" - } - } + "match": {"large-community-list": {"id": "ALL"}}, } ] } } } result = create_route_maps(tgen, input_dict_5) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map") input_dict_6 = { @@ -1854,10 +1733,9 @@ def test_large_community_lists_with_rmap_match_all(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } @@ -1870,34 +1748,30 @@ def test_large_community_lists_with_rmap_match_all(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_6) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify large-community-list") dut = "r4" - input_dict_4 = { - "largeCommunity": "1:1:1 1:2:3 2:1:1 2:2:2 2:3:3 2:4:4 2:5:5" - } + input_dict_4 = {"largeCommunity": "1:1:1 1:2:3 2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - input_dict_4) + result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -1929,18 +1803,15 @@ def test_large_community_lists_with_rmap_match_any(request): "action": "permit", "seq_id": "10", "set": { - "large_community": { - "num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5" - } - } + "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} + }, } ] } } } result = create_route_maps(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map") input_dict_3 = { @@ -1949,18 +1820,12 @@ def test_large_community_lists_with_rmap_match_any(request): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [ - {"network": "200.50.2.0/32"} - ] + "advertise_networks": [{"network": "200.50.2.0/32"}] } }, "ipv6": { - "unicast": { - "advertise_networks": [ - {"network": "1::1/128"} - ] - } - } + "unicast": {"advertise_networks": [{"network": "1::1/128"}]} + }, } } }, @@ -1973,10 +1838,12 @@ def test_large_community_lists_with_rmap_match_any(request): "r4": { "dest_link": { "r2": { - "route_maps": [{ - "name": "RM_R4_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R4_OUT", + "direction": "out", + } + ] } } } @@ -1989,23 +1856,24 @@ def test_large_community_lists_with_rmap_match_any(request): "r4": { "dest_link": { "r2": { - "route_maps": [{ - "name": "RM_R4_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R4_OUT", + "direction": "out", + } + ] } } } } } - } + }, } } - } + }, } result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create standard large commumity-list") input_dict_4 = { @@ -2016,40 +1884,38 @@ def test_large_community_lists_with_rmap_match_any(request): "action": "permit", "name": "ANY", "value": "2:1:1", - "large": True + "large": True, }, { "community_type": "standard", "action": "permit", "name": "ANY", "value": "2:2:1", - "large": True + "large": True, }, { "community_type": "standard", "action": "permit", "name": "ANY", "value": "2:3:1", - "large": True + "large": True, }, { "community_type": "standard", "action": "permit", "name": "ANY", "value": "2:4:1", - "large": True - } + "large": True, + }, ] } } result = create_bgp_community_lists(tgen, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify BGP large community is created") result = verify_create_community_list(tgen, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create route map") input_dict_5 = { @@ -2059,19 +1925,14 @@ def test_large_community_lists_with_rmap_match_any(request): { "action": "permit", "seq_id": "10", - "match": { - "large-community-list": { - "id": "ANY" - } - } + "match": {"large-community-list": {"id": "ANY"}}, } ] } } } result = create_route_maps(tgen, input_dict_5) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map") input_dict_6 = { @@ -2084,10 +1945,9 @@ def test_large_community_lists_with_rmap_match_any(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } @@ -2100,34 +1960,30 @@ def test_large_community_lists_with_rmap_match_any(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_6) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify large-community-list") dut = "r4" - input_dict_7 = { - "largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5" - } + input_dict_7 = {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - input_dict_7) + result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) write_test_footer(tc_name) @@ -2162,18 +2018,15 @@ def test_large_community_lists_with_rmap_match_regex(request): "large_community": { "num": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5", }, - "community": { - "num": "1:1 1:2 1:3 1:4 1:5" - } - } + "community": {"num": "1:1 1:2 1:3 1:4 1:5"}, + }, } ] } } } result = create_route_maps(tgen, input_dict_2) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map") input_dict_3 = { @@ -2182,18 +2035,12 @@ def test_large_community_lists_with_rmap_match_regex(request): "address_family": { "ipv4": { "unicast": { - "advertise_networks": [ - {"network": "200.50.2.0/32"} - ] + "advertise_networks": [{"network": "200.50.2.0/32"}] } }, "ipv6": { - "unicast": { - "advertise_networks": [ - {"network": "1::1/128"} - ] - } - } + "unicast": {"advertise_networks": [{"network": "1::1/128"}]} + }, } } }, @@ -2206,10 +2053,12 @@ def test_large_community_lists_with_rmap_match_regex(request): "r4": { "dest_link": { "r2": { - "route_maps": [{ - "name": "RM_R4_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R4_OUT", + "direction": "out", + } + ] } } } @@ -2222,23 +2071,24 @@ def test_large_community_lists_with_rmap_match_regex(request): "r4": { "dest_link": { "r2": { - "route_maps": [{ - "name": "RM_R4_OUT", - "direction": "out" - }] + "route_maps": [ + { + "name": "RM_R4_OUT", + "direction": "out", + } + ] } } } } } - } + }, } } - } + }, } - result = create_router_bgp(tgen, topo,input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + result = create_router_bgp(tgen, topo, input_dict_3) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create standard large commumity-list") input_dict_4 = { @@ -2249,26 +2099,24 @@ def test_large_community_lists_with_rmap_match_regex(request): "action": "permit", "name": "ALL", "value": "1:1:1 2:1:3 2:1:4 2:1:5", - "large": True + "large": True, }, { "community_type": "expanded", "action": "permit", "name": "EXP_ALL", "value": "1:1:1 2:1:[3-5]", - "large": True - } + "large": True, + }, ] } } result = create_bgp_community_lists(tgen, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify BGP large community is created") result = verify_create_community_list(tgen, input_dict_4) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create route map") input_dict_5 = { @@ -2278,19 +2126,14 @@ def test_large_community_lists_with_rmap_match_regex(request): { "action": "permit", "seq_id": "10", - "match": { - "large_community_list": { - "id": "ALL", - }, - }, + "match": {"large_community_list": {"id": "ALL",},}, } ] } } } result = create_route_maps(tgen, input_dict_5) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure neighbor for route map") input_dict_6 = { @@ -2303,10 +2146,9 @@ def test_large_community_lists_with_rmap_match_regex(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } @@ -2319,48 +2161,38 @@ def test_large_community_lists_with_rmap_match_regex(request): "r2": { "dest_link": { "r4": { - "route_maps": [{ - "name": "RM_R4_IN", - "direction": "in" - }] + "route_maps": [ + {"name": "RM_R4_IN", "direction": "in"} + ] } } } } } - } + }, } } } } result = create_router_bgp(tgen, topo, input_dict_6) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify large-community-list") dut = "r4" - input_dict_7 = { - "largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5" - } + input_dict_7 = {"largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5"} for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - input_dict_7) + result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) step("Delete route map reference by community-list") - input_dict_3 = { - "r4": { - "route_maps": ["RM_R4_IN"] - } - } + input_dict_3 = {"r4": {"route_maps": ["RM_R4_IN"]}} result = delete_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) result = verify_route_maps(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Create route map") input_dict_5 = { @@ -2370,35 +2202,29 @@ def test_large_community_lists_with_rmap_match_regex(request): { "action": "permit", "seq_id": "20", - "match": { - "large_community_list": { - "id": "EXP_ALL", - }, - }, + "match": {"large_community_list": {"id": "EXP_ALL",},}, } ] } } } result = create_route_maps(tgen, input_dict_5) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("clear ip bgp") - result = clear_bgp_and_verify(tgen, topo, 'r4') - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + result = clear_bgp_and_verify(tgen, topo, "r4") + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("Verify large-community-list") dut = "r4" - input_dict_7 = { - "largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5" - } + input_dict_7 = {"largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5"} for adt in ADDR_TYPES: - result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], - input_dict_7, expected=False) - assert result is not True, "Testcase {} : Failed \n Error: {}".\ - format(tc_name, result) + result = verify_bgp_community( + tgen, adt, dut, NETWORKS[adt], input_dict_7, expected=False + ) + assert result is not True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) write_test_footer(tc_name) diff --git a/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py b/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py index da4b67b087..56bb14411a 100644 --- a/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py +++ b/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py @@ -35,7 +35,7 @@ import time import pytest CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -43,20 +43,22 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 5): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r3']) - switch.add_link(tgen.gears['r4']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -66,20 +68,20 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_remove_private_as(): tgen = get_topogen() @@ -88,24 +90,29 @@ def test_bgp_remove_private_as(): def _bgp_converge(router): while True: - output = json.loads(tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) - if output['192.168.255.1']['bgpState'] == 'Established': + output = json.loads( + tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json") + ) + if output["192.168.255.1"]["bgpState"] == "Established": time.sleep(1) return True def _bgp_as_path(router): - output = json.loads(tgen.gears[router].vtysh_cmd("show ip bgp 172.16.255.254/32 json")) - if output['prefix'] == '172.16.255.254/32': - return output['paths'][0]['aspath']['segments'][0]['list'] + output = json.loads( + tgen.gears[router].vtysh_cmd("show ip bgp 172.16.255.254/32 json") + ) + if output["prefix"] == "172.16.255.254/32": + return output["paths"][0]["aspath"]["segments"][0]["list"] - if _bgp_converge('r2'): - assert len(_bgp_as_path('r2')) == 1 - assert 65000 not in _bgp_as_path('r2') + if _bgp_converge("r2"): + assert len(_bgp_as_path("r2")) == 1 + assert 65000 not in _bgp_as_path("r2") - if _bgp_converge('r4'): - assert len(_bgp_as_path('r4')) == 2 - assert 3000 in _bgp_as_path('r4') + if _bgp_converge("r4"): + assert len(_bgp_as_path("r4")) == 2 + assert 3000 in _bgp_as_path("r4") -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py b/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py index e7f4f40f06..5e7c6d4b63 100644 --- a/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py +++ b/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py @@ -39,7 +39,7 @@ import time import pytest CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -47,16 +47,18 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 3): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -66,20 +68,20 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_maximum_prefix_invalid(): tgen = get_topogen() @@ -88,12 +90,16 @@ def test_bgp_maximum_prefix_invalid(): def _bgp_converge(router): while True: - output = json.loads(tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) - if output['192.168.255.1']['connectionsEstablished'] > 0: + output = json.loads( + tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json") + ) + if output["192.168.255.1"]["connectionsEstablished"] > 0: return True def _bgp_parsing_nlri(router): - cmd_max_exceeded = 'grep "%MAXPFXEXCEED: No. of IPv4 Unicast prefix received" bgpd.log' + cmd_max_exceeded = ( + 'grep "%MAXPFXEXCEED: No. of IPv4 Unicast prefix received" bgpd.log' + ) cmdt_error_parsing_nlri = 'grep "Error parsing NLRI" bgpd.log' output_max_exceeded = tgen.gears[router].run(cmd_max_exceeded) output_error_parsing_nlri = tgen.gears[router].run(cmdt_error_parsing_nlri) @@ -103,10 +109,10 @@ def test_bgp_maximum_prefix_invalid(): return False return True + if _bgp_converge("r2"): + assert _bgp_parsing_nlri("r2") == True - if _bgp_converge('r2'): - assert _bgp_parsing_nlri('r2') == True -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py b/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py index d77aa5aff2..708684f696 100644 --- a/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py +++ b/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py @@ -35,7 +35,7 @@ import pytest import functools CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -43,16 +43,18 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 3): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -62,38 +64,34 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_maximum_prefix_out(): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) - router = tgen.gears['r2'] + router = tgen.gears["r2"] def _bgp_converge(router): output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json")) expected = { - '192.168.255.2': { - 'bgpState': 'Established', - 'addressFamilyInfo': { - 'ipv4Unicast': { - 'acceptedPrefixCounter': 2 - } - } + "192.168.255.2": { + "bgpState": "Established", + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}}, } } return topotest.json_cmp(output, expected) @@ -103,6 +101,7 @@ def test_bgp_maximum_prefix_out(): assert result is None, 'Failed bgp convergence in "{}"'.format(router) -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_multiview_topo1/peer1/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer1/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp_multiview_topo1/peer1/exa-receive.py +++ b/tests/topotests/bgp_multiview_topo1/peer1/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp_multiview_topo1/peer1/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer1/exa-send.py index 2de2bce40a..505b08d6aa 100755 --- a/tests/topotests/bgp_multiview_topo1/peer1/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer1/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -16,13 +16,16 @@ numRoutes = int(argv[2]) # Announce numRoutes different routes per PE for i in range(0, numRoutes): - stdout.write('announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n' % ((peer+100), i, peer, peer)) + stdout.write( + "announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n" + % ((peer + 100), i, peer, peer) + ) stdout.flush() # Announce 1 overlapping route per peer -stdout.write('announce route 10.0.1.0/24 next-hop 172.16.1.%i\n' % peer) +stdout.write("announce route 10.0.1.0/24 next-hop 172.16.1.%i\n" % peer) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) diff --git a/tests/topotests/bgp_multiview_topo1/peer2/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer2/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp_multiview_topo1/peer2/exa-receive.py +++ b/tests/topotests/bgp_multiview_topo1/peer2/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp_multiview_topo1/peer2/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer2/exa-send.py index 2de2bce40a..505b08d6aa 100755 --- a/tests/topotests/bgp_multiview_topo1/peer2/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer2/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -16,13 +16,16 @@ numRoutes = int(argv[2]) # Announce numRoutes different routes per PE for i in range(0, numRoutes): - stdout.write('announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n' % ((peer+100), i, peer, peer)) + stdout.write( + "announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n" + % ((peer + 100), i, peer, peer) + ) stdout.flush() # Announce 1 overlapping route per peer -stdout.write('announce route 10.0.1.0/24 next-hop 172.16.1.%i\n' % peer) +stdout.write("announce route 10.0.1.0/24 next-hop 172.16.1.%i\n" % peer) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) diff --git a/tests/topotests/bgp_multiview_topo1/peer3/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer3/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp_multiview_topo1/peer3/exa-receive.py +++ b/tests/topotests/bgp_multiview_topo1/peer3/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp_multiview_topo1/peer3/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer3/exa-send.py index 2de2bce40a..505b08d6aa 100755 --- a/tests/topotests/bgp_multiview_topo1/peer3/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer3/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -16,13 +16,16 @@ numRoutes = int(argv[2]) # Announce numRoutes different routes per PE for i in range(0, numRoutes): - stdout.write('announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n' % ((peer+100), i, peer, peer)) + stdout.write( + "announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n" + % ((peer + 100), i, peer, peer) + ) stdout.flush() # Announce 1 overlapping route per peer -stdout.write('announce route 10.0.1.0/24 next-hop 172.16.1.%i\n' % peer) +stdout.write("announce route 10.0.1.0/24 next-hop 172.16.1.%i\n" % peer) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) diff --git a/tests/topotests/bgp_multiview_topo1/peer4/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer4/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp_multiview_topo1/peer4/exa-receive.py +++ b/tests/topotests/bgp_multiview_topo1/peer4/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp_multiview_topo1/peer4/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer4/exa-send.py index 2de2bce40a..505b08d6aa 100755 --- a/tests/topotests/bgp_multiview_topo1/peer4/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer4/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -16,13 +16,16 @@ numRoutes = int(argv[2]) # Announce numRoutes different routes per PE for i in range(0, numRoutes): - stdout.write('announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n' % ((peer+100), i, peer, peer)) + stdout.write( + "announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n" + % ((peer + 100), i, peer, peer) + ) stdout.flush() # Announce 1 overlapping route per peer -stdout.write('announce route 10.0.1.0/24 next-hop 172.16.1.%i\n' % peer) +stdout.write("announce route 10.0.1.0/24 next-hop 172.16.1.%i\n" % peer) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) diff --git a/tests/topotests/bgp_multiview_topo1/peer5/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer5/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp_multiview_topo1/peer5/exa-receive.py +++ b/tests/topotests/bgp_multiview_topo1/peer5/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp_multiview_topo1/peer5/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer5/exa-send.py index 2de2bce40a..505b08d6aa 100755 --- a/tests/topotests/bgp_multiview_topo1/peer5/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer5/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -16,13 +16,16 @@ numRoutes = int(argv[2]) # Announce numRoutes different routes per PE for i in range(0, numRoutes): - stdout.write('announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n' % ((peer+100), i, peer, peer)) + stdout.write( + "announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n" + % ((peer + 100), i, peer, peer) + ) stdout.flush() # Announce 1 overlapping route per peer -stdout.write('announce route 10.0.1.0/24 next-hop 172.16.1.%i\n' % peer) +stdout.write("announce route 10.0.1.0/24 next-hop 172.16.1.%i\n" % peer) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) diff --git a/tests/topotests/bgp_multiview_topo1/peer6/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer6/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp_multiview_topo1/peer6/exa-receive.py +++ b/tests/topotests/bgp_multiview_topo1/peer6/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp_multiview_topo1/peer6/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer6/exa-send.py index 2de2bce40a..505b08d6aa 100755 --- a/tests/topotests/bgp_multiview_topo1/peer6/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer6/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -16,13 +16,16 @@ numRoutes = int(argv[2]) # Announce numRoutes different routes per PE for i in range(0, numRoutes): - stdout.write('announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n' % ((peer+100), i, peer, peer)) + stdout.write( + "announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n" + % ((peer + 100), i, peer, peer) + ) stdout.flush() # Announce 1 overlapping route per peer -stdout.write('announce route 10.0.1.0/24 next-hop 172.16.1.%i\n' % peer) +stdout.write("announce route 10.0.1.0/24 next-hop 172.16.1.%i\n" % peer) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) diff --git a/tests/topotests/bgp_multiview_topo1/peer7/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer7/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp_multiview_topo1/peer7/exa-receive.py +++ b/tests/topotests/bgp_multiview_topo1/peer7/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp_multiview_topo1/peer7/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer7/exa-send.py index 2de2bce40a..505b08d6aa 100755 --- a/tests/topotests/bgp_multiview_topo1/peer7/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer7/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -16,13 +16,16 @@ numRoutes = int(argv[2]) # Announce numRoutes different routes per PE for i in range(0, numRoutes): - stdout.write('announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n' % ((peer+100), i, peer, peer)) + stdout.write( + "announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n" + % ((peer + 100), i, peer, peer) + ) stdout.flush() # Announce 1 overlapping route per peer -stdout.write('announce route 10.0.1.0/24 next-hop 172.16.1.%i\n' % peer) +stdout.write("announce route 10.0.1.0/24 next-hop 172.16.1.%i\n" % peer) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) diff --git a/tests/topotests/bgp_multiview_topo1/peer8/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer8/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp_multiview_topo1/peer8/exa-receive.py +++ b/tests/topotests/bgp_multiview_topo1/peer8/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp_multiview_topo1/peer8/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer8/exa-send.py index 2de2bce40a..505b08d6aa 100755 --- a/tests/topotests/bgp_multiview_topo1/peer8/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer8/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -16,13 +16,16 @@ numRoutes = int(argv[2]) # Announce numRoutes different routes per PE for i in range(0, numRoutes): - stdout.write('announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n' % ((peer+100), i, peer, peer)) + stdout.write( + "announce route 10.%s.%s.0/24 med 100 community %i:1 next-hop 172.16.1.%i\n" + % ((peer + 100), i, peer, peer) + ) stdout.flush() # Announce 1 overlapping route per peer -stdout.write('announce route 10.0.1.0/24 next-hop 172.16.1.%i\n' % peer) +stdout.write("announce route 10.0.1.0/24 next-hop 172.16.1.%i\n" % peer) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) diff --git a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py index c851567dda..c342b17dd2 100755 --- a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py +++ b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py @@ -60,7 +60,7 @@ test_bgp_multiview_topo1.py: Simple Quagga/FRR Route-Server Test ~~ 172.20.0.1/28 ~~ attributes (using route-map) ~~ Stub Switch ~~ ~~~~~~~~~~~~~ -""" +""" import os import re @@ -90,37 +90,39 @@ fatal_error = "" ## ##################################################### + class NetworkTopo(Topo): "BGP Multiview Topology 1" def build(self, **_opts): - exabgpPrivateDirs = ['/etc/exabgp', - '/var/run/exabgp', - '/var/log'] + exabgpPrivateDirs = ["/etc/exabgp", "/var/run/exabgp", "/var/log"] # Setup Routers router = {} for i in range(1, 2): - router[i] = topotest.addRouter(self, 'r%s' % i) + router[i] = topotest.addRouter(self, "r%s" % i) # Setup Provider BGP peers peer = {} for i in range(1, 9): - peer[i] = self.addHost('peer%s' % i, ip='172.16.1.%s/24' % i, - defaultRoute='via 172.16.1.254', - privateDirs=exabgpPrivateDirs) + peer[i] = self.addHost( + "peer%s" % i, + ip="172.16.1.%s/24" % i, + defaultRoute="via 172.16.1.254", + privateDirs=exabgpPrivateDirs, + ) # Setup Switches switch = {} # First switch is for a dummy interface (for local network) - switch[0] = self.addSwitch('sw0', cls=topotest.LegacySwitch) - self.addLink(switch[0], router[1], intfName2='r1-stub') + switch[0] = self.addSwitch("sw0", cls=topotest.LegacySwitch) + self.addLink(switch[0], router[1], intfName2="r1-stub") # Second switch is for connection to all peering routers - switch[1] = self.addSwitch('sw1', cls=topotest.LegacySwitch) - self.addLink(switch[1], router[1], intfName2='r1-eth0') + switch[1] = self.addSwitch("sw1", cls=topotest.LegacySwitch) + self.addLink(switch[1], router[1], intfName2="r1-eth0") for j in range(1, 9): - self.addLink(switch[1], peer[j], intfName2='peer%s-eth0' % j) + self.addLink(switch[1], peer[j], intfName2="peer%s-eth0" % j) ##################################################### @@ -129,6 +131,7 @@ class NetworkTopo(Topo): ## ##################################################### + def setup_module(module): global topo, net @@ -136,7 +139,7 @@ def setup_module(module): print("******************************************\n") print("Cleanup old Mininet runs") - os.system('sudo mn -c > /dev/null 2>&1') + os.system("sudo mn -c > /dev/null 2>&1") thisDir = os.path.dirname(os.path.realpath(__file__)) topo = NetworkTopo() @@ -146,25 +149,26 @@ def setup_module(module): # Starting Routers for i in range(1, 2): - net['r%s' % i].loadConf('zebra', '%s/r%s/zebra.conf' % (thisDir, i)) - net['r%s' % i].loadConf('bgpd', '%s/r%s/bgpd.conf' % (thisDir, i)) - net['r%s' % i].startRouter() + net["r%s" % i].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir, i)) + net["r%s" % i].loadConf("bgpd", "%s/r%s/bgpd.conf" % (thisDir, i)) + net["r%s" % i].startRouter() # Starting PE Hosts and init ExaBGP on each of them - print('*** Starting BGP on all 8 Peers') + print("*** Starting BGP on all 8 Peers") for i in range(1, 9): - net['peer%s' % i].cmd('cp %s/exabgp.env /etc/exabgp/exabgp.env' % thisDir) - net['peer%s' % i].cmd('cp %s/peer%s/* /etc/exabgp/' % (thisDir, i)) - net['peer%s' % i].cmd('chmod 644 /etc/exabgp/*') - net['peer%s' % i].cmd('chmod 755 /etc/exabgp/*.py') - net['peer%s' % i].cmd('chown -R exabgp:exabgp /etc/exabgp') - net['peer%s' % i].cmd('exabgp -e /etc/exabgp/exabgp.env /etc/exabgp/exabgp.cfg') - print('peer%s' % i), - print('') + net["peer%s" % i].cmd("cp %s/exabgp.env /etc/exabgp/exabgp.env" % thisDir) + net["peer%s" % i].cmd("cp %s/peer%s/* /etc/exabgp/" % (thisDir, i)) + net["peer%s" % i].cmd("chmod 644 /etc/exabgp/*") + net["peer%s" % i].cmd("chmod 755 /etc/exabgp/*.py") + net["peer%s" % i].cmd("chown -R exabgp:exabgp /etc/exabgp") + net["peer%s" % i].cmd("exabgp -e /etc/exabgp/exabgp.env /etc/exabgp/exabgp.cfg") + print("peer%s" % i), + print("") # For debugging after starting Quagga/FRR daemons, uncomment the next line # CLI(net) + def teardown_module(module): global net @@ -172,20 +176,21 @@ def teardown_module(module): print("******************************************\n") # Shutdown - clean up everything - print('*** Killing BGP on Peer routers') + print("*** Killing BGP on Peer routers") # Killing ExaBGP for i in range(1, 9): - net['peer%s' % i].cmd('kill `cat /var/run/exabgp/exabgp.pid`') + net["peer%s" % i].cmd("kill `cat /var/run/exabgp/exabgp.pid`") # End - Shutdown network net.stop() + def test_router_running(): global fatal_error global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) print("\n\n** Check if FRR/Quagga is running on each Router node") @@ -193,7 +198,7 @@ def test_router_running(): # Starting Routers for i in range(1, 2): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -207,7 +212,7 @@ def test_bgp_converge(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) # Wait for BGP to converge (All Neighbors in either Full or TwoWay State) @@ -220,9 +225,12 @@ def test_bgp_converge(): # Look for any node not yet converged for i in range(1, 2): for view in range(1, 4): - notConverged = net['r%s' % i].cmd('vtysh -c "show ip bgp view %s summary" 2> /dev/null | grep ^[0-9] | grep -v " 11$"' % view) + notConverged = net["r%s" % i].cmd( + 'vtysh -c "show ip bgp view %s summary" 2> /dev/null | grep ^[0-9] | grep -v " 11$"' + % view + ) if notConverged: - print('Waiting for r%s, view %s' % (i, view)) + print("Waiting for r%s, view %s" % (i, view)) sys.stdout.flush() break if notConverged: @@ -231,17 +239,17 @@ def test_bgp_converge(): sleep(5) timeout -= 5 else: - print('Done') + print("Done") break else: # Bail out with error if a router fails to converge - bgpStatus = net['r%s' % i].cmd('vtysh -c "show ip bgp view %s summary"' % view) + bgpStatus = net["r%s" % i].cmd('vtysh -c "show ip bgp view %s summary"' % view) assert False, "BGP did not converge:\n%s" % bgpStatus # Wait for an extra 5s to announce all routes - print('Waiting 5s for routes to be announced'); + print("Waiting 5s for routes to be announced") sleep(5) - + print("BGP converged.") # if timeout < 60: @@ -251,18 +259,19 @@ def test_bgp_converge(): # Make sure that all daemons are running for i in range(1, 2): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting Quagga/FRR daemons, uncomment the next line # CLI(net) + def test_bgp_routingTable(): global fatal_error global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -274,56 +283,68 @@ def test_bgp_routingTable(): 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))): + 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) + 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() - + 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) + 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 = 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) + 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) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual BGP routing table", - title2="expected 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; + break if not success: - resultstr = 'No template matched.\n' + 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])) + "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)) - + "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() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -335,24 +356,26 @@ def test_shutdown_check_stderr(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) - if os.environ.get('TOPOTESTS_CHECK_STDERR') is None: - print("SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n") - pytest.skip('Skipping test for Stderr output') + if os.environ.get("TOPOTESTS_CHECK_STDERR") is None: + print( + "SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n" + ) + pytest.skip("Skipping test for Stderr output") thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying unexpected STDERR output from daemons") print("******************************************\n") - net['r1'].stopRouter() + net["r1"].stopRouter() - log = net['r1'].getStdErr('bgpd') + log = net["r1"].getStdErr("bgpd") if log: print("\nBGPd StdErr Log:\n" + log) - log = net['r1'].getStdErr('zebra') + log = net["r1"].getStdErr("zebra") if log: print("\nZebra StdErr Log:\n" + log) @@ -362,22 +385,26 @@ def test_shutdown_check_memleak(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) - if os.environ.get('TOPOTESTS_CHECK_MEMLEAK') is None: - print("SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)\n") - pytest.skip('Skipping test for memory leaks') - + if os.environ.get("TOPOTESTS_CHECK_MEMLEAK") is None: + print( + "SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)\n" + ) + pytest.skip("Skipping test for memory leaks") + thisDir = os.path.dirname(os.path.realpath(__file__)) - net['r1'].stopRouter() - net['r1'].report_memory_leaks(os.environ.get('TOPOTESTS_CHECK_MEMLEAK'), os.path.basename(__file__)) + net["r1"].stopRouter() + net["r1"].report_memory_leaks( + os.environ.get("TOPOTESTS_CHECK_MEMLEAK"), os.path.basename(__file__) + ) -if __name__ == '__main__': +if __name__ == "__main__": - setLogLevel('info') + 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"]) diff --git a/tests/topotests/bgp_prefix_sid/peer2/exa-receive.py b/tests/topotests/bgp_prefix_sid/peer2/exa-receive.py index eaa6a67872..f1ec9fa5ba 100755 --- a/tests/topotests/bgp_prefix_sid/peer2/exa-receive.py +++ b/tests/topotests/bgp_prefix_sid/peer2/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,7 +13,7 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: diff --git a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py index dc203cabc5..3a6aefe7ee 100755 --- a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py +++ b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py @@ -33,7 +33,7 @@ import functools import pytest CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -45,13 +45,17 @@ from mininet.topo import Topo class TemplateTopo(Topo): def build(self, **_opts): tgen = get_topogen(self) - router = tgen.add_router('r1') - switch = tgen.add_switch('s1') + router = tgen.add_router("r1") + switch = tgen.add_switch("s1") switch.add_link(router) - switch = tgen.gears['s1'] - peer1 = tgen.add_exabgp_peer('peer1', ip='10.0.0.101', defaultRoute='via 10.0.0.1') - peer2 = tgen.add_exabgp_peer('peer2', ip='10.0.0.102', defaultRoute='via 10.0.0.1') + switch = tgen.gears["s1"] + peer1 = tgen.add_exabgp_peer( + "peer1", ip="10.0.0.101", defaultRoute="via 10.0.0.1" + ) + peer2 = tgen.add_exabgp_peer( + "peer2", ip="10.0.0.102", defaultRoute="via 10.0.0.1" + ) switch.add_link(peer1) switch.add_link(peer2) @@ -60,17 +64,21 @@ def setup_module(module): tgen = Topogen(TemplateTopo, module.__name__) tgen.start_topology() - router = tgen.gears['r1'] - router.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, '{}/zebra.conf'.format('r1'))) - router.load_config(TopoRouter.RD_BGP, os.path.join(CWD, '{}/bgpd.conf'.format('r1'))) + router = tgen.gears["r1"] + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format("r1")) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format("r1")) + ) router.start() - logger.info('starting exaBGP on peer1') + logger.info("starting exaBGP on peer1") peer_list = tgen.exabgp_peers() for pname, peer in peer_list.iteritems(): peer_dir = os.path.join(CWD, pname) - env_file = os.path.join(CWD, 'exabgp.env') - logger.info('Running ExaBGP peer') + env_file = os.path.join(CWD, "exabgp.env") + logger.info("Running ExaBGP peer") peer.start(peer_dir, env_file) logger.info(pname) @@ -82,45 +90,45 @@ def teardown_module(module): def test_r1_receive_and_advertise_prefix_sid_type1(): tgen = get_topogen() - router = tgen.gears['r1'] + router = tgen.gears["r1"] def _check_type1_r1(router, prefix, remoteLabel, labelIndex): - output = router.vtysh_cmd('show bgp ipv4 labeled-unicast {} json'.format(prefix)) + output = router.vtysh_cmd( + "show bgp ipv4 labeled-unicast {} json".format(prefix) + ) output = json.loads(output) expected = { - 'prefix': prefix, - 'advertisedTo': { '10.0.0.101':{}, '10.0.0.102':{} }, - 'paths': [{ - 'valid':True, - 'remoteLabel': remoteLabel, - 'labelIndex': labelIndex, - }] + "prefix": prefix, + "advertisedTo": {"10.0.0.101": {}, "10.0.0.102": {}}, + "paths": [ + {"valid": True, "remoteLabel": remoteLabel, "labelIndex": labelIndex,} + ], } return topotest.json_cmp(output, expected) - test_func = functools.partial(_check_type1_r1, router, '3.0.0.1/32', 800001, 1) + test_func = functools.partial(_check_type1_r1, router, "3.0.0.1/32", 800001, 1) success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) assert result is None, 'Failed _check_type1_r1 in "{}"'.format(router) - test_func = functools.partial(_check_type1_r1, router, '3.0.0.2/32', 800002, 2) + test_func = functools.partial(_check_type1_r1, router, "3.0.0.2/32", 800002, 2) success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) assert result is None, 'Failed _check_type1_r1 in "{}"'.format(router) def exabgp_get_update_prefix(filename, afi, nexthop, prefix): - with open('/tmp/peer2-received.log') as f: + with open("/tmp/peer2-received.log") as f: for line in f.readlines(): output = json.loads(line) - ret = output.get('neighbor') + ret = output.get("neighbor") if ret is None: continue - ret = ret.get('message') + ret = ret.get("message") if ret is None: continue - ret = ret.get('update') + ret = ret.get("update") if ret is None: continue - ret = ret.get('announce') + ret = ret.get("announce") if ret is None: continue ret = ret.get(afi) @@ -138,36 +146,40 @@ def exabgp_get_update_prefix(filename, afi, nexthop, prefix): def test_peer2_receive_prefix_sid_type1(): tgen = get_topogen() - peer2 = tgen.gears['peer2'] + peer2 = tgen.gears["peer2"] def _check_type1_peer2(prefix, labelindex): - output = exabgp_get_update_prefix('/tmp/peer2-received.log', 'ipv4 nlri-mpls', '10.0.0.101', prefix) + output = exabgp_get_update_prefix( + "/tmp/peer2-received.log", "ipv4 nlri-mpls", "10.0.0.101", prefix + ) expected = { - 'type': 'update', - 'neighbor': { - 'ip': '10.0.0.1', - 'message': { - 'update': { - 'attribute': { - 'attribute-0x28-0xE0': '0x010007000000{:08x}'.format(labelindex) + "type": "update", + "neighbor": { + "ip": "10.0.0.1", + "message": { + "update": { + "attribute": { + "attribute-0x28-0xE0": "0x010007000000{:08x}".format( + labelindex + ) }, - 'announce': { 'ipv4 nlri-mpls': { '10.0.0.101': {} } } + "announce": {"ipv4 nlri-mpls": {"10.0.0.101": {}}}, } - } - } + }, + }, } return topotest.json_cmp(output, expected) - test_func = functools.partial(_check_type1_peer2, '3.0.0.1/32', labelindex=1) + test_func = functools.partial(_check_type1_peer2, "3.0.0.1/32", labelindex=1) success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) - assert result is None, 'Failed _check_type1_peer2 in "{}"'.format('peer2') + assert result is None, 'Failed _check_type1_peer2 in "{}"'.format("peer2") - test_func = functools.partial(_check_type1_peer2, '3.0.0.2/32', labelindex=2) + test_func = functools.partial(_check_type1_peer2, "3.0.0.2/32", labelindex=2) success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) - assert result is None, 'Failed _check_type1_peer2 in "{}"'.format('peer2') + assert result is None, 'Failed _check_type1_peer2 in "{}"'.format("peer2") -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] ret = pytest.main(args) sys.exit(ret) diff --git a/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py b/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py index d95adc185d..b49a57b308 100644 --- a/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py +++ b/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py @@ -42,7 +42,7 @@ import pytest import functools CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -50,20 +50,22 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 4): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -73,38 +75,34 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_reject_as_sets(): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) - router = tgen.gears['r2'] + router = tgen.gears["r2"] def _bgp_converge(router): output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json")) expected = { - '192.168.255.2': { - 'bgpState': 'Established', - 'addressFamilyInfo': { - 'ipv4Unicast': { - 'acceptedPrefixCounter': 2 - } - } + "192.168.255.2": { + "bgpState": "Established", + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}}, } } return topotest.json_cmp(output, expected) @@ -112,34 +110,23 @@ def test_bgp_reject_as_sets(): def _bgp_has_aggregated_route_with_stripped_as_set(router): output = json.loads(router.vtysh_cmd("show ip bgp 172.16.0.0/16 json")) expected = { - 'paths': [ - { - 'aspath': { - 'string': 'Local', - 'segments': [ - ], - 'length': 0 - } - } - ] + "paths": [{"aspath": {"string": "Local", "segments": [], "length": 0}}] } return topotest.json_cmp(output, expected) def _bgp_announce_route_without_as_sets(router): - output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.254.2 advertised-routes json")) + output = json.loads( + router.vtysh_cmd( + "show ip bgp neighbor 192.168.254.2 advertised-routes json" + ) + ) expected = { - 'advertisedRoutes': { - '172.16.0.0/16': { - 'path': '' - }, - '192.168.254.0/30': { - 'path': '65003' - }, - '192.168.255.0/30': { - 'path': '65001' - } + "advertisedRoutes": { + "172.16.0.0/16": {"path": ""}, + "192.168.254.0/30": {"path": "65003"}, + "192.168.255.0/30": {"path": "65001"}, }, - 'totalPrefixCounter': 3 + "totalPrefixCounter": 3, } return topotest.json_cmp(output, expected) @@ -148,7 +135,9 @@ def test_bgp_reject_as_sets(): assert result is None, 'Failed bgp convergence in "{}"'.format(router) - test_func = functools.partial(_bgp_has_aggregated_route_with_stripped_as_set, router) + test_func = functools.partial( + _bgp_has_aggregated_route_with_stripped_as_set, router + ) success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) assert result is None, 'Failed to see an aggregated route in "{}"'.format(router) @@ -156,8 +145,11 @@ def test_bgp_reject_as_sets(): test_func = functools.partial(_bgp_announce_route_without_as_sets, router) success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) - assert result is None, 'Route 172.16.0.0/16 should be sent without AS_SET to r3 "{}"'.format(router) + assert ( + result is None + ), 'Route 172.16.0.0/16 should be sent without AS_SET to r3 "{}"'.format(router) -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_rfapi_basic_sanity/customize.py b/tests/topotests/bgp_rfapi_basic_sanity/customize.py index a125c6582f..ea548a7337 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/customize.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/customize.py @@ -75,12 +75,15 @@ from lib.ltemplate import ltemplateRtrCmd from mininet.topo import Topo import shutil + CWD = os.path.dirname(os.path.realpath(__file__)) # test name based on directory TEST = os.path.basename(CWD) + class ThisTestTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) @@ -89,36 +92,37 @@ class ThisTestTopo(Topo): # between routers, switches and hosts. # # Create P/PE routers - tgen.add_router('r1') + tgen.add_router("r1") for routern in range(2, 5): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) # Create a switch with just one router connected to it to simulate a # empty network. switch = {} - switch[0] = tgen.add_switch('sw0') - switch[0].add_link(tgen.gears['r1'], nodeif='r1-eth0') - switch[0].add_link(tgen.gears['r2'], nodeif='r2-eth0') + switch[0] = tgen.add_switch("sw0") + switch[0].add_link(tgen.gears["r1"], nodeif="r1-eth0") + switch[0].add_link(tgen.gears["r2"], nodeif="r2-eth0") - switch[1] = tgen.add_switch('sw1') - switch[1].add_link(tgen.gears['r2'], nodeif='r2-eth1') - switch[1].add_link(tgen.gears['r3'], nodeif='r3-eth0') - switch[1].add_link(tgen.gears['r4'], nodeif='r4-eth0') + switch[1] = tgen.add_switch("sw1") + switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth1") + switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth0") + switch[1].add_link(tgen.gears["r4"], nodeif="r4-eth0") + + switch[2] = tgen.add_switch("sw2") + switch[2].add_link(tgen.gears["r2"], nodeif="r2-eth2") + switch[2].add_link(tgen.gears["r3"], nodeif="r3-eth1") - switch[2] = tgen.add_switch('sw2') - switch[2].add_link(tgen.gears['r2'], nodeif='r2-eth2') - switch[2].add_link(tgen.gears['r3'], nodeif='r3-eth1') def ltemplatePreRouterStartHook(): cc = ltemplateRtrCmd() tgen = get_topogen() - logger.info('pre router-start hook') - #check for normal init + logger.info("pre router-start hook") + # check for normal init if len(tgen.net) == 1: - logger.info('Topology not configured, skipping setup') + logger.info("Topology not configured, skipping setup") return False return True -def ltemplatePostRouterStartHook(): - logger.info('post router-start hook') - return True +def ltemplatePostRouterStartHook(): + logger.info("post router-start hook") + return True diff --git a/tests/topotests/bgp_rfapi_basic_sanity/scripts/add_routes.py b/tests/topotests/bgp_rfapi_basic_sanity/scripts/add_routes.py index 4d6a7582ba..f4b4da55d2 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/scripts/add_routes.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/scripts/add_routes.py @@ -1,36 +1,159 @@ from lutil import luCommand -holddownFactorSet = luCommand('r1','vtysh -c "show running"','rfp holddown-factor','none','Holddown factor set') + +holddownFactorSet = luCommand( + "r1", + 'vtysh -c "show running"', + "rfp holddown-factor", + "none", + "Holddown factor set", +) if not holddownFactorSet: to = "-1" cost = "" else: to = "6" cost = "cost 50" -luCommand('r1','vtysh -c "debug rfapi-dev open vn 10.0.0.1 un 1.1.1.1"','rfapi_set_response_cb: status 0', 'pass', 'Opened RFAPI') -luCommand('r1','vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 11.11.11.11"','rc=2', 'pass', 'Clean query') -luCommand('r1','vtysh -c "debug rfapi-dev register vn 10.0.0.1 un 1.1.1.1 prefix 11.11.11.0/24 lifetime {}"'.format(to),'', 'none', 'Prefix registered') -luCommand('r1','vtysh -c "show vnc registrations local"','1 out of 1','wait','Local registration') -luCommand('r1','vtysh -c "debug rfapi-dev response-omit-self off"','.','none') -luCommand('r1','vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 11.11.11.11"','11.11.11.0/24', 'pass', 'Query self') +luCommand( + "r1", + 'vtysh -c "debug rfapi-dev open vn 10.0.0.1 un 1.1.1.1"', + "rfapi_set_response_cb: status 0", + "pass", + "Opened RFAPI", +) +luCommand( + "r1", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 11.11.11.11"', + "rc=2", + "pass", + "Clean query", +) +luCommand( + "r1", + 'vtysh -c "debug rfapi-dev register vn 10.0.0.1 un 1.1.1.1 prefix 11.11.11.0/24 lifetime {}"'.format( + to + ), + "", + "none", + "Prefix registered", +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations local"', + "1 out of 1", + "wait", + "Local registration", +) +luCommand("r1", 'vtysh -c "debug rfapi-dev response-omit-self off"', ".", "none") +luCommand( + "r1", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 11.11.11.11"', + "11.11.11.0/24", + "pass", + "Query self", +) -luCommand('r3','vtysh -c "debug rfapi-dev open vn 10.0.0.2 un 2.2.2.2"','rfapi_set_response_cb: status 0', 'pass', 'Opened RFAPI') -luCommand('r3','vtysh -c "debug rfapi-dev register vn 10.0.0.2 un 2.2.2.2 prefix 22.22.22.0/24 lifetime {}"'.format(to),'', 'none', 'Prefix registered') -luCommand('r3','vtysh -c "show vnc registrations local"','1 out of 1','wait','Local registration') -luCommand('r3','vtysh -c "debug rfapi-dev response-omit-self on"','.','none') -luCommand('r3','vtysh -c "debug rfapi-dev query vn 10.0.0.2 un 2.2.2.2 target 22.22.22.22"','rc=2', 'pass', 'Self excluded') -luCommand('r3','vtysh -c "debug rfapi-dev open vn 10.0.1.2 un 2.1.1.2"','rfapi_set_response_cb: status 0', 'pass', 'Opened query only RFAPI') -luCommand('r3','vtysh -c "debug rfapi-dev query vn 10.0.1.2 un 2.1.1.2 target 22.22.22.22"','22.22.22.0/24', 'pass', 'See local') +luCommand( + "r3", + 'vtysh -c "debug rfapi-dev open vn 10.0.0.2 un 2.2.2.2"', + "rfapi_set_response_cb: status 0", + "pass", + "Opened RFAPI", +) +luCommand( + "r3", + 'vtysh -c "debug rfapi-dev register vn 10.0.0.2 un 2.2.2.2 prefix 22.22.22.0/24 lifetime {}"'.format( + to + ), + "", + "none", + "Prefix registered", +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations local"', + "1 out of 1", + "wait", + "Local registration", +) +luCommand("r3", 'vtysh -c "debug rfapi-dev response-omit-self on"', ".", "none") +luCommand( + "r3", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.2 un 2.2.2.2 target 22.22.22.22"', + "rc=2", + "pass", + "Self excluded", +) +luCommand( + "r3", + 'vtysh -c "debug rfapi-dev open vn 10.0.1.2 un 2.1.1.2"', + "rfapi_set_response_cb: status 0", + "pass", + "Opened query only RFAPI", +) +luCommand( + "r3", + 'vtysh -c "debug rfapi-dev query vn 10.0.1.2 un 2.1.1.2 target 22.22.22.22"', + "22.22.22.0/24", + "pass", + "See local", +) -luCommand('r4','vtysh -c "debug rfapi-dev open vn 10.0.0.3 un 3.3.3.3"','rfapi_set_response_cb: status 0', 'pass', 'Opened RFAPI') -luCommand('r4','vtysh -c "debug rfapi-dev register vn 10.0.0.3 un 3.3.3.3 prefix 33.33.33.0/24 lifetime {}"'.format(to),'', 'none', 'Prefix registered') -luCommand('r4','vtysh -c "show vnc registrations local"','1 out of 1','wait','Local registration') -luCommand('r4','vtysh -c "debug rfapi-dev response-omit-self off"','.','none') -luCommand('r4','vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 33.33.33.33"','33.33.33.0/24', 'pass', 'Query self') +luCommand( + "r4", + 'vtysh -c "debug rfapi-dev open vn 10.0.0.3 un 3.3.3.3"', + "rfapi_set_response_cb: status 0", + "pass", + "Opened RFAPI", +) +luCommand( + "r4", + 'vtysh -c "debug rfapi-dev register vn 10.0.0.3 un 3.3.3.3 prefix 33.33.33.0/24 lifetime {}"'.format( + to + ), + "", + "none", + "Prefix registered", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations local"', + "1 out of 1", + "wait", + "Local registration", +) +luCommand("r4", 'vtysh -c "debug rfapi-dev response-omit-self off"', ".", "none") +luCommand( + "r4", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 33.33.33.33"', + "33.33.33.0/24", + "pass", + "Query self", +) -luCommand('r4','vtysh -c "debug rfapi-dev register vn 10.0.0.3 un 3.3.3.3 prefix 11.11.11.0/24 lifetime {} {}"'.format(to, cost),'', 'none', 'MP Prefix registered') -luCommand('r4','vtysh -c "show vnc registrations local"','2 out of 2','wait','Local registration') -luCommand('r4','vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 11.11.11.11"','11.11.11.0/24', 'pass', 'Query self MP') +luCommand( + "r4", + 'vtysh -c "debug rfapi-dev register vn 10.0.0.3 un 3.3.3.3 prefix 11.11.11.0/24 lifetime {} {}"'.format( + to, cost + ), + "", + "none", + "MP Prefix registered", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations local"', + "2 out of 2", + "wait", + "Local registration", +) +luCommand( + "r4", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 11.11.11.11"', + "11.11.11.0/24", + "pass", + "Query self MP", +) -luCommand('r1','vtysh -c "show vnc registrations"','.','none') -luCommand('r3','vtysh -c "show vnc registrations"','.','none') -luCommand('r4','vtysh -c "show vnc registrations"','.','none') +luCommand("r1", 'vtysh -c "show vnc registrations"', ".", "none") +luCommand("r3", 'vtysh -c "show vnc registrations"', ".", "none") +luCommand("r4", 'vtysh -c "show vnc registrations"', ".", "none") diff --git a/tests/topotests/bgp_rfapi_basic_sanity/scripts/adjacencies.py b/tests/topotests/bgp_rfapi_basic_sanity/scripts/adjacencies.py index 6fbe4ff1c0..6ad3e735ee 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/scripts/adjacencies.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/scripts/adjacencies.py @@ -1,10 +1,48 @@ -luCommand('r1','ping 2.2.2.2 -c 1',' 0. packet loss','wait','PE->P2 (loopback) ping',60) -luCommand('r3','ping 2.2.2.2 -c 1',' 0. packet loss','wait','PE->P2 (loopback) ping',60) -luCommand('r4','ping 2.2.2.2 -c 1',' 0. packet loss','wait','PE->P2 (loopback) ping',60) -luCommand('r2','vtysh -c "show bgp summary"',' 00:0.* 00:0.* 00:0','wait','Core adjacencies up',180) -luCommand('r1','vtysh -c "show bgp vrf all summary"',' 00:0','wait','All adjacencies up',180) -luCommand('r3','vtysh -c "show bgp vrf all summary"',' 00:0','wait','All adjacencies up',180) -luCommand('r4','vtysh -c "show bgp vrf all summary"',' 00:0','wait','All adjacencies up',180) -luCommand('r1','ping 3.3.3.3 -c 1',' 0. packet loss','wait','PE->PE3 (loopback) ping') -luCommand('r1','ping 4.4.4.4 -c 1',' 0. packet loss','wait','PE->PE4 (loopback) ping') -#luCommand('r4','ping 3.3.3.3 -c 1',' 0. packet loss','wait','PE->PE3 (loopback) ping') +luCommand( + "r1", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 +) +luCommand( + "r3", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 +) +luCommand( + "r4", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 +) +luCommand( + "r2", + 'vtysh -c "show bgp summary"', + " 00:0.* 00:0.* 00:0", + "wait", + "Core adjacencies up", + 180, +) +luCommand( + "r1", + 'vtysh -c "show bgp vrf all summary"', + " 00:0", + "wait", + "All adjacencies up", + 180, +) +luCommand( + "r3", + 'vtysh -c "show bgp vrf all summary"', + " 00:0", + "wait", + "All adjacencies up", + 180, +) +luCommand( + "r4", + 'vtysh -c "show bgp vrf all summary"', + " 00:0", + "wait", + "All adjacencies up", + 180, +) +luCommand( + "r1", "ping 3.3.3.3 -c 1", " 0. packet loss", "wait", "PE->PE3 (loopback) ping" +) +luCommand( + "r1", "ping 4.4.4.4 -c 1", " 0. packet loss", "wait", "PE->PE4 (loopback) ping" +) +# luCommand('r4','ping 3.3.3.3 -c 1',' 0. packet loss','wait','PE->PE3 (loopback) ping') diff --git a/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_close.py b/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_close.py index 5fffce7ca0..9fdef84cdf 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_close.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_close.py @@ -1,19 +1,102 @@ from lutil import luCommand -holddownFactorSet = luCommand('r1','vtysh -c "show running"','rfp holddown-factor','none','Holddown factor set') + +holddownFactorSet = luCommand( + "r1", + 'vtysh -c "show running"', + "rfp holddown-factor", + "none", + "Holddown factor set", +) if not holddownFactorSet: to = "-1" else: to = "1" -luCommand('r1','vtysh -c "debug rfapi-dev open vn 20.0.0.1 un 1.1.1.21"','rfapi_set_response_cb: status 0', 'pass', 'Opened RFAPI') -luCommand('r1','vtysh -c "debug rfapi-dev register vn 20.0.0.1 un 1.1.1.21 prefix 111.111.111.0/24 lifetime {}"'.format(to),'', 'none', 'Prefix registered') -luCommand('r1','vtysh -c "show vnc registrations local"','111.111.111.0/24','wait','Local registration',1) -luCommand('r1','vtysh -c "show vnc registrations"','.','none') -luCommand('r3','vtysh -c "show vnc registrations"','111.111.111.0/24','wait','See registration') -luCommand('r4','vtysh -c "show vnc registrations"','111.111.111.0/24','wait','See registration') -luCommand('r1','vtysh -c "debug rfapi-dev close vn 20.0.0.1 un 1.1.1.21"','status 0', 'pass', 'Closed RFAPI') -luCommand('r1','vtysh -c "show vnc registrations"','Locally: *Active: 1 .* Remotely: *Active: 3','wait','See cleanup') -luCommand('r3','vtysh -c "show vnc registrations"','Locally: *Active: 1 .* Remotely: *Active: 3','wait','See cleanup') -luCommand('r4','vtysh -c "show vnc registrations"','Locally: *Active: 2 .* Remotely: *Active: 2','wait','See cleanup') -luCommand('r1','vtysh -c "show vnc registrations"','In Holddown: *Active: 0','wait','Out of holddown',20) -luCommand('r3','vtysh -c "show vnc registrations"','In Holddown: *Active: 0','wait','Out of holddown') -luCommand('r4','vtysh -c "show vnc registrations"','In Holddown: *Active: 0','wait','Out of holddown') +luCommand( + "r1", + 'vtysh -c "debug rfapi-dev open vn 20.0.0.1 un 1.1.1.21"', + "rfapi_set_response_cb: status 0", + "pass", + "Opened RFAPI", +) +luCommand( + "r1", + 'vtysh -c "debug rfapi-dev register vn 20.0.0.1 un 1.1.1.21 prefix 111.111.111.0/24 lifetime {}"'.format( + to + ), + "", + "none", + "Prefix registered", +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations local"', + "111.111.111.0/24", + "wait", + "Local registration", + 1, +) +luCommand("r1", 'vtysh -c "show vnc registrations"', ".", "none") +luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "111.111.111.0/24", + "wait", + "See registration", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "111.111.111.0/24", + "wait", + "See registration", +) +luCommand( + "r1", + 'vtysh -c "debug rfapi-dev close vn 20.0.0.1 un 1.1.1.21"', + "status 0", + "pass", + "Closed RFAPI", +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 1 .* Remotely: *Active: 3", + "wait", + "See cleanup", +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 1 .* Remotely: *Active: 3", + "wait", + "See cleanup", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 2 .* Remotely: *Active: 2", + "wait", + "See cleanup", +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations"', + "In Holddown: *Active: 0", + "wait", + "Out of holddown", + 20, +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "In Holddown: *Active: 0", + "wait", + "Out of holddown", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "In Holddown: *Active: 0", + "wait", + "Out of holddown", +) diff --git a/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_routes.py b/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_routes.py index a380c79fcf..1caa827ce2 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_routes.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_routes.py @@ -1,19 +1,74 @@ from lutil import luCommand -luCommand('r1','vtysh -c "show bgp ipv4 vpn"','','none','VPN SAFI') -luCommand('r2','vtysh -c "show bgp ipv4 vpn"','','none','VPN SAFI') -luCommand('r3','vtysh -c "show bgp ipv4 vpn"','','none','VPN SAFI') -luCommand('r4','vtysh -c "show bgp ipv4 vpn"','','none','VPN SAFI') -luCommand('r1','vtysh -c "show vnc registrations"','Locally: *Active: 1 .* Remotely: *Active: 3','wait','See all registrations') -luCommand('r3','vtysh -c "show vnc registrations"','Locally: *Active: 1 .* Remotely: *Active: 3','wait','See all registrations') -luCommand('r4','vtysh -c "show vnc registrations"','Locally: *Active: 2 .* Remotely: *Active: 2','wait','See all registrations') -num = '4 routes and 4' -luCommand('r1','vtysh -c "show bgp ipv4 vpn"',num,'pass','VPN SAFI okay') -luCommand('r2','vtysh -c "show bgp ipv4 vpn"',num,'pass','VPN SAFI okay') -luCommand('r3','vtysh -c "show bgp ipv4 vpn"',num,'pass','VPN SAFI okay') -luCommand('r4','vtysh -c "show bgp ipv4 vpn"',num,'pass','VPN SAFI okay') -luCommand('r1','vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 22.22.22.22"','pfx=', 'pass', 'Query R2s info') -luCommand('r1','vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 33.33.33.33"','pfx=', 'pass', 'Query R4s info') -luCommand('r3','vtysh -c "debug rfapi-dev query vn 10.0.0.2 un 2.2.2.2 target 11.11.11.11"','11.11.11.0/24.*11.11.11.0/24.*', 'pass', 'Query R1s+R4s info') -luCommand('r3','vtysh -c "debug rfapi-dev query vn 10.0.0.2 un 2.2.2.2 target 33.33.33.33"','pfx=', 'pass', 'Query R4s info') -luCommand('r4','vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 11.11.11.11"','11.11.11.0/24.*11.11.11.0/24.*', 'pass', 'Query R1s+R4s info') -luCommand('r4','vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 22.22.22.22"','pfx=', 'pass', 'Query R2s info') + +luCommand("r1", 'vtysh -c "show bgp ipv4 vpn"', "", "none", "VPN SAFI") +luCommand("r2", 'vtysh -c "show bgp ipv4 vpn"', "", "none", "VPN SAFI") +luCommand("r3", 'vtysh -c "show bgp ipv4 vpn"', "", "none", "VPN SAFI") +luCommand("r4", 'vtysh -c "show bgp ipv4 vpn"', "", "none", "VPN SAFI") +luCommand( + "r1", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 1 .* Remotely: *Active: 3", + "wait", + "See all registrations", +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 1 .* Remotely: *Active: 3", + "wait", + "See all registrations", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 2 .* Remotely: *Active: 2", + "wait", + "See all registrations", +) +num = "4 routes and 4" +luCommand("r1", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI okay") +luCommand("r2", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI okay") +luCommand("r3", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI okay") +luCommand("r4", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI okay") +luCommand( + "r1", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 22.22.22.22"', + "pfx=", + "pass", + "Query R2s info", +) +luCommand( + "r1", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 33.33.33.33"', + "pfx=", + "pass", + "Query R4s info", +) +luCommand( + "r3", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.2 un 2.2.2.2 target 11.11.11.11"', + "11.11.11.0/24.*11.11.11.0/24.*", + "pass", + "Query R1s+R4s info", +) +luCommand( + "r3", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.2 un 2.2.2.2 target 33.33.33.33"', + "pfx=", + "pass", + "Query R4s info", +) +luCommand( + "r4", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 11.11.11.11"', + "11.11.11.0/24.*11.11.11.0/24.*", + "pass", + "Query R1s+R4s info", +) +luCommand( + "r4", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 22.22.22.22"', + "pfx=", + "pass", + "Query R2s info", +) diff --git a/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_timeout.py b/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_timeout.py index f4467ecc33..e68e9e93ab 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_timeout.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_timeout.py @@ -1,68 +1,325 @@ from lutil import luCommand -holddownFactorSet = luCommand('r1','vtysh -c "show running"','rfp holddown-factor','none','Holddown factor set') -luCommand('r1','vtysh -c "show vnc registrations"','.','none') -luCommand('r3','vtysh -c "show vnc registrations"','.','none') -luCommand('r4','vtysh -c "show vnc registrations"','.','none') + +holddownFactorSet = luCommand( + "r1", + 'vtysh -c "show running"', + "rfp holddown-factor", + "none", + "Holddown factor set", +) +luCommand("r1", 'vtysh -c "show vnc registrations"', ".", "none") +luCommand("r3", 'vtysh -c "show vnc registrations"', ".", "none") +luCommand("r4", 'vtysh -c "show vnc registrations"', ".", "none") if not holddownFactorSet: - luCommand('r1','vtysh -c "show vnc summary"','.','pass','Holddown factor not set -- skipping test') + luCommand( + "r1", + 'vtysh -c "show vnc summary"', + ".", + "pass", + "Holddown factor not set -- skipping test", + ) else: - #holddown time test - luCommand('r1','vtysh -c "debug rfapi-dev register vn 10.0.0.1 un 1.1.1.1 prefix 1.111.0.0/16 lifetime 10"','', 'none', 'Prefix registered') - luCommand('r1','vtysh -c "show vnc registrations local"','1.111.0.0/16','wait','Local registration') + # holddown time test + luCommand( + "r1", + 'vtysh -c "debug rfapi-dev register vn 10.0.0.1 un 1.1.1.1 prefix 1.111.0.0/16 lifetime 10"', + "", + "none", + "Prefix registered", + ) + luCommand( + "r1", + 'vtysh -c "show vnc registrations local"', + "1.111.0.0/16", + "wait", + "Local registration", + ) - luCommand('r3','vtysh -c "debug rfapi-dev register vn 10.0.0.2 un 2.2.2.2 prefix 1.222.0.0/16 lifetime 10"','', 'none', 'Prefix registered') - luCommand('r3','vtysh -c "show vnc registrations local"','1.222.0.0/16','wait','Local registration') + luCommand( + "r3", + 'vtysh -c "debug rfapi-dev register vn 10.0.0.2 un 2.2.2.2 prefix 1.222.0.0/16 lifetime 10"', + "", + "none", + "Prefix registered", + ) + luCommand( + "r3", + 'vtysh -c "show vnc registrations local"', + "1.222.0.0/16", + "wait", + "Local registration", + ) - luCommand('r4','vtysh -c "show vnc registrations"','Remotely: *Active: 4 ','wait', 'See registrations, L=10') + luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "Remotely: *Active: 4 ", + "wait", + "See registrations, L=10", + ) - luCommand('r4','vtysh -c "debug rfapi-dev register vn 10.0.0.3 un 3.3.3.3 prefix 1.222.0.0/16 lifetime 5 cost 50"','', 'none', 'MP Prefix registered') - luCommand('r4','vtysh -c "show vnc registrations local"','1.222.0.0/16','wait','Local registration (MP prefix)') + luCommand( + "r4", + 'vtysh -c "debug rfapi-dev register vn 10.0.0.3 un 3.3.3.3 prefix 1.222.0.0/16 lifetime 5 cost 50"', + "", + "none", + "MP Prefix registered", + ) + luCommand( + "r4", + 'vtysh -c "show vnc registrations local"', + "1.222.0.0/16", + "wait", + "Local registration (MP prefix)", + ) - luCommand('r1','vtysh -c "show vnc registrations"','.','none') - luCommand('r3','vtysh -c "show vnc registrations"','.','none') + luCommand("r1", 'vtysh -c "show vnc registrations"', ".", "none") + luCommand("r3", 'vtysh -c "show vnc registrations"', ".", "none") - luCommand('r4','vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 1.111.111.111"','pfx=', 'pass', 'Query R1s info') - luCommand('r4','vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 1.222.222.222"','1.222.0.0/16.*1.222.0.0/16', 'pass', 'Query R3s+R4s info') + luCommand( + "r4", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 1.111.111.111"', + "pfx=", + "pass", + "Query R1s info", + ) + luCommand( + "r4", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 1.222.222.222"', + "1.222.0.0/16.*1.222.0.0/16", + "pass", + "Query R3s+R4s info", + ) - luCommand('r4','vtysh -c "debug rfapi-dev unregister vn 10.0.0.3 un 3.3.3.3 prefix 1.222.0.0/16"','', 'none', 'MP Prefix removed') - luCommand('r4','vtysh -c "show vnc registrations"','In Holddown: *Active: 1 ','wait', 'MP prefix in holddown') - luCommand('r1','vtysh -c "show vnc registrations"','In Holddown: *Active: 1 ','wait', 'MP prefix in holddown') - luCommand('r3','vtysh -c "show vnc registrations"','In Holddown: *Active: 1 ','wait', 'MP prefix in holddown') - luCommand('r1','vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 1.222.222.222"','1.222.0.0/16', 'pass', 'Query R3s info') - luCommand('r1','vtysh -c "debug rfapi-dev unregister vn 10.0.0.1 un 1.1.1.1 prefix 1.111.0.0/16"','', 'none', 'Prefix timeout') - luCommand('r1','vtysh -c "show vnc registrations holddown"','1.111.0.0/16','wait','Local holddown',1) - luCommand('r3','vtysh -c "debug rfapi-dev unregister vn 10.0.0.2 un 2.2.2.2 prefix 1.222.0.0/16"','', 'none', 'Prefix timeout') - luCommand('r3','vtysh -c "show vnc registrations holddown"','1.222.0.0/16','wait','Local holddown',1) - luCommand('r4','vtysh -c "show vnc registrations"','.','none') - luCommand('r4','vtysh -c "show vnc registrations"','.','none') + luCommand( + "r4", + 'vtysh -c "debug rfapi-dev unregister vn 10.0.0.3 un 3.3.3.3 prefix 1.222.0.0/16"', + "", + "none", + "MP Prefix removed", + ) + luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "In Holddown: *Active: 1 ", + "wait", + "MP prefix in holddown", + ) + luCommand( + "r1", + 'vtysh -c "show vnc registrations"', + "In Holddown: *Active: 1 ", + "wait", + "MP prefix in holddown", + ) + luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "In Holddown: *Active: 1 ", + "wait", + "MP prefix in holddown", + ) + luCommand( + "r1", + 'vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 1.222.222.222"', + "1.222.0.0/16", + "pass", + "Query R3s info", + ) + luCommand( + "r1", + 'vtysh -c "debug rfapi-dev unregister vn 10.0.0.1 un 1.1.1.1 prefix 1.111.0.0/16"', + "", + "none", + "Prefix timeout", + ) + luCommand( + "r1", + 'vtysh -c "show vnc registrations holddown"', + "1.111.0.0/16", + "wait", + "Local holddown", + 1, + ) + luCommand( + "r3", + 'vtysh -c "debug rfapi-dev unregister vn 10.0.0.2 un 2.2.2.2 prefix 1.222.0.0/16"', + "", + "none", + "Prefix timeout", + ) + luCommand( + "r3", + 'vtysh -c "show vnc registrations holddown"', + "1.222.0.0/16", + "wait", + "Local holddown", + 1, + ) + luCommand("r4", 'vtysh -c "show vnc registrations"', ".", "none") + luCommand("r4", 'vtysh -c "show vnc registrations"', ".", "none") - luCommand('r4','vtysh -c "show vnc registrations"','In Holddown: *Active: 2 ','wait', 'In holddown') - luCommand('r1','vtysh -c "show vnc registrations"','In Holddown: *Active: 2 ','wait', 'In holddown') - luCommand('r3','vtysh -c "show vnc registrations"','In Holddown: *Active: 2 ','wait', 'In holddown') + luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "In Holddown: *Active: 2 ", + "wait", + "In holddown", + ) + luCommand( + "r1", + 'vtysh -c "show vnc registrations"', + "In Holddown: *Active: 2 ", + "wait", + "In holddown", + ) + luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "In Holddown: *Active: 2 ", + "wait", + "In holddown", + ) - luCommand('r1','vtysh -c "show vnc registrations"','In Holddown: *Active: 0','wait','Out of holddown',20) - luCommand('r3','vtysh -c "show vnc registrations"','In Holddown: *Active: 0','wait','Out of holddown') - luCommand('r4','vtysh -c "show vnc registrations"','In Holddown: *Active: 0','wait','Out of holddown') + luCommand( + "r1", + 'vtysh -c "show vnc registrations"', + "In Holddown: *Active: 0", + "wait", + "Out of holddown", + 20, + ) + luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "In Holddown: *Active: 0", + "wait", + "Out of holddown", + ) + luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "In Holddown: *Active: 0", + "wait", + "Out of holddown", + ) - #kill test - luCommand('r1','vtysh -c "debug rfapi-dev register vn 10.0.0.1 un 1.1.1.1 prefix 1.111.0.0/16 lifetime 10"','', 'none', 'Prefix registered') - luCommand('r1','vtysh -c "show vnc registrations local"','1.111.0.0/16','wait','Local registration') + # kill test + luCommand( + "r1", + 'vtysh -c "debug rfapi-dev register vn 10.0.0.1 un 1.1.1.1 prefix 1.111.0.0/16 lifetime 10"', + "", + "none", + "Prefix registered", + ) + luCommand( + "r1", + 'vtysh -c "show vnc registrations local"', + "1.111.0.0/16", + "wait", + "Local registration", + ) - luCommand('r3','vtysh -c "debug rfapi-dev register vn 10.0.0.2 un 2.2.2.2 prefix 1.222.0.0/16 lifetime 10"','', 'none', 'Prefix registered') - luCommand('r3','vtysh -c "show vnc registrations local"','1.222.0.0/16','wait','Local registration') + luCommand( + "r3", + 'vtysh -c "debug rfapi-dev register vn 10.0.0.2 un 2.2.2.2 prefix 1.222.0.0/16 lifetime 10"', + "", + "none", + "Prefix registered", + ) + luCommand( + "r3", + 'vtysh -c "show vnc registrations local"', + "1.222.0.0/16", + "wait", + "Local registration", + ) - luCommand('r4','vtysh -c "show vnc registrations"','Remotely: *Active: 4 ','wait', 'See registrations L=10 (pre-kill)',5) - luCommand('r1','vtysh -c "show vnc registrations"','.','none') - luCommand('r3','vtysh -c "show vnc registrations"','.','none') - luCommand('r1','vtysh -c "debug rfapi-dev unregister vn 10.0.0.1 un 1.1.1.1 prefix 1.111.0.0/16 kill"','', 'none', 'Prefix kill') - luCommand('r1','vtysh -c "show vnc registrations"','Locally: *Active: 1 .* Remotely: *Active: 4 .*In Holddown: *Active: 0','wait','Registration killed',1) - luCommand('r3','vtysh -c "show vnc registrations"','Locally: *Active: 2 .* Remotely: *Active: 3 .*In Holddown: *Active: 1','wait','Remote in holddown',5) - luCommand('r4','vtysh -c "show vnc registrations"','Locally: *Active: 2 .* Remotely: *Active: 3 .*In Holddown: *Active: 1','wait','Remote in holddown',5) + luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "Remotely: *Active: 4 ", + "wait", + "See registrations L=10 (pre-kill)", + 5, + ) + luCommand("r1", 'vtysh -c "show vnc registrations"', ".", "none") + luCommand("r3", 'vtysh -c "show vnc registrations"', ".", "none") + luCommand( + "r1", + 'vtysh -c "debug rfapi-dev unregister vn 10.0.0.1 un 1.1.1.1 prefix 1.111.0.0/16 kill"', + "", + "none", + "Prefix kill", + ) + luCommand( + "r1", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 1 .* Remotely: *Active: 4 .*In Holddown: *Active: 0", + "wait", + "Registration killed", + 1, + ) + luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 2 .* Remotely: *Active: 3 .*In Holddown: *Active: 1", + "wait", + "Remote in holddown", + 5, + ) + luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 2 .* Remotely: *Active: 3 .*In Holddown: *Active: 1", + "wait", + "Remote in holddown", + 5, + ) - luCommand('r3','vtysh -c "debug rfapi-dev unregister vn 10.0.0.2 un 2.2.2.2 prefix 1.222.0.0/16 kill"','', 'none', 'Prefix kill') - luCommand('r3','vtysh -c "show vnc registrations"','Locally: *Active: 1 .* Remotely: *Active: 3 .*In Holddown: *Active: 1','wait','Registration killed',1) - luCommand('r4','vtysh -c "show vnc registrations"','Locally: *Active: 2 .* Remotely: *Active: 2 .*In Holddown: *Active: 2','wait','Remote in holddown',5) + luCommand( + "r3", + 'vtysh -c "debug rfapi-dev unregister vn 10.0.0.2 un 2.2.2.2 prefix 1.222.0.0/16 kill"', + "", + "none", + "Prefix kill", + ) + luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 1 .* Remotely: *Active: 3 .*In Holddown: *Active: 1", + "wait", + "Registration killed", + 1, + ) + luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 2 .* Remotely: *Active: 2 .*In Holddown: *Active: 2", + "wait", + "Remote in holddown", + 5, + ) - luCommand('r1','vtysh -c "show vnc registrations"','Locally: *Active: 1 .* Remotely: *Active: 3 .*In Holddown: *Active: 0','wait','Out of holddown',20) - luCommand('r3','vtysh -c "show vnc registrations"','Locally: *Active: 1 .* Remotely: *Active: 3 .*In Holddown: *Active: 0','wait','Out of holddown') - luCommand('r4','vtysh -c "show vnc registrations"','Locally: *Active: 2 .* Remotely: *Active: 2 .*In Holddown: *Active: 0','wait','Out of holddown') + luCommand( + "r1", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 1 .* Remotely: *Active: 3 .*In Holddown: *Active: 0", + "wait", + "Out of holddown", + 20, + ) + luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 1 .* Remotely: *Active: 3 .*In Holddown: *Active: 0", + "wait", + "Out of holddown", + ) + luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 2 .* Remotely: *Active: 2 .*In Holddown: *Active: 0", + "wait", + "Out of holddown", + ) diff --git a/tests/topotests/bgp_rfapi_basic_sanity/scripts/cleanup_all.py b/tests/topotests/bgp_rfapi_basic_sanity/scripts/cleanup_all.py index e9c1916f75..eea977bfaf 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/scripts/cleanup_all.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/scripts/cleanup_all.py @@ -1,33 +1,124 @@ from lutil import luCommand -luCommand('r1','vtysh -c "debug rfapi-dev unregister vn 10.0.0.1 un 1.1.1.1 prefix 11.11.11.0/24"','', 'none', 'Prefix removed') -luCommand('r1','vtysh -c "show vnc registrations"','Locally: *Active: 0 ','wait','Local registration removed') -luCommand('r1','vtysh -c "debug rfapi-dev close vn 10.0.0.1 un 1.1.1.1"','status 0', 'pass', 'Closed RFAPI') -luCommand('r3','vtysh -c "debug rfapi-dev unregister vn 10.0.0.2 un 2.2.2.2 prefix 22.22.22.0/24"','', 'none', 'Prefix removed') -luCommand('r3','vtysh -c "show vnc registrations"','Locally: *Active: 0 ','wait','Local registration removed') -luCommand('r3','vtysh -c "debug rfapi-dev close vn 10.0.0.2 un 2.2.2.2"','status 0', 'pass', 'Closed RFAPI') +luCommand( + "r1", + 'vtysh -c "debug rfapi-dev unregister vn 10.0.0.1 un 1.1.1.1 prefix 11.11.11.0/24"', + "", + "none", + "Prefix removed", +) +luCommand( + "r1", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 0 ", + "wait", + "Local registration removed", +) +luCommand( + "r1", + 'vtysh -c "debug rfapi-dev close vn 10.0.0.1 un 1.1.1.1"', + "status 0", + "pass", + "Closed RFAPI", +) -luCommand('r4','vtysh -c "debug rfapi-dev unregister vn 10.0.0.3 un 3.3.3.3 prefix 33.33.33.0/24"','', 'none', 'Prefix removed') -luCommand('r4','vtysh -c "debug rfapi-dev unregister vn 10.0.0.3 un 3.3.3.3 prefix 11.11.11.0/24"','', 'none', 'MP prefix removed') -luCommand('r4','vtysh -c "show vnc registrations"','Locally: *Active: 0 ','wait','Local registration removed') -#luCommand('r4','vtysh -c "debug rfapi-dev close vn 10.0.0.3 un 3.3.3.3"','status 0', 'pass', 'Closed RFAPI') -luCommand('r4','vtysh -c "clear vnc nve *"','.', 'pass', 'Cleared NVEs') +luCommand( + "r3", + 'vtysh -c "debug rfapi-dev unregister vn 10.0.0.2 un 2.2.2.2 prefix 22.22.22.0/24"', + "", + "none", + "Prefix removed", +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 0 ", + "wait", + "Local registration removed", +) +luCommand( + "r3", + 'vtysh -c "debug rfapi-dev close vn 10.0.0.2 un 2.2.2.2"', + "status 0", + "pass", + "Closed RFAPI", +) -luCommand('r1','vtysh -c "show vnc registrations"','Locally: *Active: 0 .* Remotely: *Active: 0','wait','All registrations cleared') -luCommand('r3','vtysh -c "show vnc registrations"','Locally: *Active: 0 .* Remotely: *Active: 0','wait','All registrations cleared') -luCommand('r4','vtysh -c "show vnc registrations"','Locally: *Active: 0 .* Remotely: *Active: 0','wait','All registrations cleared') +luCommand( + "r4", + 'vtysh -c "debug rfapi-dev unregister vn 10.0.0.3 un 3.3.3.3 prefix 33.33.33.0/24"', + "", + "none", + "Prefix removed", +) +luCommand( + "r4", + 'vtysh -c "debug rfapi-dev unregister vn 10.0.0.3 un 3.3.3.3 prefix 11.11.11.0/24"', + "", + "none", + "MP prefix removed", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 0 ", + "wait", + "Local registration removed", +) +# luCommand('r4','vtysh -c "debug rfapi-dev close vn 10.0.0.3 un 3.3.3.3"','status 0', 'pass', 'Closed RFAPI') +luCommand("r4", 'vtysh -c "clear vnc nve *"', ".", "pass", "Cleared NVEs") -num = '0 exist' -luCommand('r1','vtysh -c "show bgp ipv4 vpn"',num,'pass','VPN SAFI clear') -luCommand('r2','vtysh -c "show bgp ipv4 vpn"',num,'pass','VPN SAFI clear') -luCommand('r3','vtysh -c "show bgp ipv4 vpn"',num,'pass','VPN SAFI clear') -luCommand('r4','vtysh -c "show bgp ipv4 vpn"',num,'pass','VPN SAFI clear') +luCommand( + "r1", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 0 .* Remotely: *Active: 0", + "wait", + "All registrations cleared", +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 0 .* Remotely: *Active: 0", + "wait", + "All registrations cleared", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 0 .* Remotely: *Active: 0", + "wait", + "All registrations cleared", +) -luCommand('r1','vtysh -c "show vnc registrations"','Locally: *Active: 0 .* Remotely: *Active: 0 .*In Holddown: *Active: 0','wait','No holddowns',20) -luCommand('r3','vtysh -c "show vnc registrations"','Locally: *Active: 0 .* Remotely: *Active: 0 .*In Holddown: *Active: 0','wait','No holddowns') -luCommand('r4','vtysh -c "show vnc registrations"','Locally: *Active: 0 .* Remotely: *Active: 0 .*In Holddown: *Active: 0','wait','No holddowns') +num = "0 exist" +luCommand("r1", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI clear") +luCommand("r2", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI clear") +luCommand("r3", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI clear") +luCommand("r4", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI clear") -luCommand('r1','vtysh -c "show vnc summary"','.','none') -luCommand('r3','vtysh -c "show vnc summary"','.','none') -luCommand('r4','vtysh -c "show vnc summary"','.','none') +luCommand( + "r1", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 0 .* Remotely: *Active: 0 .*In Holddown: *Active: 0", + "wait", + "No holddowns", + 20, +) +luCommand( + "r3", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 0 .* Remotely: *Active: 0 .*In Holddown: *Active: 0", + "wait", + "No holddowns", +) +luCommand( + "r4", + 'vtysh -c "show vnc registrations"', + "Locally: *Active: 0 .* Remotely: *Active: 0 .*In Holddown: *Active: 0", + "wait", + "No holddowns", +) +luCommand("r1", 'vtysh -c "show vnc summary"', ".", "none") +luCommand("r3", 'vtysh -c "show vnc summary"', ".", "none") +luCommand("r4", 'vtysh -c "show vnc summary"', ".", "none") diff --git a/tests/topotests/bgp_rfapi_basic_sanity/test_bgp_rfapi_basic_sanity.py b/tests/topotests/bgp_rfapi_basic_sanity/test_bgp_rfapi_basic_sanity.py index 0e1f236b7d..cd59bbc395 100755 --- a/tests/topotests/bgp_rfapi_basic_sanity/test_bgp_rfapi_basic_sanity.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/test_bgp_rfapi_basic_sanity.py @@ -25,64 +25,71 @@ import os import sys import pytest -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')) +sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from lib.ltemplate import * + def test_add_routes(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'3.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' - ltemplateTest('scripts/add_routes.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('3.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' + ltemplateTest("scripts/add_routes.py", False, CliOnFail, CheckFunc) + def test_adjacencies(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'3.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' - ltemplateTest('scripts/adjacencies.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('3.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' + ltemplateTest("scripts/adjacencies.py", False, CliOnFail, CheckFunc) + def test_check_routes(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'3.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' - ltemplateTest('scripts/check_routes.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('3.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' + ltemplateTest("scripts/check_routes.py", False, CliOnFail, CheckFunc) + def test_check_close(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'3.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' - ltemplateTest('scripts/check_close.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('3.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' + ltemplateTest("scripts/check_close.py", False, CliOnFail, CheckFunc) + def test_check_timeout(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'3.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' - ltemplateTest('scripts/check_timeout.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('3.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' + ltemplateTest("scripts/check_timeout.py", False, CliOnFail, CheckFunc) + def test_cleanup_all(): CliOnFail = None # For debugging, uncomment the next line - #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'ltemplateVersionCheck(\'3.1\')' - #uncomment next line to start cli *before* script is run - #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' - ltemplateTest('scripts/cleanup_all.py', False, CliOnFail, CheckFunc) + # CliOnFail = 'tgen.mininet_cli' + CheckFunc = "ltemplateVersionCheck('3.1')" + # uncomment next line to start cli *before* script is run + # CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' + ltemplateTest("scripts/cleanup_all.py", False, CliOnFail, CheckFunc) -if __name__ == '__main__': + +if __name__ == "__main__": retval = pytest.main(["-s"]) sys.exit(retval) diff --git a/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py b/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py index c7daa06b76..da45e73ab4 100755 --- a/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py +++ b/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py @@ -38,7 +38,7 @@ import json # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -55,6 +55,7 @@ from mininet.topo import Topo ## ##################################################### + class NetworkTopo(Topo): "BGP_RR_IBGP Topology 1" @@ -63,30 +64,30 @@ class NetworkTopo(Topo): tgen = get_topogen(self) - tgen.add_router('tor1') - tgen.add_router('tor2') - tgen.add_router('spine1') + tgen.add_router("tor1") + tgen.add_router("tor2") + tgen.add_router("spine1") # First switch is for a dummy interface (for local network) # on tor1 - # 192.168.1.0/24 - switch = tgen.add_switch('sw1') - switch.add_link(tgen.gears['tor1']) + # 192.168.1.0/24 + switch = tgen.add_switch("sw1") + switch.add_link(tgen.gears["tor1"]) - # 192.168.2.0/24 - tor1 <-> spine1 connection - switch = tgen.add_switch('sw2') - switch.add_link(tgen.gears['tor1']) - switch.add_link(tgen.gears['spine1']) + # 192.168.2.0/24 - tor1 <-> spine1 connection + switch = tgen.add_switch("sw2") + switch.add_link(tgen.gears["tor1"]) + switch.add_link(tgen.gears["spine1"]) # 3rd switch is for a dummy interface (for local netwokr) - # 192.168.3.0/24 - tor2 - switch = tgen.add_switch('sw3') - switch.add_link(tgen.gears['tor2']) + # 192.168.3.0/24 - tor2 + switch = tgen.add_switch("sw3") + switch.add_link(tgen.gears["tor2"]) - # 192.168.4.0/24 - tor2 <-> spine1 connection - switch = tgen.add_switch('sw4') - switch.add_link(tgen.gears['tor2']) - switch.add_link(tgen.gears['spine1']) + # 192.168.4.0/24 - tor2 <-> spine1 connection + switch = tgen.add_switch("sw4") + switch.add_link(tgen.gears["tor2"]) + switch.add_link(tgen.gears["spine1"]) ##################################################### @@ -95,6 +96,7 @@ class NetworkTopo(Topo): ## ##################################################### + def setup_module(module): "Setup topology" tgen = Topogen(NetworkTopo, module.__name__) @@ -104,12 +106,10 @@ def setup_module(module): router_list = tgen.routers() for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() @@ -132,7 +132,7 @@ def test_converge_protocols(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - topotest.sleep(5, 'Waiting for BGP_RR_IBGP convergence') + topotest.sleep(5, "Waiting for BGP_RR_IBGP convergence") def test_bgp_rr_ibgp_routes(): @@ -146,6 +146,7 @@ def test_bgp_rr_ibgp_routes(): # Verify BGP_RR_IBGP Status logger.info("Verifying BGP_RR_IBGP routes") + def test_zebra_ipv4_routingTable(): "Test 'show ip route'" @@ -157,16 +158,19 @@ def test_zebra_ipv4_routingTable(): failures = 0 router_list = tgen.routers().values() for router in router_list: - output = router.vtysh_cmd('show ip route json', isjson=True) - refTableFile = '{}/{}/show_ip_route.json_ref'.format(CWD, router.name) + output = router.vtysh_cmd("show ip route json", isjson=True) + refTableFile = "{}/{}/show_ip_route.json_ref".format(CWD, router.name) expected = json.loads(open(refTableFile).read()) - assertmsg = 'Zebra IPv4 Routing Table verification failed for router {}'.format(router.name) + assertmsg = "Zebra IPv4 Routing Table verification failed for router {}".format( + router.name + ) assert topotest.json_cmp(output, expected) is None, assertmsg + def test_shutdown_check_stderr(): - if os.environ.get('TOPOTESTS_CHECK_STDERR') is None: - pytest.skip('Skipping test for Stderr output and memory leaks') + if os.environ.get("TOPOTESTS_CHECK_STDERR") is None: + pytest.skip("Skipping test for Stderr output and memory leaks") tgen = get_topogen() # Don't run this test if we have any failure. @@ -179,15 +183,15 @@ def test_shutdown_check_stderr(): for router in router_list: router.stop() - log = tgen.net[router.name].getStdErr('bgpd') + log = tgen.net[router.name].getStdErr("bgpd") if log: - logger.error('BGPd StdErr Log:' + log) - log = tgen.net[router.name].getStdErr('zebra') + logger.error("BGPd StdErr Log:" + log) + log = tgen.net[router.name].getStdErr("zebra") if log: - logger.error('Zebra StdErr Log:' + log) + logger.error("Zebra StdErr Log:" + log) -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_sender-as-path-loop-detection/test_bgp_sender-as-path-loop-detection.py b/tests/topotests/bgp_sender-as-path-loop-detection/test_bgp_sender-as-path-loop-detection.py index 708464864a..56a98c1ef8 100644 --- a/tests/topotests/bgp_sender-as-path-loop-detection/test_bgp_sender-as-path-loop-detection.py +++ b/tests/topotests/bgp_sender-as-path-loop-detection/test_bgp_sender-as-path-loop-detection.py @@ -35,7 +35,7 @@ import pytest import functools CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -43,20 +43,22 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 4): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -66,38 +68,34 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_sender_as_path_loop_detection(): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) - router = tgen.gears['r2'] + router = tgen.gears["r2"] def _bgp_converge(router): output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json")) expected = { - '192.168.255.2': { - 'bgpState': 'Established', - 'addressFamilyInfo': { - 'ipv4Unicast': { - 'acceptedPrefixCounter': 2 - } - } + "192.168.255.2": { + "bgpState": "Established", + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}}, } } return topotest.json_cmp(output, expected) @@ -105,19 +103,11 @@ def test_bgp_sender_as_path_loop_detection(): def _bgp_has_route_from_r1(router): output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.254/32 json")) expected = { - 'paths': [ + "paths": [ { - 'aspath': { - 'segments': [ - { - 'type': 'as-sequence', - 'list': [ - 65001, - 65003 - ] - } - ], - 'length': 2 + "aspath": { + "segments": [{"type": "as-sequence", "list": [65001, 65003]}], + "length": 2, } } ] @@ -125,10 +115,12 @@ def test_bgp_sender_as_path_loop_detection(): return topotest.json_cmp(output, expected) def _bgp_suppress_route_to_r3(router): - output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.254.2 advertised-routes json")) - expected = { - 'totalPrefixCounter': 0 - } + output = json.loads( + router.vtysh_cmd( + "show ip bgp neighbor 192.168.254.2 advertised-routes json" + ) + ) + expected = {"totalPrefixCounter": 0} return topotest.json_cmp(output, expected) test_func = functools.partial(_bgp_converge, router) @@ -144,8 +136,11 @@ def test_bgp_sender_as_path_loop_detection(): test_func = functools.partial(_bgp_suppress_route_to_r3, router) success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) - assert result is None, 'Route 172.16.255.254/32 should not be sent to r3 "{}"'.format(router) + assert ( + result is None + ), 'Route 172.16.255.254/32 should not be sent to r3 "{}"'.format(router) -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_set_local-preference_add_subtract/test_bgp_set_local-preference_add_subtract.py b/tests/topotests/bgp_set_local-preference_add_subtract/test_bgp_set_local-preference_add_subtract.py index 387cb0b42f..ce3165db25 100644 --- a/tests/topotests/bgp_set_local-preference_add_subtract/test_bgp_set_local-preference_add_subtract.py +++ b/tests/topotests/bgp_set_local-preference_add_subtract/test_bgp_set_local-preference_add_subtract.py @@ -36,7 +36,7 @@ import pytest import functools CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -44,17 +44,19 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 4): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -64,70 +66,48 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_set_local_preference(): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) - router = tgen.gears['r1'] + router = tgen.gears["r1"] def _bgp_converge(router): output = json.loads(router.vtysh_cmd("show ip bgp neighbor json")) expected = { - '192.168.255.2': { - 'bgpState': 'Established', - 'addressFamilyInfo': { - 'ipv4Unicast': { - 'acceptedPrefixCounter': 2 - } - } + "192.168.255.2": { + "bgpState": "Established", + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}}, + }, + "192.168.255.3": { + "bgpState": "Established", + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}}, }, - '192.168.255.3': { - 'bgpState': 'Established', - 'addressFamilyInfo': { - 'ipv4Unicast': { - 'acceptedPrefixCounter': 2 - } - } - } } return topotest.json_cmp(output, expected) def _bgp_check_local_preference(router): output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.254/32 json")) expected = { - 'paths': [ - { - 'locPrf': 50, - 'nexthops': [ - { - 'ip': '192.168.255.3' - } - ] - }, - { - 'locPrf': 150, - 'nexthops': [ - { - 'ip': '192.168.255.2' - } - ] - } + "paths": [ + {"locPrf": 50, "nexthops": [{"ip": "192.168.255.3"}]}, + {"locPrf": 150, "nexthops": [{"ip": "192.168.255.2"}]}, ] } return topotest.json_cmp(output, expected) @@ -140,8 +120,11 @@ def test_bgp_set_local_preference(): test_func = functools.partial(_bgp_check_local_preference, router) success, result = topotest.run_and_expect(test_func, None, count=15, wait=0.5) - assert result is None, 'Failed to see applied BGP local-preference in "{}"'.format(router) + assert result is None, 'Failed to see applied BGP local-preference in "{}"'.format( + router + ) -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_show_ip_bgp_fqdn/test_bgp_show_ip_bgp_fqdn.py b/tests/topotests/bgp_show_ip_bgp_fqdn/test_bgp_show_ip_bgp_fqdn.py index f5119468e0..c41ae7cb2a 100644 --- a/tests/topotests/bgp_show_ip_bgp_fqdn/test_bgp_show_ip_bgp_fqdn.py +++ b/tests/topotests/bgp_show_ip_bgp_fqdn/test_bgp_show_ip_bgp_fqdn.py @@ -36,7 +36,7 @@ import pytest import functools CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -44,16 +44,18 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from mininet.topo import Topo + class TemplateTopo(Topo): def build(self, *_args, **_opts): tgen = get_topogen(self) for routern in range(1, 3): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) def setup_module(mod): tgen = Topogen(TemplateTopo, mod.__name__) @@ -63,46 +65,42 @@ def setup_module(mod): for i, (rname, router) in enumerate(router_list.iteritems(), 1): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() + def test_bgp_show_ip_bgp_hostname(): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) - router = tgen.gears['r2'] + router = tgen.gears["r2"] def _bgp_converge(router): output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) expected = { - '192.168.255.1': { - 'bgpState': 'Established', - 'addressFamilyInfo': { - 'ipv4Unicast': { - 'acceptedPrefixCounter': 2 - } - } + "192.168.255.1": { + "bgpState": "Established", + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}}, } } return topotest.json_cmp(output, expected) def _bgp_show_nexthop_hostname_and_ip(router): output = json.loads(router.vtysh_cmd("show ip bgp json")) - for nh in output['routes']['172.16.255.253/32'][0]['nexthops']: - if 'hostname' in nh and 'ip' in nh: + for nh in output["routes"]["172.16.255.253/32"][0]["nexthops"]: + if "hostname" in nh and "ip" in nh: return True return False @@ -112,6 +110,7 @@ def test_bgp_show_ip_bgp_hostname(): assert result is None, 'Failed bgp convergence in "{}"'.format(router) assert _bgp_show_nexthop_hostname_and_ip(router) == True -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py b/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py index 2944b3729c..5d8c80c6a2 100644 --- a/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py +++ b/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py @@ -35,7 +35,7 @@ import platform # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -49,17 +49,19 @@ from mininet.topo import Topo class BGPIPV6RTADVVRFTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) # Create 2 routers. - tgen.add_router('r1') - tgen.add_router('r2') + tgen.add_router("r1") + tgen.add_router("r2") + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) def setup_module(mod): "Sets up the pytest environment" @@ -68,52 +70,57 @@ def setup_module(mod): router_list = tgen.routers() - logger.info('Testing with VRF Lite support') + logger.info("Testing with VRF Lite support") krel = platform.release() # May need to adjust handling of vrf traffic depending on kernel version l3mdev_accept = 0 - if topotest.version_cmp(krel, '4.15') >= 0 and \ - topotest.version_cmp(krel, '4.18') <= 0: + if ( + topotest.version_cmp(krel, "4.15") >= 0 + and topotest.version_cmp(krel, "4.18") <= 0 + ): l3mdev_accept = 1 - if topotest.version_cmp(krel, '5.0') >= 0: + if topotest.version_cmp(krel, "5.0") >= 0: l3mdev_accept = 1 - logger.info('krel \'{0}\' setting net.ipv4.tcp_l3mdev_accept={1}'.format( - krel, l3mdev_accept)) + logger.info( + "krel '{0}' setting net.ipv4.tcp_l3mdev_accept={1}".format(krel, l3mdev_accept) + ) - cmds = ['ip link add {0}-cust1 type vrf table 1001', - 'ip link add loop1 type dummy', - 'ip link set loop1 master {0}-cust1', - 'ip link set {0}-eth0 master {0}-cust1'] + cmds = [ + "ip link add {0}-cust1 type vrf table 1001", + "ip link add loop1 type dummy", + "ip link set loop1 master {0}-cust1", + "ip link set {0}-eth0 master {0}-cust1", + ] for rname, router in router_list.iteritems(): for cmd in cmds: output = tgen.net[rname].cmd(cmd.format(rname)) - output = tgen.net[rname].cmd('sysctl -n net.ipv4.tcp_l3mdev_accept') + output = tgen.net[rname].cmd("sysctl -n net.ipv4.tcp_l3mdev_accept") logger.info( - 'router {0}: existing tcp_l3mdev_accept was {1}'.format( - rname, output)) + "router {0}: existing tcp_l3mdev_accept was {1}".format(rname, output) + ) if l3mdev_accept: output = tgen.net[rname].cmd( - 'sysctl -w net.ipv4.tcp_l3mdev_accept={}'.format(l3mdev_accept)) + "sysctl -w net.ipv4.tcp_l3mdev_accept={}".format(l3mdev_accept) + ) for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) # Initialize all routers. tgen.start_router() + def teardown_module(_mod): "Teardown the pytest environment" tgen = get_topogen() @@ -134,44 +141,51 @@ def test_protocols_convergence(): logger.info("Checking IPv4 routes for convergence") for router in tgen.routers().values(): - json_file = '{}/{}/ipv4_routes.json'.format(CWD, router.name) + json_file = "{}/{}/ipv4_routes.json".format(CWD, router.name) if not os.path.isfile(json_file): - logger.info('skipping file {}'.format(json_file)) + logger.info("skipping file {}".format(json_file)) continue expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show ip route vrf {}-cust1 json'.format(router.name), expected) - _, result = topotest.run_and_expect(test_func, None, count=160, - wait=0.5) + test_func = partial( + topotest.router_json_cmp, + router, + "show ip route vrf {}-cust1 json".format(router.name), + expected, + ) + _, result = topotest.run_and_expect(test_func, None, count=160, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg # Check IPv6 routing tables. logger.info("Checking IPv6 routes for convergence") for router in tgen.routers().values(): - json_file = '{}/{}/ipv6_routes.json'.format(CWD, router.name) + json_file = "{}/{}/ipv6_routes.json".format(CWD, router.name) if not os.path.isfile(json_file): - logger.info('skipping file {}'.format(json_file)) + logger.info("skipping file {}".format(json_file)) continue expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - router, 'show ipv6 route vrf {}-cust1 json'.format(router.name), expected) - _, result = topotest.run_and_expect(test_func, None, count=160, - wait=0.5) + test_func = partial( + topotest.router_json_cmp, + router, + "show ipv6 route vrf {}-cust1 json".format(router.name), + expected, + ) + _, result = topotest.run_and_expect(test_func, None, count=160, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg + def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_vrf_netns/peer1/exa-receive.py b/tests/topotests/bgp_vrf_netns/peer1/exa-receive.py index 5334ea5369..031ff455ca 100755 --- a/tests/topotests/bgp_vrf_netns/peer1/exa-receive.py +++ b/tests/topotests/bgp_vrf_netns/peer1/exa-receive.py @@ -4,7 +4,7 @@ exa-receive.py: Save received routes form ExaBGP into file """ -from sys import stdin,argv +from sys import stdin, argv from datetime import datetime # 1st arg is peer number @@ -13,12 +13,12 @@ peer = int(argv[1]) # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 0 -routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') +routesavefile = open("/tmp/peer%s-received.log" % peer, "w") while True: try: line = stdin.readline() - timestamp = datetime.now().strftime('%Y%m%d_%H:%M:%S - ') + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") routesavefile.write(timestamp + line) routesavefile.flush() diff --git a/tests/topotests/bgp_vrf_netns/peer1/exa-send.py b/tests/topotests/bgp_vrf_netns/peer1/exa-send.py index 9a2a201c57..9279cc45ff 100755 --- a/tests/topotests/bgp_vrf_netns/peer1/exa-send.py +++ b/tests/topotests/bgp_vrf_netns/peer1/exa-send.py @@ -4,7 +4,7 @@ exa-send.py: Send a few testroutes with ExaBGP """ -from sys import stdout,argv +from sys import stdout, argv from time import sleep sleep(5) @@ -17,10 +17,12 @@ asnum = 99 # Announce numRoutes equal routes per PE - different neighbor AS for i in range(0, numRoutes): - stdout.write('announce route 10.201.%s.0/24 med 100 community %i:1 next-hop 10.0.%i.%i\n' % (i, i, (((peer-1) / 5) + 1), peer+100)) + stdout.write( + "announce route 10.201.%s.0/24 med 100 community %i:1 next-hop 10.0.%i.%i\n" + % (i, i, (((peer - 1) / 5) + 1), peer + 100) + ) stdout.flush() -#Loop endlessly to allow ExaBGP to continue running +# Loop endlessly to allow ExaBGP to continue running while True: sleep(1) - diff --git a/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py b/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py index a5590bcaf6..ae48f01a0e 100755 --- a/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py +++ b/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py @@ -33,7 +33,7 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -53,6 +53,7 @@ CustomizeVrfWithNetns = True ## ##################################################### + class BGPVRFNETNSTopo1(Topo): "BGP EBGP VRF NETNS Topology 1" @@ -60,18 +61,17 @@ class BGPVRFNETNSTopo1(Topo): tgen = get_topogen(self) # Setup Routers - tgen.add_router('r1') + tgen.add_router("r1") # Setup Switches - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) # Add eBGP ExaBGP neighbors - peer_ip = '10.0.1.101' - peer_route = 'via 10.0.1.1' - peer = tgen.add_exabgp_peer('peer1', - ip=peer_ip, defaultRoute=peer_route) - switch = tgen.gears['s1'] + peer_ip = "10.0.1.101" + peer_route = "via 10.0.1.1" + peer = tgen.add_exabgp_peer("peer1", ip=peer_ip, defaultRoute=peer_route) + switch = tgen.gears["s1"] switch.add_link(peer) @@ -81,74 +81,87 @@ class BGPVRFNETNSTopo1(Topo): ## ##################################################### + def setup_module(module): tgen = Topogen(BGPVRFNETNSTopo1, module.__name__) tgen.start_topology() # Get r1 reference - router = tgen.gears['r1'] + router = tgen.gears["r1"] # check for zebra capability if CustomizeVrfWithNetns == True: - if router.check_capability( - TopoRouter.RD_ZEBRA, - '--vrfwnetns' - ) == False: - return pytest.skip('Skipping BGP VRF NETNS Test. VRF NETNS backend not available on FRR') - if os.system('ip netns list') != 0: - return pytest.skip('Skipping BGP VRF NETNS Test. NETNS not available on System') + if router.check_capability(TopoRouter.RD_ZEBRA, "--vrfwnetns") == False: + return pytest.skip( + "Skipping BGP VRF NETNS Test. VRF NETNS backend not available on FRR" + ) + if os.system("ip netns list") != 0: + return pytest.skip( + "Skipping BGP VRF NETNS Test. NETNS not available on System" + ) # retrieve VRF backend kind if CustomizeVrfWithNetns == True: - logger.info('Testing with VRF Namespace support') + logger.info("Testing with VRF Namespace support") # create VRF r1-cust1 # move r1-eth0 to VRF r1-cust1 - cmds = ['if [ -e /var/run/netns/{0}-cust1 ] ; then ip netns del {0}-cust1 ; fi', - 'ip netns add {0}-cust1', - 'ip link set dev {0}-eth0 netns {0}-cust1', - 'ip netns exec {0}-cust1 ifconfig {0}-eth0 up'] + cmds = [ + "if [ -e /var/run/netns/{0}-cust1 ] ; then ip netns del {0}-cust1 ; fi", + "ip netns add {0}-cust1", + "ip link set dev {0}-eth0 netns {0}-cust1", + "ip netns exec {0}-cust1 ifconfig {0}-eth0 up", + ] for cmd in cmds: - cmd = cmd.format('r1') - logger.info('cmd: '+cmd); - output = router.run(cmd.format('r1')) + cmd = cmd.format("r1") + logger.info("cmd: " + cmd) + output = router.run(cmd.format("r1")) if output != None and len(output) > 0: - logger.info('Aborting due to unexpected output: cmd="{}" output=\n{}'.format(cmd, output)) - return pytest.skip('Skipping BGP VRF NETNS Test. Unexpected output to command: '+cmd) - #run daemons + logger.info( + 'Aborting due to unexpected output: cmd="{}" output=\n{}'.format( + cmd, output + ) + ) + return pytest.skip( + "Skipping BGP VRF NETNS Test. Unexpected output to command: " + cmd + ) + # run daemons router.load_config( TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format('r1')), - '--vrfwnetns' + os.path.join(CWD, "{}/zebra.conf".format("r1")), + "--vrfwnetns", ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format('r1')) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format("r1")) ) - logger.info('Launching BGP and ZEBRA') + logger.info("Launching BGP and ZEBRA") # BGP and ZEBRA start without underlying VRF router.start() # Starting Hosts and init ExaBGP on each of them - logger.info('starting exaBGP on peer1') + logger.info("starting exaBGP on peer1") peer_list = tgen.exabgp_peers() for pname, peer in peer_list.iteritems(): peer_dir = os.path.join(CWD, pname) - env_file = os.path.join(CWD, 'exabgp.env') - logger.info('Running ExaBGP peer') + env_file = os.path.join(CWD, "exabgp.env") + logger.info("Running ExaBGP peer") peer.start(peer_dir, env_file) logger.info(pname) + def teardown_module(module): tgen = get_topogen() # move back r1-eth0 to default VRF # delete VRF r1-cust1 - cmds = ['ip netns exec {0}-cust1 ip link set {0}-eth0 netns 1', - 'ip netns delete {0}-cust1'] + cmds = [ + "ip netns exec {0}-cust1 ip link set {0}-eth0 netns 1", + "ip netns delete {0}-cust1", + ] for cmd in cmds: - tgen.net['r1'].cmd(cmd.format('r1')) + tgen.net["r1"].cmd(cmd.format("r1")) tgen.stop_topology() + def test_bgp_vrf_learn(): "Test daemon learnt VRF context" tgen = get_topogen() @@ -158,11 +171,11 @@ def test_bgp_vrf_learn(): pytest.skip(tgen.errors) # Expected result - output = tgen.gears['r1'].vtysh_cmd("show vrf", isjson=False) - logger.info('output is: {}'.format(output)) + output = tgen.gears["r1"].vtysh_cmd("show vrf", isjson=False) + logger.info("output is: {}".format(output)) - output = tgen.gears['r1'].vtysh_cmd("show bgp vrfs", isjson=False) - logger.info('output is: {}'.format(output)) + output = tgen.gears["r1"].vtysh_cmd("show bgp vrfs", isjson=False) + logger.info("output is: {}".format(output)) def test_bgp_convergence(): @@ -175,23 +188,25 @@ def test_bgp_convergence(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('waiting for bgp convergence') + logger.info("waiting for bgp convergence") # Expected result - router = tgen.gears['r1'] - if router.has_version('<', '3.0'): - reffile = os.path.join(CWD, 'r1/summary20.txt') + router = tgen.gears["r1"] + if router.has_version("<", "3.0"): + reffile = os.path.join(CWD, "r1/summary20.txt") else: - reffile = os.path.join(CWD, 'r1/summary.txt') + reffile = os.path.join(CWD, "r1/summary.txt") expected = json.loads(open(reffile).read()) - test_func = functools.partial(topotest.router_json_cmp, - router, 'show bgp vrf r1-cust1 summary json', expected) + test_func = functools.partial( + topotest.router_json_cmp, router, "show bgp vrf r1-cust1 summary json", expected + ) _, res = topotest.run_and_expect(test_func, None, count=90, wait=0.5) - assertmsg = 'BGP router network did not converge' + assertmsg = "BGP router network did not converge" assert res is None, assertmsg + def test_bgp_vrf_netns(): tgen = get_topogen() @@ -200,24 +215,28 @@ def test_bgp_vrf_netns(): pytest.skip(tgen.errors) expect = { - 'routerId': '10.0.1.1', - 'routes': { - }, + "routerId": "10.0.1.1", + "routes": {}, } for subnet in range(0, 10): - netkey = '10.201.{}.0/24'.format(subnet) - expect['routes'][netkey] = [] - peer = {'valid': True} - expect['routes'][netkey].append(peer) + netkey = "10.201.{}.0/24".format(subnet) + expect["routes"][netkey] = [] + peer = {"valid": True} + expect["routes"][netkey].append(peer) - test_func = functools.partial(topotest.router_json_cmp, - tgen.gears['r1'], 'show ip bgp vrf r1-cust1 ipv4 json', expect) + test_func = functools.partial( + topotest.router_json_cmp, + tgen.gears["r1"], + "show ip bgp vrf r1-cust1 ipv4 json", + expect, + ) _, res = topotest.run_and_expect(test_func, None, count=12, wait=0.5) assertmsg = 'expected routes in "show ip bgp vrf r1-cust1 ipv4" output' assert res is None, assertmsg -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] ret = pytest.main(args) diff --git a/tests/topotests/conftest.py b/tests/topotests/conftest.py index 76b0ab017e..d46c52a4c4 100755 --- a/tests/topotests/conftest.py +++ b/tests/topotests/conftest.py @@ -9,13 +9,18 @@ import pytest topology_only = False + def pytest_addoption(parser): """ Add topology-only option to the topology tester. This option makes pytest only run the setup_module() to setup the topology without running any tests. """ - parser.addoption('--topology-only', action='store_true', - help='Only set up this topology, don\'t run tests') + parser.addoption( + "--topology-only", + action="store_true", + help="Only set up this topology, don't run tests", + ) + def pytest_runtest_call(): """ @@ -30,7 +35,8 @@ def pytest_runtest_call(): # Allow user to play with the setup. tgen.mininet_cli() - pytest.exit('the topology executed successfully') + pytest.exit("the topology executed successfully") + def pytest_assertrepr_compare(op, left, right): """ @@ -44,17 +50,19 @@ def pytest_assertrepr_compare(op, left, right): return json_result.errors + def pytest_configure(config): "Assert that the environment is correctly configured." global topology_only if not diagnose_env(): - pytest.exit('enviroment has errors, please read the logs') + pytest.exit("enviroment has errors, please read the logs") - if config.getoption('--topology-only'): + if config.getoption("--topology-only"): topology_only = True + def pytest_runtest_makereport(item, call): "Log all assert messages to default logger with error level" # Nothing happened @@ -65,18 +73,22 @@ def pytest_runtest_makereport(item, call): modname = parent.module.__name__ # Treat skips as non errors - if call.excinfo.typename != 'AssertionError': - logger.info('assert skipped at "{}/{}": {}'.format( - modname, item.name, call.excinfo.value)) + if call.excinfo.typename != "AssertionError": + logger.info( + 'assert skipped at "{}/{}": {}'.format( + modname, item.name, call.excinfo.value + ) + ) return # Handle assert failures parent._previousfailed = item - logger.error('assert failed at "{}/{}": {}'.format( - modname, item.name, call.excinfo.value)) + logger.error( + 'assert failed at "{}/{}": {}'.format(modname, item.name, call.excinfo.value) + ) # (topogen) Set topology error to avoid advancing in the test. tgen = get_topogen() if tgen is not None: # This will cause topogen to report error on `routers_have_failure`. - tgen.set_error('{}/{}'.format(modname, item.name)) + tgen.set_error("{}/{}".format(modname, item.name)) diff --git a/tests/topotests/eigrp-topo1/test_eigrp_topo1.py b/tests/topotests/eigrp-topo1/test_eigrp_topo1.py index 1c00face43..c1dd88823b 100755 --- a/tests/topotests/eigrp-topo1/test_eigrp_topo1.py +++ b/tests/topotests/eigrp-topo1/test_eigrp_topo1.py @@ -35,7 +35,7 @@ import json # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -52,6 +52,7 @@ from mininet.topo import Topo ## ##################################################### + class NetworkTopo(Topo): "EIGRP Topology 1" @@ -61,27 +62,27 @@ class NetworkTopo(Topo): tgen = get_topogen(self) for routern in range(1, 4): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) # On main router # First switch is for a dummy interface (for local network) - switch = tgen.add_switch('sw1') - switch.add_link(tgen.gears['r1']) + switch = tgen.add_switch("sw1") + switch.add_link(tgen.gears["r1"]) # Switches for EIGRP # switch 2 switch is for connection to EIGRP router - switch = tgen.add_switch('sw2') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("sw2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) # switch 4 is stub on remote EIGRP router - switch = tgen.add_switch('sw4') - switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch("sw4") + switch.add_link(tgen.gears["r3"]) # switch 3 is between EIGRP routers - switch = tgen.add_switch('sw3') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch("sw3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) ##################################################### @@ -90,6 +91,7 @@ class NetworkTopo(Topo): ## ##################################################### + def setup_module(module): "Setup topology" tgen = Topogen(NetworkTopo, module.__name__) @@ -99,12 +101,10 @@ def setup_module(module): router_list = tgen.routers() for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_EIGRP, - os.path.join(CWD, '{}/eigrpd.conf'.format(rname)) + TopoRouter.RD_EIGRP, os.path.join(CWD, "{}/eigrpd.conf".format(rname)) ) tgen.start_router() @@ -126,7 +126,7 @@ def test_converge_protocols(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - topotest.sleep(5, 'Waiting for EIGRP convergence') + topotest.sleep(5, "Waiting for EIGRP convergence") def test_eigrp_routes(): @@ -142,7 +142,7 @@ def test_eigrp_routes(): router_list = tgen.routers().values() for router in router_list: - refTableFile = '{}/{}/show_ip_eigrp.json'.format(CWD, router.name) + refTableFile = "{}/{}/show_ip_eigrp.json".format(CWD, router.name) # Read expected result from file expected = json.loads(open(refTableFile).read()) @@ -153,6 +153,7 @@ def test_eigrp_routes(): assertmsg = '"show ip eigrp topo" mismatches on {}'.format(router.name) assert topotest.json_cmp(actual, expected) is None, assertmsg + def test_zebra_ipv4_routingTable(): "Test 'show ip route'" @@ -164,27 +165,29 @@ def test_zebra_ipv4_routingTable(): failures = 0 router_list = tgen.routers().values() for router in router_list: - output = router.vtysh_cmd('show ip route json', isjson=True) - refTableFile = '{}/{}/show_ip_route.json_ref'.format(CWD, router.name) + output = router.vtysh_cmd("show ip route json", isjson=True) + refTableFile = "{}/{}/show_ip_route.json_ref".format(CWD, router.name) expected = json.loads(open(refTableFile).read()) - assertmsg = 'Zebra IPv4 Routing Table verification failed for router {}'.format(router.name) + assertmsg = "Zebra IPv4 Routing Table verification failed for router {}".format( + router.name + ) assert topotest.json_cmp(output, expected) is None, assertmsg + def test_shut_interface_and_recover(): "Test shutdown of an interface and recovery of the interface" tgen = get_topogen() - router = tgen.gears['r1'] - router.run('ip link set r1-eth1 down') - topotest.sleep(5, 'Waiting for EIGRP convergence') - router.run('ip link set r1-eth1 up') - + router = tgen.gears["r1"] + router.run("ip link set r1-eth1 down") + topotest.sleep(5, "Waiting for EIGRP convergence") + router.run("ip link set r1-eth1 up") def test_shutdown_check_stderr(): - if os.environ.get('TOPOTESTS_CHECK_STDERR') is None: - pytest.skip('Skipping test for Stderr output and memory leaks') + if os.environ.get("TOPOTESTS_CHECK_STDERR") is None: + pytest.skip("Skipping test for Stderr output and memory leaks") tgen = get_topogen() # Don't run this test if we have any failure. @@ -197,15 +200,15 @@ def test_shutdown_check_stderr(): for router in router_list: router.stop() - log = tgen.net[router.name].getStdErr('eigrpd') + log = tgen.net[router.name].getStdErr("eigrpd") if log: - logger.error('EIGRPd StdErr Log:' + log) - log = tgen.net[router.name].getStdErr('zebra') + logger.error("EIGRPd StdErr Log:" + log) + log = tgen.net[router.name].getStdErr("zebra") if log: - logger.error('Zebra StdErr Log:' + log) + logger.error("Zebra StdErr Log:" + log) -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) @@ -237,23 +240,23 @@ def ip_eigrp_topo(node): } } """ - output = topotest.normalize_text(node.vtysh_cmd('show ip eigrp topo')).splitlines() + output = topotest.normalize_text(node.vtysh_cmd("show ip eigrp topo")).splitlines() result = {} for idx, line in enumerate(output): - columns = line.split(' ', 1) + columns = line.split(" ", 1) # Parse the following format into python dicts # code A.B.C.D/E, X successors, FD is Y, serno: Z # via FOO, interface-name code = columns[0] - if code not in ['P', 'A', 'U', 'Q', 'R', 'r', 's']: + if code not in ["P", "A", "U", "Q", "R", "r", "s"]: continue if not result.has_key(code): result[code] = {} # Split network from the rest - columns = columns[1].split(',') + columns = columns[1].split(",") # Parse first line data network = columns[0] @@ -263,33 +266,33 @@ def ip_eigrp_topo(node): if column == columns[0]: continue - match = re.search(r'(\d+) successors', column) + match = re.search(r"(\d+) successors", column) if match is not None: - result[code][network]['successors'] = match.group(1) + result[code][network]["successors"] = match.group(1) continue - match = re.search(r'FD is (\d+)', column) + match = re.search(r"FD is (\d+)", column) if match is not None: - result[code][network]['fd'] = match.group(1) + result[code][network]["fd"] = match.group(1) continue - match = re.search(r'serno: (\d+)', column) + match = re.search(r"serno: (\d+)", column) if match is not None: - result[code][network]['serno'] = match.group(1) + result[code][network]["serno"] = match.group(1) continue # Parse second line data nextline = output[idx + 1] - columns = topotest.normalize_text(nextline).split(',') + columns = topotest.normalize_text(nextline).split(",") for column in columns: - match = re.search(r'via (.+)', column) + match = re.search(r"via (.+)", column) if match is not None: - result[code][network]['via'] = match.group(1) + result[code][network]["via"] = match.group(1) continue - match = re.search(r'(.+)', column) + match = re.search(r"(.+)", column) if match is not None: - result[code][network]['interface'] = match.group(1) + result[code][network]["interface"] = match.group(1) continue return result diff --git a/tests/topotests/evpn-pim-1/test_evpn_pim_topo1.py b/tests/topotests/evpn-pim-1/test_evpn_pim_topo1.py index dafe2e03ac..94bb91d49f 100755 --- a/tests/topotests/evpn-pim-1/test_evpn_pim_topo1.py +++ b/tests/topotests/evpn-pim-1/test_evpn_pim_topo1.py @@ -36,7 +36,7 @@ from functools import partial # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -53,6 +53,7 @@ from mininet.topo import Topo ## ##################################################### + class NetworkTopo(Topo): "evpn-pim Topology 1" @@ -61,34 +62,33 @@ class NetworkTopo(Topo): tgen = get_topogen(self) - tgen.add_router('spine') - tgen.add_router('leaf1') - tgen.add_router('leaf2') - tgen.add_router('host1') - tgen.add_router('host2') + tgen.add_router("spine") + tgen.add_router("leaf1") + tgen.add_router("leaf2") + tgen.add_router("host1") + tgen.add_router("host2") # On main router # First switch is for a dummy interface (for local network) # spine-eth0 is connected to leaf1-eth0 - switch = tgen.add_switch('sw1') - switch.add_link(tgen.gears['spine']) - switch.add_link(tgen.gears['leaf1']) + switch = tgen.add_switch("sw1") + switch.add_link(tgen.gears["spine"]) + switch.add_link(tgen.gears["leaf1"]) # spine-eth1 is connected to leaf2-eth0 - switch = tgen.add_switch('sw2') - switch.add_link(tgen.gears['spine']) - switch.add_link(tgen.gears['leaf2']) + switch = tgen.add_switch("sw2") + switch.add_link(tgen.gears["spine"]) + switch.add_link(tgen.gears["leaf2"]) # leaf1-eth1 is connected to host1-eth0 - switch = tgen.add_switch('sw3') - switch.add_link(tgen.gears['leaf1']) - switch.add_link(tgen.gears['host1']) + switch = tgen.add_switch("sw3") + switch.add_link(tgen.gears["leaf1"]) + switch.add_link(tgen.gears["host1"]) # leaf2-eth1 is connected to host2-eth0 - switch = tgen.add_switch('sw4') - switch.add_link(tgen.gears['leaf2']) - switch.add_link(tgen.gears['host2']) - + switch = tgen.add_switch("sw4") + switch.add_link(tgen.gears["leaf2"]) + switch.add_link(tgen.gears["host2"]) ##################################################### @@ -97,42 +97,45 @@ class NetworkTopo(Topo): ## ##################################################### + def setup_module(module): "Setup topology" tgen = Topogen(NetworkTopo, module.__name__) tgen.start_topology() - leaf1 = tgen.gears['leaf1'] - leaf2 = tgen.gears['leaf2'] + leaf1 = tgen.gears["leaf1"] + leaf2 = tgen.gears["leaf2"] - leaf1.run('brctl addbr brleaf1') - leaf2.run('brctl addbr brleaf2') - leaf1.run('ip link set dev brleaf1 up') - leaf2.run('ip link set dev brleaf2 up') - leaf1.run('ip link add vxlan0 type vxlan id 42 group 239.1.1.1 dev leaf1-eth1 dstport 4789') - leaf2.run('ip link add vxlan0 type vxlan id 42 group 239.1.1.1 dev leaf2-eth1 dstport 4789') - leaf1.run('brctl addif brleaf1 vxlan0') - leaf2.run('brctl addif brleaf2 vxlan0') - leaf1.run('ip link set up dev vxlan0') - leaf2.run('ip link set up dev vxlan0') - #tgen.mininet_cli() + leaf1.run("brctl addbr brleaf1") + leaf2.run("brctl addbr brleaf2") + leaf1.run("ip link set dev brleaf1 up") + leaf2.run("ip link set dev brleaf2 up") + leaf1.run( + "ip link add vxlan0 type vxlan id 42 group 239.1.1.1 dev leaf1-eth1 dstport 4789" + ) + leaf2.run( + "ip link add vxlan0 type vxlan id 42 group 239.1.1.1 dev leaf2-eth1 dstport 4789" + ) + leaf1.run("brctl addif brleaf1 vxlan0") + leaf2.run("brctl addif brleaf2 vxlan0") + leaf1.run("ip link set up dev vxlan0") + leaf2.run("ip link set up dev vxlan0") + # tgen.mininet_cli() # This is a sample of configuration loading. router_list = tgen.routers() for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) router.load_config( - TopoRouter.RD_PIM, - os.path.join(CWD, '{}/pimd.conf'.format(rname)) + TopoRouter.RD_PIM, os.path.join(CWD, "{}/pimd.conf".format(rname)) ) tgen.start_router() - #tgen.mininet_cli() + # tgen.mininet_cli() + def teardown_module(_mod): "Teardown the pytest environment" @@ -150,16 +153,18 @@ def test_converge_protocols(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - spine = tgen.gears['spine'] - json_file = '{}/{}/bgp.summ.json'.format(CWD, spine.name) + spine = tgen.gears["spine"] + json_file = "{}/{}/bgp.summ.json".format(CWD, spine.name) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - spine, 'show bgp ipv4 uni summ json', expected) + test_func = partial( + topotest.router_json_cmp, spine, "show bgp ipv4 uni summ json", expected + ) _, result = topotest.run_and_expect(test_func, None, count=125, wait=1) assertmsg = '"{}" JSON output mismatches'.format(spine.name) assert result is None, assertmsg - #tgen.mininet_cli() + # tgen.mininet_cli() + def test_multicast_groups_on_rp(): "Ensure the multicast groups show up on the spine" @@ -172,20 +177,22 @@ def test_multicast_groups_on_rp(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - spine = tgen.gears['spine'] - json_file = '{}/{}/join-info.json'.format(CWD, spine.name) + spine = tgen.gears["spine"] + json_file = "{}/{}/join-info.json".format(CWD, spine.name) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - spine, 'show ip pim join json', expected) + test_func = partial( + topotest.router_json_cmp, spine, "show ip pim join json", expected + ) _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) assertmsg = '"{}" JSON output mismatches'.format(spine.name) assert result is None, assertmsg - #tgen.mininet_cli() + # tgen.mininet_cli() + def test_shutdown_check_stderr(): - if os.environ.get('TOPOTESTS_CHECK_STDERR') is None: - pytest.skip('Skipping test for Stderr output and memory leaks') + if os.environ.get("TOPOTESTS_CHECK_STDERR") is None: + pytest.skip("Skipping test for Stderr output and memory leaks") tgen = get_topogen() # Don't run this test if we have any failure. @@ -198,18 +205,17 @@ def test_shutdown_check_stderr(): for router in router_list: router.stop() - log = tgen.net[router.name].getStdErr('pimd') + log = tgen.net[router.name].getStdErr("pimd") if log: - logger.error('PIMd StdErr Log:' + log) - log = tgen.net[router.name].getStdErr('bgpd') + logger.error("PIMd StdErr Log:" + log) + log = tgen.net[router.name].getStdErr("bgpd") if log: - logger.error('BGPd StdErr Log:' + log) - log = tgen.net[router.name].getStdErr('zebra') + logger.error("BGPd StdErr Log:" + log) + log = tgen.net[router.name].getStdErr("zebra") if log: - logger.error('Zebra StdErr Log:' + log) + logger.error("Zebra StdErr Log:" + log) -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) - diff --git a/tests/topotests/example-test/test_example.py b/tests/topotests/example-test/test_example.py index 8e37ad11d4..72eceee612 100755 --- a/tests/topotests/example-test/test_example.py +++ b/tests/topotests/example-test/test_example.py @@ -9,52 +9,61 @@ import pytest fatal_error = "" + def setup_module(module): - print ("setup_module module:%s" % module.__name__) + print("setup_module module:%s" % module.__name__) + def teardown_module(module): - print ("teardown_module module:%s" % module.__name__) + print("teardown_module module:%s" % module.__name__) + def setup_function(function): - print ("setup_function function:%s" % function.__name__) + print("setup_function function:%s" % function.__name__) + def teardown_function(function): - print ("teardown_function function:%s" % function.__name__) + print("teardown_function function:%s" % function.__name__) + def test_numbers_compare(): a = 12 - print ("Dummy Output") - assert( a == 12 ) + print("Dummy Output") + assert a == 12 + def test_fail_example(): assert True, "Some Text with explaination in case of failure" + def test_ls_exits_zero(): "Tests for ls command on invalid file" global fatal_error proc = subprocess.Popen( - ["ls", "/some/nonexistant/file"], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + ["ls", "/some/nonexistant/file"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, ) stdout, stderr = proc.communicate() - if (proc.returncode != 0): + if proc.returncode != 0: # Mark this as a fatal error which skips some other tests on failure fatal_error = "test_fail_example failed" assert proc.returncode == 0, "Return Code is non-Zero:\n%s" % stderr + def test_skipped_on_fatalerror(): global fatal_error # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) assert True, "Some Text with explaination in case of failure" -if __name__ == '__main__': + +if __name__ == "__main__": retval = pytest.main(["-s"]) sys.exit(retval) diff --git a/tests/topotests/example-test/test_template.py b/tests/topotests/example-test/test_template.py index 4e35ce8b9f..afe974876a 100755 --- a/tests/topotests/example-test/test_template.py +++ b/tests/topotests/example-test/test_template.py @@ -32,7 +32,7 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -43,8 +43,10 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from mininet.topo import Topo + class TemplateTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) @@ -56,17 +58,18 @@ class TemplateTopo(Topo): # # Create 2 routers for routern in range(1, 3): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) # Create a switch with just one router connected to it to simulate a # empty network. - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) # Create a connection between r1 and r2 - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + def setup_module(mod): "Sets up the pytest environment" @@ -83,12 +86,13 @@ def setup_module(mod): router.load_config( TopoRouter.RD_ZEBRA, # Uncomment next line to load configuration from ./router/zebra.conf - #os.path.join(CWD, '{}/zebra.conf'.format(rname)) + # os.path.join(CWD, '{}/zebra.conf'.format(rname)) ) # After loading the configurations, this function loads configured daemons. tgen.start_router() + def teardown_module(mod): "Teardown the pytest environment" tgen = get_topogen() @@ -96,6 +100,7 @@ def teardown_module(mod): # This function tears down the whole topology. tgen.stop_topology() + def test_call_mininet_cli(): "Dummy test that just calls mininet CLI so we can interact with the build." tgen = get_topogen() @@ -103,18 +108,20 @@ def test_call_mininet_cli(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('calling mininet CLI') + logger.info("calling mininet CLI") tgen.mininet_cli() + # Memory leak test template def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/example-topojson-test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py b/tests/topotests/example-topojson-test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py index 8e794b9946..f24f463b8a 100755 --- a/tests/topotests/example-topojson-test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py +++ b/tests/topotests/example-topojson-test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py @@ -33,8 +33,8 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) -sys.path.append(os.path.join(CWD, '../../')) +sys.path.append(os.path.join(CWD, "../")) +sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 from lib.topogen import Topogen, get_topogen @@ -44,19 +44,19 @@ from mininet.topo import Topo # Import topoJson from lib, to create topology and initial configuration from lib.common_config import ( - start_topology, write_test_header, - write_test_footer, verify_rib + start_topology, + write_test_header, + write_test_footer, + verify_rib, ) from lib.topolog import logger -from lib.bgp import ( - verify_bgp_convergence -) +from lib.bgp import verify_bgp_convergence from lib.topojson import build_topo_from_json, build_config_from_json # Reading the data from JSON File for topology and configuration creation jsonFile = "{}/example_topojson_multiple_links.json".format(CWD) try: - with open(jsonFile, 'r') as topoJson: + with open(jsonFile, "r") as topoJson: topo = json.load(topoJson) except IOError: assert False, "Could not read file {}".format(jsonFile) @@ -155,8 +155,9 @@ def test_bgp_convergence(request): # Api call verify whether BGP is converged bgp_convergence = verify_bgp_convergence(tgen, topo) - assert bgp_convergence is True, "test_bgp_convergence failed.. \n" \ - " Error: {}".format(bgp_convergence) + assert ( + bgp_convergence is True + ), "test_bgp_convergence failed.. \n" " Error: {}".format(bgp_convergence) logger.info("BGP is converged successfully \n") write_test_footer(tc_name) @@ -167,7 +168,7 @@ def test_static_routes(request): tgen = get_topogen() if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name @@ -175,20 +176,19 @@ def test_static_routes(request): # Static routes are created as part of initial configuration, # verifying RIB - dut = 'r3' - protocol = 'bgp' - next_hop = '10.0.0.1' + dut = "r3" + protocol = "bgp" + next_hop = "10.0.0.1" input_dict = {"r1": topo["routers"]["r1"]} # Uncomment below to debug # tgen.mininet_cli() - result = verify_rib(tgen, 'ipv4', dut, input_dict, next_hop=next_hop) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + result = verify_rib(tgen, "ipv4", dut, input_dict, next_hop=next_hop) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/example-topojson-test/test_topo_json_single_link/test_example_topojson.py b/tests/topotests/example-topojson-test/test_topo_json_single_link/test_example_topojson.py index 315c7b3f2d..3ae3c9f4fe 100755 --- a/tests/topotests/example-topojson-test/test_topo_json_single_link/test_example_topojson.py +++ b/tests/topotests/example-topojson-test/test_topo_json_single_link/test_example_topojson.py @@ -32,31 +32,31 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) -sys.path.append(os.path.join(CWD, '../../')) +sys.path.append(os.path.join(CWD, "../")) +sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 -from lib.topogen import Topogen, get_topogen +from lib.topogen import Topogen, get_topogen # Required to instantiate the topology builder class. from mininet.topo import Topo # Import topoJson from lib, to create topology and initial configuration from lib.common_config import ( - start_topology, write_test_header, - write_test_footer, verify_rib + start_topology, + write_test_header, + write_test_footer, + verify_rib, ) from lib.topolog import logger -from lib.bgp import ( - verify_bgp_convergence -) +from lib.bgp import verify_bgp_convergence from lib.topojson import build_topo_from_json, build_config_from_json # Reading the data from JSON File for topology and configuration creation jsonFile = "{}/example_topojson.json".format(CWD) try: - with open(jsonFile, 'r') as topoJson: + with open(jsonFile, "r") as topoJson: topo = json.load(topoJson) except IOError: assert False, "Could not read file {}".format(jsonFile) @@ -65,6 +65,7 @@ except IOError: bgp_convergence = False input_dict = {} + class TemplateTopo(Topo): """ Test topology builder @@ -87,6 +88,7 @@ class TemplateTopo(Topo): # Building topology from json file build_topo_from_json(tgen, topo) + def setup_module(mod): """ Sets up the pytest environment @@ -96,7 +98,7 @@ def setup_module(mod): testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) - logger.info("="*40) + logger.info("=" * 40) logger.info("Running setup_module to create topology") @@ -122,6 +124,7 @@ def setup_module(mod): logger.info("Running setup_module() done") + def teardown_module(mod): """ Teardown the pytest environment @@ -152,8 +155,9 @@ def test_bgp_convergence(request): # Api call verify whether BGP is converged bgp_convergence = verify_bgp_convergence(tgen, topo) - assert bgp_convergence is True, "test_bgp_convergence failed.. \n"\ - " Error: {}".format(bgp_convergence) + assert ( + bgp_convergence is True + ), "test_bgp_convergence failed.. \n" " Error: {}".format(bgp_convergence) logger.info("BGP is converged successfully \n") write_test_footer(tc_name) @@ -164,7 +168,7 @@ def test_static_routes(request): tgen = get_topogen() if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name @@ -172,19 +176,18 @@ def test_static_routes(request): # Static routes are created as part of initial configuration, # verifying RIB - dut = 'r3' - next_hop = '10.0.0.1' + dut = "r3" + next_hop = "10.0.0.1" input_dict = {"r1": topo["routers"]["r1"]} # Uncomment below to debug # tgen.mininet_cli() - result = verify_rib(tgen, 'ipv4', dut, input_dict, next_hop=next_hop) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + result = verify_rib(tgen, "ipv4", dut, input_dict, next_hop=next_hop) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/example-topojson-test/test_topo_json_single_link_loopback/test_example_topojson.py b/tests/topotests/example-topojson-test/test_topo_json_single_link_loopback/test_example_topojson.py index cd069aaec5..06fa2f4626 100755 --- a/tests/topotests/example-topojson-test/test_topo_json_single_link_loopback/test_example_topojson.py +++ b/tests/topotests/example-topojson-test/test_topo_json_single_link_loopback/test_example_topojson.py @@ -33,32 +33,32 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) -sys.path.append(os.path.join(CWD, '../../')) +sys.path.append(os.path.join(CWD, "../")) +sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib.topogen import Topogen, get_topogen +from lib.topogen import Topogen, get_topogen # Required to instantiate the topology builder class. from mininet.topo import Topo # Import topoJson from lib, to create topology and initial configuration from lib.common_config import ( - start_topology, write_test_header, - write_test_footer, verify_rib + start_topology, + write_test_header, + write_test_footer, + verify_rib, ) from lib.topolog import logger -from lib.bgp import ( - verify_bgp_convergence -) +from lib.bgp import verify_bgp_convergence from lib.topojson import build_topo_from_json, build_config_from_json # Reading the data from JSON File for topology and configuration creation jsonFile = "{}/example_topojson.json".format(CWD) try: - with open(jsonFile, 'r') as topoJson: + with open(jsonFile, "r") as topoJson: topo = json.load(topoJson) except IOError: assert False, "Could not read file {}".format(jsonFile) @@ -100,7 +100,7 @@ def setup_module(mod): testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) - logger.info("="*40) + logger.info("=" * 40) logger.info("Running setup_module to create topology") @@ -157,8 +157,9 @@ def test_bgp_convergence(request): # Api call verify whether BGP is converged bgp_convergence = verify_bgp_convergence(tgen, topo) - assert bgp_convergence is True, "test_bgp_convergence failed.. \n"\ - " Error: {}".format(bgp_convergence) + assert ( + bgp_convergence is True + ), "test_bgp_convergence failed.. \n" " Error: {}".format(bgp_convergence) logger.info("BGP is converged successfully \n") write_test_footer(tc_name) @@ -169,7 +170,7 @@ def test_static_routes(request): tgen = get_topogen() if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name @@ -177,8 +178,8 @@ def test_static_routes(request): # Static routes are created as part of initial configuration, # verifying RIB - dut = 'r3' - next_hop = ['10.0.0.1', '10.0.0.5'] + dut = "r3" + next_hop = ["10.0.0.1", "10.0.0.5"] input_dict = { "r1": { "static_routes": [ @@ -186,20 +187,19 @@ def test_static_routes(request): "network": "100.0.20.1/32", "no_of_ip": 9, "admin_distance": 100, - "next_hop": "10.0.0.1" + "next_hop": "10.0.0.1", } ] } } # Uncomment below to debug # tgen.mininet_cli() - result = verify_rib(tgen, 'ipv4', dut, input_dict, next_hop=next_hop) - assert result is True, "Testcase {} :Failed \n Error: {}". \ - format(tc_name, result) + result = verify_rib(tgen, "ipv4", dut, input_dict, next_hop=next_hop) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name) -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/isis-topo1/test_isis_topo1.py b/tests/topotests/isis-topo1/test_isis_topo1.py index 941f917c6b..6b1d9a8964 100644 --- a/tests/topotests/isis-topo1/test_isis_topo1.py +++ b/tests/topotests/isis-topo1/test_isis_topo1.py @@ -36,7 +36,7 @@ import pytest import time CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -48,6 +48,7 @@ from mininet.topo import Topo class ISISTopo1(Topo): "Simple two layer ISIS topology" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) @@ -61,27 +62,27 @@ class ISISTopo1(Topo): # \ / # r5 for routern in range(1, 6): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) # r1 <- sw1 -> r3 - sw = tgen.add_switch('sw1') - sw.add_link(tgen.gears['r1']) - sw.add_link(tgen.gears['r3']) + sw = tgen.add_switch("sw1") + sw.add_link(tgen.gears["r1"]) + sw.add_link(tgen.gears["r3"]) # r2 <- sw2 -> r4 - sw = tgen.add_switch('sw2') - sw.add_link(tgen.gears['r2']) - sw.add_link(tgen.gears['r4']) + sw = tgen.add_switch("sw2") + sw.add_link(tgen.gears["r2"]) + sw.add_link(tgen.gears["r4"]) # r3 <- sw3 -> r5 - sw = tgen.add_switch('sw3') - sw.add_link(tgen.gears['r3']) - sw.add_link(tgen.gears['r5']) + sw = tgen.add_switch("sw3") + sw.add_link(tgen.gears["r3"]) + sw.add_link(tgen.gears["r5"]) # r4 <- sw4 -> r5 - sw = tgen.add_switch('sw4') - sw.add_link(tgen.gears['r4']) - sw.add_link(tgen.gears['r5']) + sw = tgen.add_switch("sw4") + sw.add_link(tgen.gears["r4"]) + sw.add_link(tgen.gears["r5"]) def setup_module(mod): @@ -92,12 +93,10 @@ def setup_module(mod): # For all registered routers, load the zebra configuration file for rname, router in tgen.routers().iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_ISIS, - os.path.join(CWD, '{}/isisd.conf'.format(rname)) + TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname)) ) # After loading the configurations, this function loads configured daemons. @@ -105,12 +104,12 @@ def setup_module(mod): has_version_20 = False for router in tgen.routers().values(): - if router.has_version('<', '3'): + if router.has_version("<", "3"): has_version_20 = True if has_version_20: - logger.info('Skipping ISIS tests for FRR 2.0') - tgen.set_error('ISIS has convergence problems with IPv6') + logger.info("Skipping ISIS tests for FRR 2.0") + tgen.set_error("ISIS has convergence problems with IPv6") def teardown_module(mod): @@ -136,7 +135,7 @@ def test_isis_convergence(): # ) for rname, router in tgen.routers().iteritems(): - filename = '{0}/{1}/{1}_topology.json'.format(CWD, rname) + filename = "{0}/{1}/{1}_topology.json".format(CWD, rname) expected = json.loads(open(filename).read()) def compare_isis_topology(router, expected): @@ -145,9 +144,8 @@ def test_isis_convergence(): return topotest.json_cmp(actual, expected) test_func = functools.partial(compare_isis_topology, router, expected) - (result, diff) = topotest.run_and_expect(test_func, None, - wait=0.5, count=120) - assert result, 'ISIS did not converge on {}:\n{}'.format(rname, diff) + (result, diff) = topotest.run_and_expect(test_func, None, wait=0.5, count=120) + assert result, "ISIS did not converge on {}:\n{}".format(rname, diff) def test_isis_route_installation(): @@ -157,24 +155,24 @@ def test_isis_route_installation(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('Checking routers for installed ISIS routes') + logger.info("Checking routers for installed ISIS routes") # Check for routes in 'show ip route json' for rname, router in tgen.routers().iteritems(): - filename = '{0}/{1}/{1}_route.json'.format(CWD, rname) - expected = json.loads(open(filename, 'r').read()) - actual = router.vtysh_cmd('show ip route json', isjson=True) + filename = "{0}/{1}/{1}_route.json".format(CWD, rname) + expected = json.loads(open(filename, "r").read()) + actual = router.vtysh_cmd("show ip route json", isjson=True) # Older FRR versions don't list interfaces in some ISIS routes - if router.has_version('<', '3.1'): + if router.has_version("<", "3.1"): for network, routes in expected.iteritems(): for route in routes: - if route['protocol'] != 'isis': + if route["protocol"] != "isis": continue - for nexthop in route['nexthops']: - nexthop.pop('interfaceIndex', None) - nexthop.pop('interfaceName', None) + for nexthop in route["nexthops"]: + nexthop.pop("interfaceIndex", None) + nexthop.pop("interfaceName", None) assertmsg = "Router '{}' routes mismatch".format(rname) assert topotest.json_cmp(actual, expected) is None, assertmsg @@ -187,19 +185,19 @@ def test_isis_linux_route_installation(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('Checking routers for installed ISIS routes in OS') + logger.info("Checking routers for installed ISIS routes in OS") # Check for routes in `ip route` for rname, router in tgen.routers().iteritems(): - filename = '{0}/{1}/{1}_route_linux.json'.format(CWD, rname) - expected = json.loads(open(filename, 'r').read()) + filename = "{0}/{1}/{1}_route_linux.json".format(CWD, rname) + expected = json.loads(open(filename, "r").read()) actual = topotest.ip4_route(router) # Older FRR versions install routes using different proto - if router.has_version('<', '3.1'): + if router.has_version("<", "3.1"): for network, netoptions in expected.iteritems(): - if 'proto' in netoptions and netoptions['proto'] == '187': - netoptions['proto'] = 'zebra' + if "proto" in netoptions and netoptions["proto"] == "187": + netoptions["proto"] = "zebra" assertmsg = "Router '{}' OS routes mismatch".format(rname) assert topotest.json_cmp(actual, expected) is None, assertmsg @@ -212,27 +210,27 @@ def test_isis_route6_installation(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('Checking routers for installed ISIS IPv6 routes') + logger.info("Checking routers for installed ISIS IPv6 routes") # Check for routes in 'show ip route json' for rname, router in tgen.routers().iteritems(): - filename = '{0}/{1}/{1}_route6.json'.format(CWD, rname) - expected = json.loads(open(filename, 'r').read()) - actual = router.vtysh_cmd('show ipv6 route json', isjson=True) + filename = "{0}/{1}/{1}_route6.json".format(CWD, rname) + expected = json.loads(open(filename, "r").read()) + actual = router.vtysh_cmd("show ipv6 route json", isjson=True) # Older FRR versions don't list interfaces in some ISIS routes - if router.has_version('<', '3.1'): + if router.has_version("<", "3.1"): for network, routes in expected.iteritems(): for route in routes: # Older versions display different metrics for IPv6 routes - route.pop('metric', None) + route.pop("metric", None) - if route['protocol'] != 'isis': + if route["protocol"] != "isis": continue - for nexthop in route['nexthops']: - nexthop.pop('interfaceIndex', None) - nexthop.pop('interfaceName', None) + for nexthop in route["nexthops"]: + nexthop.pop("interfaceIndex", None) + nexthop.pop("interfaceName", None) assertmsg = "Router '{}' routes mismatch".format(rname) assert topotest.json_cmp(actual, expected) is None, assertmsg @@ -245,19 +243,19 @@ def test_isis_linux_route6_installation(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('Checking routers for installed ISIS IPv6 routes in OS') + logger.info("Checking routers for installed ISIS IPv6 routes in OS") # Check for routes in `ip route` for rname, router in tgen.routers().iteritems(): - filename = '{0}/{1}/{1}_route6_linux.json'.format(CWD, rname) - expected = json.loads(open(filename, 'r').read()) + filename = "{0}/{1}/{1}_route6_linux.json".format(CWD, rname) + expected = json.loads(open(filename, "r").read()) actual = topotest.ip6_route(router) # Older FRR versions install routes using different proto - if router.has_version('<', '3.1'): + if router.has_version("<", "3.1"): for network, netoptions in expected.iteritems(): - if 'proto' in netoptions and netoptions['proto'] == '187': - netoptions['proto'] = 'zebra' + if "proto" in netoptions and netoptions["proto"] == "187": + netoptions["proto"] = "zebra" assertmsg = "Router '{}' OS routes mismatch".format(rname) assert topotest.json_cmp(actual, expected) is None, assertmsg @@ -267,12 +265,12 @@ def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) @@ -296,8 +294,11 @@ def dict_merge(dct, merge_dct): https://gist.github.com/angstwad/bf22d1822c38a92ec0a9 """ for k, v in merge_dct.iteritems(): - if (k in dct and isinstance(dct[k], dict) - and isinstance(merge_dct[k], collections.Mapping)): + if ( + k in dct + and isinstance(dct[k], dict) + and isinstance(merge_dct[k], collections.Mapping) + ): dict_merge(dct[k], merge_dct[k]) else: dct[k] = merge_dct[k] @@ -316,59 +317,59 @@ def parse_topology(lines, level): if area_match: area = area_match.group(1) if area not in areas: - areas[area] = { - level: { - 'ipv4': [], - 'ipv6': [] - } - } + areas[area] = {level: {"ipv4": [], "ipv6": []}} ipv = None continue elif area is None: continue if re.match(r"IS\-IS paths to level-. routers that speak IPv6", line): - ipv = 'ipv6' + ipv = "ipv6" continue if re.match(r"IS\-IS paths to level-. routers that speak IP", line): - ipv = 'ipv4' + ipv = "ipv4" continue - item_match = re.match( - r"([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+)", line) + item_match = re.match(r"([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+)", line) if item_match is not None: # Skip header - if (item_match.group(1) == 'Vertex' and - item_match.group(2) == 'Type' and - item_match.group(3) == 'Metric' and - item_match.group(4) == 'Next-Hop' and - item_match.group(5) == 'Interface' and - item_match.group(6) == 'Parent'): + if ( + item_match.group(1) == "Vertex" + and item_match.group(2) == "Type" + and item_match.group(3) == "Metric" + and item_match.group(4) == "Next-Hop" + and item_match.group(5) == "Interface" + and item_match.group(6) == "Parent" + ): continue - areas[area][level][ipv].append({ - 'vertex': item_match.group(1), - 'type': item_match.group(2), - 'metric': item_match.group(3), - 'next-hop': item_match.group(4), - 'interface': item_match.group(5), - 'parent': item_match.group(6), - }) + areas[area][level][ipv].append( + { + "vertex": item_match.group(1), + "type": item_match.group(2), + "metric": item_match.group(3), + "next-hop": item_match.group(4), + "interface": item_match.group(5), + "parent": item_match.group(6), + } + ) continue item_match = re.match(r"([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+)", line) if item_match is not None: - areas[area][level][ipv].append({ - 'vertex': item_match.group(1), - 'type': item_match.group(2), - 'metric': item_match.group(3), - 'parent': item_match.group(4), - }) + areas[area][level][ipv].append( + { + "vertex": item_match.group(1), + "type": item_match.group(2), + "metric": item_match.group(3), + "parent": item_match.group(4), + } + ) continue item_match = re.match(r"([^ ]+)", line) if item_match is not None: - areas[area][level][ipv].append({'vertex': item_match.group(1)}) + areas[area][level][ipv].append({"vertex": item_match.group(1)}) continue return areas @@ -410,14 +411,14 @@ def show_isis_topology(router): } """ l1out = topotest.normalize_text( - router.vtysh_cmd('show isis topology level-1') + router.vtysh_cmd("show isis topology level-1") ).splitlines() l2out = topotest.normalize_text( - router.vtysh_cmd('show isis topology level-2') + router.vtysh_cmd("show isis topology level-2") ).splitlines() - l1 = parse_topology(l1out, 'level-1') - l2 = parse_topology(l2out, 'level-2') + l1 = parse_topology(l1out, "level-1") + l2 = parse_topology(l2out, "level-2") dict_merge(l1, l2) return l1 diff --git a/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.py b/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.py index 9695c0d345..450d35e16c 100755 --- a/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.py +++ b/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.py @@ -67,7 +67,7 @@ from functools import partial # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -78,8 +78,10 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from mininet.topo import Topo + class TemplateTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) @@ -87,24 +89,25 @@ class TemplateTopo(Topo): # # Define FRR Routers # - for router in ['r1', 'r2', 'r3', 'r4']: + for router in ["r1", "r2", "r3", "r4"]: tgen.add_router(router) # # Define connections # - switch = tgen.add_switch('s0') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s0") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) - switch.add_link(tgen.gears['r4']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) def setup_module(mod): "Sets up the pytest environment" @@ -116,22 +119,20 @@ def setup_module(mod): # For all registered routers, load the zebra configuration file for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) # Don't start ospfd and ldpd in the CE nodes - if router.name[0] == 'r': + if router.name[0] == "r": router.load_config( - TopoRouter.RD_OSPF, - os.path.join(CWD, '{}/ospfd.conf'.format(rname)) + TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname)) ) router.load_config( - TopoRouter.RD_LDP, - os.path.join(CWD, '{}/ldpd.conf'.format(rname)) + TopoRouter.RD_LDP, os.path.join(CWD, "{}/ldpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): "Teardown the pytest environment" tgen = get_topogen() @@ -146,17 +147,17 @@ def router_compare_json_output(rname, command, reference): logger.info('Comparing router "%s" "%s" output', rname, command) tgen = get_topogen() - filename = '{}/{}/{}'.format(CWD, rname, reference) + filename = "{}/{}/{}".format(CWD, rname, reference) expected = json.loads(open(filename).read()) # Run test function until we get an result. Wait at most 80 seconds. - test_func = partial(topotest.router_json_cmp, - tgen.gears[rname], command, expected) + test_func = partial(topotest.router_json_cmp, tgen.gears[rname], command, expected) _, diff = topotest.run_and_expect(test_func, None, count=160, wait=0.5) assertmsg = '"{}" JSON output mismatches the expected result'.format(rname) assert diff is None, assertmsg + def test_ospf_convergence(): logger.info("Test: check OSPF adjacencies") @@ -166,8 +167,11 @@ def test_ospf_convergence(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3', 'r4']: - router_compare_json_output(rname, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json") + for rname in ["r1", "r2", "r3", "r4"]: + router_compare_json_output( + rname, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json" + ) + def test_rib(): logger.info("Test: verify RIB") @@ -177,9 +181,10 @@ def test_rib(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3', 'r4']: + for rname in ["r1", "r2", "r3", "r4"]: router_compare_json_output(rname, "show ip route json", "show_ip_route.ref") + def test_ldp_adjacencies(): logger.info("Test: verify LDP adjacencies") tgen = get_topogen() @@ -188,8 +193,11 @@ def test_ldp_adjacencies(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3', 'r4']: - router_compare_json_output(rname, "show mpls ldp discovery json", "show_ldp_discovery.ref") + for rname in ["r1", "r2", "r3", "r4"]: + router_compare_json_output( + rname, "show mpls ldp discovery json", "show_ldp_discovery.ref" + ) + def test_ldp_neighbors(): logger.info("Test: verify LDP neighbors") @@ -199,8 +207,11 @@ def test_ldp_neighbors(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3', 'r4']: - router_compare_json_output(rname, "show mpls ldp neighbor json", "show_ldp_neighbor.ref") + for rname in ["r1", "r2", "r3", "r4"]: + router_compare_json_output( + rname, "show mpls ldp neighbor json", "show_ldp_neighbor.ref" + ) + def test_ldp_bindings(): logger.info("Test: verify LDP bindings") @@ -210,8 +221,11 @@ def test_ldp_bindings(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3', 'r4']: - router_compare_json_output(rname, "show mpls ldp binding json", "show_ldp_binding.ref") + for rname in ["r1", "r2", "r3", "r4"]: + router_compare_json_output( + rname, "show mpls ldp binding json", "show_ldp_binding.ref" + ) + def test_ldp_bindings_all_routes(): logger.info("Test: verify LDP bindings after host filter removed") @@ -222,22 +236,26 @@ def test_ldp_bindings_all_routes(): pytest.skip(tgen.errors) # remove ACL that blocks advertising everything but host routes */ - cmd = 'vtysh -c \"configure terminal\" -c \"mpls ldp\" -c \"address-family ipv4\" -c \"no label local allocate host-routes\"' - tgen.net['r1'].cmd(cmd) + cmd = 'vtysh -c "configure terminal" -c "mpls ldp" -c "address-family ipv4" -c "no label local allocate host-routes"' + tgen.net["r1"].cmd(cmd) sleep(2) - for rname in ['r1', 'r2', 'r3', 'r4']: - router_compare_json_output(rname, "show mpls ldp binding json", "show_ldp_all_binding.ref") + for rname in ["r1", "r2", "r3", "r4"]: + router_compare_json_output( + rname, "show mpls ldp binding json", "show_ldp_all_binding.ref" + ) + # Memory leak test template def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.py b/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.py index eda1b37e52..ac99eb1a26 100755 --- a/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.py +++ b/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.py @@ -67,7 +67,7 @@ from functools import partial # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -78,8 +78,10 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from mininet.topo import Topo + class TemplateTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) @@ -87,24 +89,25 @@ class TemplateTopo(Topo): # # Define FRR Routers # - for router in ['r1', 'r2', 'r3', 'r4']: + for router in ["r1", "r2", "r3", "r4"]: tgen.add_router(router) # # Define connections # - switch = tgen.add_switch('s0') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s0") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) - switch.add_link(tgen.gears['r4']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) def setup_module(mod): "Sets up the pytest environment" @@ -116,22 +119,20 @@ def setup_module(mod): # For all registered routers, load the zebra configuration file for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) # Don't start ospfd and ldpd in the CE nodes - if router.name[0] == 'r': + if router.name[0] == "r": router.load_config( - TopoRouter.RD_OSPF, - os.path.join(CWD, '{}/ospfd.conf'.format(rname)) + TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname)) ) router.load_config( - TopoRouter.RD_LDP, - os.path.join(CWD, '{}/ldpd.conf'.format(rname)) + TopoRouter.RD_LDP, os.path.join(CWD, "{}/ldpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): "Teardown the pytest environment" tgen = get_topogen() @@ -146,17 +147,17 @@ def router_compare_json_output(rname, command, reference): logger.info('Comparing router "%s" "%s" output', rname, command) tgen = get_topogen() - filename = '{}/{}/{}'.format(CWD, rname, reference) + filename = "{}/{}/{}".format(CWD, rname, reference) expected = json.loads(open(filename).read()) # Run test function until we get an result. Wait at most 80 seconds. - test_func = partial(topotest.router_json_cmp, - tgen.gears[rname], command, expected) + test_func = partial(topotest.router_json_cmp, tgen.gears[rname], command, expected) _, diff = topotest.run_and_expect(test_func, None, count=160, wait=0.5) assertmsg = '"{}" JSON output mismatches the expected result'.format(rname) assert diff is None, assertmsg + def test_ospf_convergence(): logger.info("Test: check OSPF adjacencies") @@ -166,8 +167,11 @@ def test_ospf_convergence(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3', 'r4']: - router_compare_json_output(rname, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json") + for rname in ["r1", "r2", "r3", "r4"]: + router_compare_json_output( + rname, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json" + ) + def test_rib(): logger.info("Test: verify RIB") @@ -177,9 +181,10 @@ def test_rib(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3', 'r4']: + for rname in ["r1", "r2", "r3", "r4"]: router_compare_json_output(rname, "show ip route json", "show_ip_route.ref") + def test_ldp_adjacencies(): logger.info("Test: verify LDP adjacencies") tgen = get_topogen() @@ -188,8 +193,11 @@ def test_ldp_adjacencies(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3', 'r4']: - router_compare_json_output(rname, "show mpls ldp discovery json", "show_ldp_discovery.ref") + for rname in ["r1", "r2", "r3", "r4"]: + router_compare_json_output( + rname, "show mpls ldp discovery json", "show_ldp_discovery.ref" + ) + def test_ldp_neighbors(): logger.info("Test: verify LDP neighbors") @@ -199,8 +207,11 @@ def test_ldp_neighbors(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3', 'r4']: - router_compare_json_output(rname, "show mpls ldp neighbor json", "show_ldp_neighbor.ref") + for rname in ["r1", "r2", "r3", "r4"]: + router_compare_json_output( + rname, "show mpls ldp neighbor json", "show_ldp_neighbor.ref" + ) + def test_ldp_bindings(): logger.info("Test: verify LDP bindings") @@ -210,18 +221,22 @@ def test_ldp_bindings(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3', 'r4']: - router_compare_json_output(rname, "show mpls ldp binding json", "show_ldp_binding.ref") + for rname in ["r1", "r2", "r3", "r4"]: + router_compare_json_output( + rname, "show mpls ldp binding json", "show_ldp_binding.ref" + ) + # Memory leak test template def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/ldp-topo1/test_ldp_topo1.py b/tests/topotests/ldp-topo1/test_ldp_topo1.py index c0d11fd5e0..cef4d6587e 100755 --- a/tests/topotests/ldp-topo1/test_ldp_topo1.py +++ b/tests/topotests/ldp-topo1/test_ldp_topo1.py @@ -57,7 +57,7 @@ r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0 | r3 | | r4 | | 3.3.3.3 | | 4.4.4.4 | +-----------+ +---------+ -""" +""" import os import re @@ -83,6 +83,7 @@ fatal_error = "" ## ##################################################### + class NetworkTopo(Topo): "LDP Test Topology 1" @@ -91,23 +92,65 @@ class NetworkTopo(Topo): # Setup Routers router = {} for i in range(1, 5): - router[i] = topotest.addRouter(self, 'r%s' % i) + router[i] = topotest.addRouter(self, "r%s" % i) # Setup Switches, add Interfaces and Connections switch = {} # First switch - switch[0] = self.addSwitch('sw0', cls=topotest.LegacySwitch) - self.addLink(switch[0], router[1], intfName2='r1-eth0', addr1='80:AA:00:00:00:00', addr2='00:11:00:01:00:00') - self.addLink(switch[0], router[2], intfName2='r2-eth0', addr1='80:AA:00:00:00:01', addr2='00:11:00:02:00:00') + switch[0] = self.addSwitch("sw0", cls=topotest.LegacySwitch) + self.addLink( + switch[0], + router[1], + intfName2="r1-eth0", + addr1="80:AA:00:00:00:00", + addr2="00:11:00:01:00:00", + ) + self.addLink( + switch[0], + router[2], + intfName2="r2-eth0", + addr1="80:AA:00:00:00:01", + addr2="00:11:00:02:00:00", + ) # Second switch - switch[1] = self.addSwitch('sw1', cls=topotest.LegacySwitch) - self.addLink(switch[1], router[2], intfName2='r2-eth1', addr1='80:AA:00:01:00:00', addr2='00:11:00:02:00:01') - self.addLink(switch[1], router[3], intfName2='r3-eth0', addr1='80:AA:00:01:00:01', addr2='00:11:00:03:00:00') - self.addLink(switch[1], router[4], intfName2='r4-eth0', addr1='80:AA:00:01:00:02', addr2='00:11:00:04:00:00') + switch[1] = self.addSwitch("sw1", cls=topotest.LegacySwitch) + self.addLink( + switch[1], + router[2], + intfName2="r2-eth1", + addr1="80:AA:00:01:00:00", + addr2="00:11:00:02:00:01", + ) + self.addLink( + switch[1], + router[3], + intfName2="r3-eth0", + addr1="80:AA:00:01:00:01", + addr2="00:11:00:03:00:00", + ) + self.addLink( + switch[1], + router[4], + intfName2="r4-eth0", + addr1="80:AA:00:01:00:02", + addr2="00:11:00:04:00:00", + ) # Third switch - switch[2] = self.addSwitch('sw2', cls=topotest.LegacySwitch) - self.addLink(switch[2], router[2], intfName2='r2-eth2', addr1='80:AA:00:02:00:00', addr2='00:11:00:02:00:02') - self.addLink(switch[2], router[3], intfName2='r3-eth1', addr1='80:AA:00:02:00:01', addr2='00:11:00:03:00:01') + switch[2] = self.addSwitch("sw2", cls=topotest.LegacySwitch) + self.addLink( + switch[2], + router[2], + intfName2="r2-eth2", + addr1="80:AA:00:02:00:00", + addr2="00:11:00:02:00:02", + ) + self.addLink( + switch[2], + router[3], + intfName2="r3-eth1", + addr1="80:AA:00:02:00:01", + addr2="00:11:00:03:00:01", + ) ##################################################### @@ -116,6 +159,7 @@ class NetworkTopo(Topo): ## ##################################################### + def setup_module(module): global topo, net global fatal_error @@ -124,7 +168,7 @@ def setup_module(module): print("******************************************\n") print("Cleanup old Mininet runs") - os.system('sudo mn -c > /dev/null 2>&1') + os.system("sudo mn -c > /dev/null 2>&1") thisDir = os.path.dirname(os.path.realpath(__file__)) topo = NetworkTopo() @@ -134,10 +178,10 @@ def setup_module(module): # Starting Routers for i in range(1, 5): - net['r%s' % i].loadConf('zebra', '%s/r%s/zebra.conf' % (thisDir, i)) - net['r%s' % i].loadConf('ospfd', '%s/r%s/ospfd.conf' % (thisDir, i)) - net['r%s' % i].loadConf('ldpd', '%s/r%s/ldpd.conf' % (thisDir, i)) - fatal_error = net['r%s' % i].startRouter() + net["r%s" % i].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir, i)) + net["r%s" % i].loadConf("ospfd", "%s/r%s/ospfd.conf" % (thisDir, i)) + net["r%s" % i].loadConf("ldpd", "%s/r%s/ldpd.conf" % (thisDir, i)) + fatal_error = net["r%s" % i].startRouter() if fatal_error != "": break @@ -145,6 +189,7 @@ def setup_module(module): # For debugging after starting FRR/Quagga daemons, uncomment the next line # CLI(net) + def teardown_module(module): global net @@ -160,7 +205,7 @@ def test_router_running(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) print("\n\n** Check if FRR/Quagga is running on each Router node") @@ -169,18 +214,19 @@ def test_router_running(): # Starting Routers for i in range(1, 5): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line # CLI(net) + def test_mpls_interfaces(): global fatal_error global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -190,40 +236,51 @@ def test_mpls_interfaces(): print("******************************************\n") failures = 0 for i in range(1, 5): - refTableFile = '%s/r%s/show_mpls_ldp_interface.ref' + refTableFile = "%s/r%s/show_mpls_ldp_interface.ref" 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) + 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() + 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) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual MPLS LDP interface status", - title2="expected 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)) + 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: + 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) + 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, 5): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -235,7 +292,7 @@ def test_mpls_ldp_neighbor_establish(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) # Wait for MPLS LDP neighbors to establish. @@ -247,17 +304,23 @@ def test_mpls_ldp_neighbor_establish(): sys.stdout.flush() # Look for any node not yet converged for i in range(1, 5): - established = net['r%s' % i].cmd('vtysh -c "show mpls ldp neighbor" 2> /dev/null').rstrip() + established = ( + net["r%s" % i] + .cmd('vtysh -c "show mpls ldp neighbor" 2> /dev/null') + .rstrip() + ) # On current version, we need to make sure they all turn to OPERATIONAL on all lines # - lines = ('\n'.join(established.splitlines()) + '\n').splitlines(1) + lines = ("\n".join(established.splitlines()) + "\n").splitlines(1) # Check all lines to be either table header (starting with ^AF or show OPERATIONAL) - header = r'^AF.*' - operational = r'^ip.*OPERATIONAL.*' + header = r"^AF.*" + operational = r"^ip.*OPERATIONAL.*" found_operational = 0 for j in range(1, len(lines)): - if (not re.search(header, lines[j])) and (not re.search(operational, lines[j])): + if (not re.search(header, lines[j])) and ( + not re.search(operational, lines[j]) + ): established = "" # Empty string shows NOT established if re.search(operational, lines[j]): found_operational += 1 @@ -265,14 +328,14 @@ def test_mpls_ldp_neighbor_establish(): # Need at least one operational neighbor established = "" # Empty string shows NOT established if not established: - print('Waiting for r%s' %i) + print("Waiting for r%s" % i) sys.stdout.flush() break if not established: sleep(5) timeout -= 5 else: - print('Done') + print("Done") break else: # Bail out with error if a router fails to converge @@ -285,10 +348,10 @@ def test_mpls_ldp_neighbor_establish(): # Only wait if we actually went through a convergence print("\nwaiting 15s for LDP sessions to establish") sleep(15) - + # Make sure that all daemons are running for i in range(1, 5): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error @@ -297,7 +360,7 @@ def test_mpls_ldp_discovery(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -307,39 +370,54 @@ def test_mpls_ldp_discovery(): print("******************************************\n") failures = 0 for i in range(1, 5): - refTableFile = '%s/r%s/show_mpls_ldp_discovery.ref' % (thisDir, i) + 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() + 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) + 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() + 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) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual MPLS LDP discovery output", - title2="expected 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)) + 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) + 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() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -351,7 +429,7 @@ def test_mpls_ldp_neighbor(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -361,44 +439,59 @@ def test_mpls_ldp_neighbor(): print("******************************************\n") failures = 0 for i in range(1, 5): - refTableFile = '%s/r%s/show_mpls_ldp_neighbor.ref' % (thisDir, i) + refTableFile = "%s/r%s/show_mpls_ldp_neighbor.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) + 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() + actual = ( + net["r%s" % i] + .cmd('vtysh -c "show mpls ldp neighbor" 2> /dev/null') + .rstrip() + ) # Mask out changing parts in output # 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) + 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) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual MPLS LDP neighbor output", - title2="expected 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)) + 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) + 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() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line - #CLI(net) + # CLI(net) def test_mpls_ldp_binding(): @@ -410,7 +503,7 @@ def test_mpls_ldp_binding(): # pytest.skip("Skipping test_mpls_ldp_binding") # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -420,58 +513,77 @@ def test_mpls_ldp_binding(): print("******************************************\n") failures = 0 for i in range(1, 5): - refTableFile = '%s/r%s/show_mpls_ldp_binding.ref' % (thisDir, i) + 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) + 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() + 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) + 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) + 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+' + 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] + 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, + diff = topotest.get_textdiff( + actual, + expected, title1="actual MPLS LDP binding output", - title2="expected 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)) + 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) + 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() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line - #CLI(net) + # CLI(net) def test_zebra_ipv4_routingTable(): @@ -479,7 +591,7 @@ def test_zebra_ipv4_routingTable(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -489,13 +601,17 @@ def test_zebra_ipv4_routingTable(): print("******************************************\n") failures = 0 for i in range(1, 5): - refTableFile = '%s/r%s/show_ipv4_route.ref' % (thisDir, i) + 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() + 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) @@ -505,32 +621,40 @@ def test_zebra_ipv4_routingTable(): # 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)): + 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) + expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) # Fix newlines (make them all the same) - actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual IPv4 zebra routing table", - title2="expected 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)) + 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) + 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() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -542,7 +666,7 @@ def test_mpls_table(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -553,45 +677,54 @@ def test_mpls_table(): failures = 0 for i in range(1, 5): - refTableFile = '%s/r%s/show_mpls_table.ref' % (thisDir, i) + 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) + 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') + 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) + 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) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Sort lines which start with " XX LDP" - pattern = r'^\s+[0-9X]+\s+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] + 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, + diff = topotest.get_textdiff( + actual, + expected, title1="actual MPLS table output", - title2="expected 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)) + sys.stderr.write( + "r%s failed MPLS table output Check:\n%s\n" % (i, diff) + ) failures += 1 else: print("r%s ok" % i) @@ -600,7 +733,7 @@ def test_mpls_table(): # Make sure that all daemons are running for i in range(1, 5): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -611,8 +744,8 @@ def test_linux_mpls_routes(): global fatal_error global net - # Skip if previous fatal error condition is raised - if (fatal_error != ""): + # Skip if previous fatal error condition is raised + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -622,15 +755,17 @@ def test_linux_mpls_routes(): print("******************************************\n") failures = 0 for i in range(1, 5): - refTableFile = '%s/r%s/ip_mpls_route.ref' % (thisDir, i) + 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) + 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() + 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) @@ -641,39 +776,48 @@ def test_linux_mpls_routes(): # 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()) + 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 = "\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) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual Linux Kernel MPLS route", - title2="expected 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)) + 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) + 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() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -685,12 +829,14 @@ def test_shutdown_check_stderr(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) - if os.environ.get('TOPOTESTS_CHECK_STDERR') is None: - print("SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n") - pytest.skip('Skipping test for Stderr output') + if os.environ.get("TOPOTESTS_CHECK_STDERR") is None: + print( + "SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n" + ) + pytest.skip("Skipping test for Stderr output") thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -698,14 +844,14 @@ def test_shutdown_check_stderr(): print("******************************************\n") for i in range(1, 5): - net['r%s' % i].stopRouter() - log = net['r%s' % i].getStdErr('ldpd') + net["r%s" % i].stopRouter() + log = net["r%s" % i].getStdErr("ldpd") if log: print("\nRouter r%s LDPd StdErr Log:\n%s" % (i, log)) - log = net['r%s' % i].getStdErr('ospfd') + log = net["r%s" % i].getStdErr("ospfd") if log: print("\nRouter r%s OSPFd StdErr Log:\n%s" % (i, log)) - log = net['r%s' % i].getStdErr('zebra') + log = net["r%s" % i].getStdErr("zebra") if log: print("\nRouter r%s Zebra StdErr Log:\n%s" % (i, log)) @@ -715,23 +861,27 @@ def test_shutdown_check_memleak(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) - if os.environ.get('TOPOTESTS_CHECK_MEMLEAK') is None: - print("SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)\n") - pytest.skip('Skipping test for memory leaks') - + if os.environ.get("TOPOTESTS_CHECK_MEMLEAK") is None: + print( + "SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)\n" + ) + pytest.skip("Skipping test for memory leaks") + thisDir = os.path.dirname(os.path.realpath(__file__)) for i in range(1, 5): - net['r%s' % i].stopRouter() - net['r%s' % i].report_memory_leaks(os.environ.get('TOPOTESTS_CHECK_MEMLEAK'), os.path.basename(__file__)) + net["r%s" % i].stopRouter() + net["r%s" % i].report_memory_leaks( + os.environ.get("TOPOTESTS_CHECK_MEMLEAK"), os.path.basename(__file__) + ) -if __name__ == '__main__': +if __name__ == "__main__": - setLogLevel('info') + 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"]) diff --git a/tests/topotests/ldp-vpls-topo1/test_ldp_vpls_topo1.py b/tests/topotests/ldp-vpls-topo1/test_ldp_vpls_topo1.py index 0fae64402a..600d640a70 100755 --- a/tests/topotests/ldp-vpls-topo1/test_ldp_vpls_topo1.py +++ b/tests/topotests/ldp-vpls-topo1/test_ldp_vpls_topo1.py @@ -69,7 +69,7 @@ from functools import partial # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -80,8 +80,10 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from mininet.topo import Topo + class TemplateTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) @@ -89,35 +91,36 @@ class TemplateTopo(Topo): # # Define FRR Routers # - for router in ['ce1', 'ce2', 'ce3', 'r1', 'r2', 'r3']: + for router in ["ce1", "ce2", "ce3", "r1", "r2", "r3"]: tgen.add_router(router) # # Define connections # - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['ce1']) - switch.add_link(tgen.gears['r1']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["ce1"]) + switch.add_link(tgen.gears["r1"]) - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['ce2']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["ce2"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s3') - switch.add_link(tgen.gears['ce3']) - switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["ce3"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch('s4') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch('s5') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r3"]) + + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch('s6') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) def setup_module(mod): "Sets up the pytest environment" @@ -129,22 +132,20 @@ def setup_module(mod): # For all registered routers, load the zebra configuration file for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) # Don't start ospfd and ldpd in the CE nodes - if router.name[0] == 'r': + if router.name[0] == "r": router.load_config( - TopoRouter.RD_OSPF, - os.path.join(CWD, '{}/ospfd.conf'.format(rname)) + TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname)) ) router.load_config( - TopoRouter.RD_LDP, - os.path.join(CWD, '{}/ldpd.conf'.format(rname)) + TopoRouter.RD_LDP, os.path.join(CWD, "{}/ldpd.conf".format(rname)) ) tgen.start_router() + def teardown_module(mod): "Teardown the pytest environment" tgen = get_topogen() @@ -159,16 +160,16 @@ def router_compare_json_output(rname, command, reference): logger.info('Comparing router "%s" "%s" output', rname, command) tgen = get_topogen() - filename = '{}/{}/{}'.format(CWD, rname, reference) + filename = "{}/{}/{}".format(CWD, rname, reference) expected = json.loads(open(filename).read()) # Run test function until we get an result. Wait at most 80 seconds. - test_func = partial(topotest.router_json_cmp, - tgen.gears[rname], command, expected) + test_func = partial(topotest.router_json_cmp, tgen.gears[rname], command, expected) _, diff = topotest.run_and_expect(test_func, None, count=160, wait=0.5) assertmsg = '"{}" JSON output mismatches the expected result'.format(rname) assert diff is None, assertmsg + def test_ospf_convergence(): logger.info("Test: check OSPF adjacencies") tgen = get_topogen() @@ -177,8 +178,11 @@ def test_ospf_convergence(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3']: - router_compare_json_output(rname, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json") + for rname in ["r1", "r2", "r3"]: + router_compare_json_output( + rname, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json" + ) + def test_rib(): logger.info("Test: verify RIB") @@ -188,9 +192,10 @@ def test_rib(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3']: + for rname in ["r1", "r2", "r3"]: router_compare_json_output(rname, "show ip route json", "show_ip_route.ref") + def test_ldp_adjacencies(): logger.info("Test: verify LDP adjacencies") tgen = get_topogen() @@ -199,8 +204,11 @@ def test_ldp_adjacencies(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3']: - router_compare_json_output(rname, "show mpls ldp discovery json", "show_ldp_discovery.ref") + for rname in ["r1", "r2", "r3"]: + router_compare_json_output( + rname, "show mpls ldp discovery json", "show_ldp_discovery.ref" + ) + def test_ldp_neighbors(): logger.info("Test: verify LDP neighbors") @@ -210,8 +218,11 @@ def test_ldp_neighbors(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3']: - router_compare_json_output(rname, "show mpls ldp neighbor json", "show_ldp_neighbor.ref") + for rname in ["r1", "r2", "r3"]: + router_compare_json_output( + rname, "show mpls ldp neighbor json", "show_ldp_neighbor.ref" + ) + def test_ldp_bindings(): logger.info("Test: verify LDP bindings") @@ -221,8 +232,11 @@ def test_ldp_bindings(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3']: - router_compare_json_output(rname, "show mpls ldp binding json", "show_ldp_binding.ref") + for rname in ["r1", "r2", "r3"]: + router_compare_json_output( + rname, "show mpls ldp binding json", "show_ldp_binding.ref" + ) + def test_ldp_pwid_bindings(): logger.info("Test: verify LDP PW-ID bindings") @@ -232,8 +246,11 @@ def test_ldp_pwid_bindings(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3']: - router_compare_json_output(rname, "show l2vpn atom binding json", "show_l2vpn_binding.ref") + for rname in ["r1", "r2", "r3"]: + router_compare_json_output( + rname, "show l2vpn atom binding json", "show_l2vpn_binding.ref" + ) + def test_ldp_pseudowires(): logger.info("Test: verify LDP pseudowires") @@ -243,8 +260,11 @@ def test_ldp_pseudowires(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - for rname in ['r1', 'r2', 'r3']: - router_compare_json_output(rname, "show l2vpn atom vc json", "show_l2vpn_vc.ref") + for rname in ["r1", "r2", "r3"]: + router_compare_json_output( + rname, "show l2vpn atom vc json", "show_l2vpn_vc.ref" + ) + def test_ldp_pseudowires_after_link_down(): logger.info("Test: verify LDP pseudowires after r1-r2 link goes down") @@ -256,22 +276,26 @@ def test_ldp_pseudowires_after_link_down(): # Shut down r1-r2 link */ tgen = get_topogen() - tgen.gears['r1'].peer_link_enable('r1-eth1', False) + tgen.gears["r1"].peer_link_enable("r1-eth1", False) topotest.sleep(5, "Waiting for the network to reconverge") # check if the pseudowire is still up (using an alternate path for nexthop resolution) - for rname in ['r1', 'r2', 'r3']: - router_compare_json_output(rname, "show l2vpn atom vc json", "show_l2vpn_vc.ref") + for rname in ["r1", "r2", "r3"]: + router_compare_json_output( + rname, "show l2vpn atom vc json", "show_l2vpn_vc.ref" + ) + # Memory leak test template def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/lib/bgp.py b/tests/topotests/lib/bgp.py index 15f970ba75..d183fb9f60 100644 --- a/tests/topotests/lib/bgp.py +++ b/tests/topotests/lib/bgp.py @@ -27,13 +27,16 @@ from lib import topotest from lib.topolog import logger # Import common_config to use commomnly used APIs -from lib.common_config import (create_common_configuration, - InvalidCLIError, - load_config_to_router, - check_address_types, - generate_ips, - find_interface_with_greater_ip, - run_frr_cmd, retry) +from lib.common_config import ( + create_common_configuration, + InvalidCLIError, + load_config_to_router, + check_address_types, + generate_ips, + find_interface_with_greater_ip, + run_frr_cmd, + retry, +) BGP_CONVERGENCE_TIMEOUT = 10 @@ -126,24 +129,31 @@ def create_router_bgp(tgen, topo, input_dict=None, build=False): bgp_addr_data = bgp_data.setdefault("address_family", {}) if not bgp_addr_data: - logger.debug("Router %s: 'address_family' not present in " - "input_dict for BGP", router) + logger.debug( + "Router %s: 'address_family' not present in " "input_dict for BGP", + router, + ) else: ipv4_data = bgp_addr_data.setdefault("ipv4", {}) ipv6_data = bgp_addr_data.setdefault("ipv6", {}) - neigh_unicast = True if ipv4_data.setdefault("unicast", {}) \ - or ipv6_data.setdefault("unicast", {}) else False + neigh_unicast = ( + True + if ipv4_data.setdefault("unicast", {}) + or ipv6_data.setdefault("unicast", {}) + else False + ) if neigh_unicast: data_all_bgp = __create_bgp_unicast_neighbor( - tgen, topo, input_dict, router, - config_data=data_all_bgp) + tgen, topo, input_dict, router, config_data=data_all_bgp + ) try: - result = create_common_configuration(tgen, router, data_all_bgp, - "bgp", build) + result = create_common_configuration( + tgen, router, data_all_bgp, "bgp", build + ) except InvalidCLIError: # Traceback errormsg = traceback.format_exc() @@ -182,8 +192,9 @@ def __create_bgp_global(tgen, input_dict, router, build=False): config_data = [] if "local_as" not in bgp_data and build: - logger.error("Router %s: 'local_as' not present in input_dict" - "for BGP", router) + logger.error( + "Router %s: 'local_as' not present in input_dict" "for BGP", router + ) return False local_as = bgp_data.setdefault("local_as", "") @@ -199,14 +210,12 @@ def __create_bgp_global(tgen, input_dict, router, build=False): if del_router_id: config_data.append("no bgp router-id") if router_id: - config_data.append("bgp router-id {}".format( - router_id)) + config_data.append("bgp router-id {}".format(router_id)) return config_data -def __create_bgp_unicast_neighbor(tgen, topo, input_dict, router, - config_data=None): +def __create_bgp_unicast_neighbor(tgen, topo, input_dict, router, config_data=None): """ Helper API to create configuration for address-family unicast @@ -235,11 +244,8 @@ def __create_bgp_unicast_neighbor(tgen, topo, input_dict, router, addr_data = addr_dict["unicast"] if addr_data: - config_data.append("address-family {} unicast".format( - addr_type - )) - advertise_network = addr_data.setdefault("advertise_networks", - []) + config_data.append("address-family {} unicast".format(addr_type)) + advertise_network = addr_data.setdefault("advertise_networks", []) for advertise_network_dict in advertise_network: network = advertise_network_dict["network"] if type(network) is not list: @@ -250,12 +256,10 @@ def __create_bgp_unicast_neighbor(tgen, topo, input_dict, router, else: no_of_network = 1 - del_action = advertise_network_dict.setdefault("delete", - False) + del_action = advertise_network_dict.setdefault("delete", False) # Generating IPs for verification - prefix = str( - ipaddr.IPNetwork(unicode(network[0])).prefixlen) + prefix = str(ipaddr.IPNetwork(unicode(network[0])).prefixlen) network_list = generate_ips(network, no_of_network) for ip in network_list: ip = str(ipaddr.IPNetwork(unicode(ip)).network) @@ -271,20 +275,17 @@ def __create_bgp_unicast_neighbor(tgen, topo, input_dict, router, ibgp = max_paths.setdefault("ibgp", None) ebgp = max_paths.setdefault("ebgp", None) if ibgp: - config_data.append("maximum-paths ibgp {}".format( - ibgp - )) + config_data.append("maximum-paths ibgp {}".format(ibgp)) if ebgp: - config_data.append("maximum-paths {}".format( - ebgp - )) + config_data.append("maximum-paths {}".format(ebgp)) aggregate_addresses = addr_data.setdefault("aggregate_address", []) for aggregate_address in aggregate_addresses: network = aggregate_address.setdefault("network", None) if not network: - logger.debug("Router %s: 'network' not present in " - "input_dict for BGP", router) + logger.debug( + "Router %s: 'network' not present in " "input_dict for BGP", router + ) else: cmd = "aggregate-address {}".format(network) @@ -305,13 +306,12 @@ def __create_bgp_unicast_neighbor(tgen, topo, input_dict, router, if redistribute_data: for redistribute in redistribute_data: if "redist_type" not in redistribute: - logger.error("Router %s: 'redist_type' not present in " - "input_dict", router) + logger.error( + "Router %s: 'redist_type' not present in " "input_dict", router + ) else: - cmd = "redistribute {}".format( - redistribute["redist_type"]) - redist_attr = redistribute.setdefault("attribute", - None) + cmd = "redistribute {}".format(redistribute["redist_type"]) + redist_attr = redistribute.setdefault("attribute", None) if redist_attr: cmd = "{} {}".format(cmd, redist_attr) del_action = redistribute.setdefault("delete", False) @@ -320,8 +320,9 @@ def __create_bgp_unicast_neighbor(tgen, topo, input_dict, router, config_data.append(cmd) if "neighbor" in addr_data: - neigh_data = __create_bgp_neighbor(topo, input_dict, - router, addr_type, add_neigh) + neigh_data = __create_bgp_neighbor( + topo, input_dict, router, addr_type, add_neigh + ) config_data.extend(neigh_data) for addr_type, addr_dict in bgp_data.iteritems(): @@ -331,11 +332,11 @@ def __create_bgp_unicast_neighbor(tgen, topo, input_dict, router, addr_data = addr_dict["unicast"] if "neighbor" in addr_data: neigh_addr_data = __create_bgp_unicast_address_family( - topo, input_dict, router, addr_type, add_neigh) + topo, input_dict, router, addr_type, add_neigh + ) config_data.extend(neigh_addr_data) - logger.debug("Exiting lib API: __create_bgp_unicast_neighbor()") return config_data @@ -365,12 +366,10 @@ def __create_bgp_neighbor(topo, input_dict, router, addr_type, add_neigh=True): update_source = None if dest_link in nh_details["links"].keys(): - ip_addr = \ - nh_details["links"][dest_link][addr_type].split("/")[0] + ip_addr = nh_details["links"][dest_link][addr_type].split("/")[0] # Loopback interface if "source_link" in peer and peer["source_link"] == "lo": - update_source = topo[router]["links"]["lo"][ - addr_type].split("/")[0] + update_source = topo[router]["links"]["lo"][addr_type].split("/")[0] neigh_cxt = "neighbor {}".format(ip_addr) @@ -380,41 +379,44 @@ def __create_bgp_neighbor(topo, input_dict, router, addr_type, add_neigh=True): config_data.append("address-family ipv6 unicast") config_data.append("{} activate".format(neigh_cxt)) - disable_connected = peer.setdefault("disable_connected_check", - False) + disable_connected = peer.setdefault("disable_connected_check", False) keep_alive = peer.setdefault("keepalivetimer", 60) hold_down = peer.setdefault("holddowntimer", 180) password = peer.setdefault("password", None) max_hop_limit = peer.setdefault("ebgp_multihop", 1) if update_source: - config_data.append("{} update-source {}".format( - neigh_cxt, update_source)) + config_data.append( + "{} update-source {}".format(neigh_cxt, update_source) + ) if disable_connected: - config_data.append("{} disable-connected-check".format( - disable_connected)) + config_data.append( + "{} disable-connected-check".format(disable_connected) + ) if update_source: - config_data.append("{} update-source {}".format(neigh_cxt, - update_source)) + config_data.append( + "{} update-source {}".format(neigh_cxt, update_source) + ) if int(keep_alive) != 60 and int(hold_down) != 180: config_data.append( - "{} timers {} {}".format(neigh_cxt, keep_alive, - hold_down)) + "{} timers {} {}".format(neigh_cxt, keep_alive, hold_down) + ) if password: - config_data.append( - "{} password {}".format(neigh_cxt, password)) + config_data.append("{} password {}".format(neigh_cxt, password)) if max_hop_limit > 1: - config_data.append("{} ebgp-multihop {}".format(neigh_cxt, - max_hop_limit)) + config_data.append( + "{} ebgp-multihop {}".format(neigh_cxt, max_hop_limit) + ) config_data.append("{} enforce-multihop".format(neigh_cxt)) logger.debug("Exiting lib API: __create_bgp_unicast_neighbor()") return config_data -def __create_bgp_unicast_address_family(topo, input_dict, router, addr_type, - add_neigh=True): +def __create_bgp_unicast_address_family( + topo, input_dict, router, addr_type, add_neigh=True +): """ API prints bgp global config to bgp_json file. @@ -440,31 +442,27 @@ def __create_bgp_unicast_address_family(topo, input_dict, router, addr_type, nh_details = topo[peer_name] # Loopback interface if "source_link" in peer and peer["source_link"] == "lo": - for destRouterLink, data in sorted(nh_details["links"]. - iteritems()): + for destRouterLink, data in sorted(nh_details["links"].iteritems()): if "type" in data and data["type"] == "loopback": if dest_link == destRouterLink: - ip_addr = \ - nh_details["links"][destRouterLink][ - addr_type].split("/")[0] + ip_addr = nh_details["links"][destRouterLink][ + addr_type + ].split("/")[0] # Physical interface else: if dest_link in nh_details["links"].keys(): - ip_addr = nh_details["links"][dest_link][ - addr_type].split("/")[0] + ip_addr = nh_details["links"][dest_link][addr_type].split("/")[0] if addr_type == "ipv4" and bgp_data["ipv6"]: - deactivate = nh_details["links"][ - dest_link]["ipv6"].split("/")[0] + deactivate = nh_details["links"][dest_link]["ipv6"].split("/")[ + 0 + ] neigh_cxt = "neighbor {}".format(ip_addr) - config_data.append("address-family {} unicast".format( - addr_type - )) + config_data.append("address-family {} unicast".format(addr_type)) if deactivate: - config_data.append( - "no neighbor {} activate".format(deactivate)) + config_data.append("no neighbor {} activate".format(deactivate)) next_hop_self = peer.setdefault("next_hop_self", None) send_community = peer.setdefault("send_community", None) @@ -481,8 +479,9 @@ def __create_bgp_unicast_address_family(topo, input_dict, router, addr_type, # no_send_community if no_send_community: - config_data.append("no {} send-community {}".format( - neigh_cxt, no_send_community)) + config_data.append( + "no {} send-community {}".format(neigh_cxt, no_send_community) + ) if prefix_lists: for prefix_list in prefix_lists: @@ -490,12 +489,13 @@ def __create_bgp_unicast_address_family(topo, input_dict, router, addr_type, direction = prefix_list.setdefault("direction", "in") del_action = prefix_list.setdefault("delete", False) if not name: - logger.info("Router %s: 'name' not present in " - "input_dict for BGP neighbor prefix lists", - router) + logger.info( + "Router %s: 'name' not present in " + "input_dict for BGP neighbor prefix lists", + router, + ) else: - cmd = "{} prefix-list {} {}".format(neigh_cxt, name, - direction) + cmd = "{} prefix-list {} {}".format(neigh_cxt, name, direction) if del_action: cmd = "no {}".format(cmd) config_data.append(cmd) @@ -506,12 +506,13 @@ def __create_bgp_unicast_address_family(topo, input_dict, router, addr_type, direction = route_map.setdefault("direction", "in") del_action = route_map.setdefault("delete", False) if not name: - logger.info("Router %s: 'name' not present in " - "input_dict for BGP neighbor route name", - router) + logger.info( + "Router %s: 'name' not present in " + "input_dict for BGP neighbor route name", + router, + ) else: - cmd = "{} route-map {} {}".format(neigh_cxt, name, - direction) + cmd = "{} route-map {} {}".format(neigh_cxt, name, direction) if del_action: cmd = "no {}".format(cmd) config_data.append(cmd) @@ -564,12 +565,10 @@ def verify_router_id(tgen, topo, input_dict): rnode = tgen.routers()[router] - del_router_id = input_dict[router]["bgp"].setdefault( - "del_router_id", False) + del_router_id = input_dict[router]["bgp"].setdefault("del_router_id", False) logger.info("Checking router %s router-id", router) - show_bgp_json = run_frr_cmd(rnode, "show bgp summary json", - isjson=True) + show_bgp_json = run_frr_cmd(rnode, "show bgp summary json", isjson=True) router_id_out = show_bgp_json["ipv4Unicast"]["routerId"] router_id_out = ipaddr.IPv4Address(unicode(router_id_out)) @@ -582,12 +581,12 @@ def verify_router_id(tgen, topo, input_dict): router_id = ipaddr.IPv4Address(unicode(router_id)) if router_id == router_id_out: - logger.info("Found expected router-id %s for router %s", - router_id, router) + logger.info("Found expected router-id %s for router %s", router_id, router) else: - errormsg = "Router-id for router:{} mismatch, expected:" \ - " {} but found:{}".format(router, router_id, - router_id_out) + errormsg = ( + "Router-id for router:{} mismatch, expected:" + " {} but found:{}".format(router, router_id, router_id_out) + ) return errormsg logger.debug("Exiting lib API: verify_router_id()") @@ -618,8 +617,7 @@ def verify_bgp_convergence(tgen, topo): logger.debug("Entering lib API: verify_bgp_convergence()") for router, rnode in tgen.routers().iteritems(): logger.info("Verifying BGP Convergence on router %s", router) - show_bgp_json = run_frr_cmd(rnode, "show bgp summary json", - isjson=True) + show_bgp_json = run_frr_cmd(rnode, "show bgp summary json", isjson=True) # Verifying output dictionary show_bgp_json is empty or not if not bool(show_bgp_json): errormsg = "BGP is not running" @@ -647,15 +645,12 @@ def verify_bgp_convergence(tgen, topo): for dest_link in peer_data["dest_link"].keys(): data = topo["routers"][bgp_neighbor]["links"] if dest_link in data: - neighbor_ip = \ - data[dest_link][addr_type].split("/")[0] + neighbor_ip = data[dest_link][addr_type].split("/")[0] if addr_type == "ipv4": - ipv4_data = show_bgp_json["ipv4Unicast"][ - "peers"] + ipv4_data = show_bgp_json["ipv4Unicast"]["peers"] nh_state = ipv4_data[neighbor_ip]["state"] else: - ipv6_data = show_bgp_json["ipv6Unicast"][ - "peers"] + ipv6_data = show_bgp_json["ipv6Unicast"]["peers"] nh_state = ipv6_data[neighbor_ip]["state"] if nh_state == "Established": @@ -663,8 +658,7 @@ def verify_bgp_convergence(tgen, topo): if no_of_peer == total_peer: logger.info("BGP is Converged for router %s", router) else: - errormsg = "BGP is not converged for router {}".format( - router) + errormsg = "BGP is not converged for router {}".format(router) return errormsg logger.debug("Exiting API: verify_bgp_convergence()") @@ -707,16 +701,9 @@ def modify_as_number(tgen, topo, input_dict): for router in input_dict.keys(): # Remove bgp configuration - router_dict.update({ - router: { - "bgp": { - "delete": True - } - } - }) + router_dict.update({router: {"bgp": {"delete": True}}}) - new_topo[router]["bgp"]["local_as"] = \ - input_dict[router]["bgp"]["local_as"] + new_topo[router]["bgp"]["local_as"] = input_dict[router]["bgp"]["local_as"] logger.info("Removing bgp configuration") create_router_bgp(tgen, topo, router_dict) @@ -777,8 +764,9 @@ def verify_as_numbers(tgen, topo, input_dict): logger.info("Verifying AS numbers for dut %s:", router) - show_ip_bgp_neighbor_json = run_frr_cmd(rnode, - "show ip bgp neighbor json", isjson=True) + show_ip_bgp_neighbor_json = run_frr_cmd( + rnode, "show ip bgp neighbor json", isjson=True + ) local_as = input_dict[router]["bgp"]["local_as"] bgp_addr_type = topo["routers"][router]["bgp"]["address_family"] @@ -786,8 +774,7 @@ def verify_as_numbers(tgen, topo, input_dict): if not check_address_types(addr_type): continue - bgp_neighbors = bgp_addr_type[addr_type]["unicast"][ - "neighbor"] + bgp_neighbors = bgp_addr_type[addr_type]["unicast"]["neighbor"] for bgp_neighbor, peer_data in bgp_neighbors.iteritems(): remote_as = input_dict[bgp_neighbor]["bgp"]["local_as"] @@ -796,32 +783,42 @@ def verify_as_numbers(tgen, topo, input_dict): data = topo["routers"][bgp_neighbor]["links"] if dest_link in data: - neighbor_ip = data[dest_link][addr_type]. \ - split("/")[0] + neighbor_ip = data[dest_link][addr_type].split("/")[0] neigh_data = show_ip_bgp_neighbor_json[neighbor_ip] # Verify Local AS for router if neigh_data["localAs"] != local_as: - errormsg = "Failed: Verify local_as for dut {}," \ - " found: {} but expected: {}".format( - router, neigh_data["localAs"], - local_as) + errormsg = ( + "Failed: Verify local_as for dut {}," + " found: {} but expected: {}".format( + router, neigh_data["localAs"], local_as + ) + ) return errormsg else: - logger.info("Verified local_as for dut %s, found" - " expected: %s", router, local_as) + logger.info( + "Verified local_as for dut %s, found" " expected: %s", + router, + local_as, + ) # Verify Remote AS for neighbor if neigh_data["remoteAs"] != remote_as: - errormsg = "Failed: Verify remote_as for dut " \ - "{}'s neighbor {}, found: {} but " \ - "expected: {}".format( - router, bgp_neighbor, - neigh_data["remoteAs"], remote_as) + errormsg = ( + "Failed: Verify remote_as for dut " + "{}'s neighbor {}, found: {} but " + "expected: {}".format( + router, bgp_neighbor, neigh_data["remoteAs"], remote_as + ) + ) return errormsg else: - logger.info("Verified remote_as for dut %s's " - "neighbor %s, found expected: %s", - router, bgp_neighbor, remote_as) + logger.info( + "Verified remote_as for dut %s's " + "neighbor %s, found expected: %s", + router, + bgp_neighbor, + remote_as, + ) logger.debug("Exiting lib API: verify_AS_numbers()") return True @@ -862,12 +859,14 @@ def clear_bgp_and_verify(tgen, topo, router): for retry in range(31): sleeptime = 3 # Waiting for BGP to converge - logger.info("Waiting for %s sec for BGP to converge on router" - " %s...", sleeptime, router) + logger.info( + "Waiting for %s sec for BGP to converge on router" " %s...", + sleeptime, + router, + ) sleep(sleeptime) - show_bgp_json = run_frr_cmd(rnode, "show bgp summary json", - isjson=True) + show_bgp_json = run_frr_cmd(rnode, "show bgp summary json", isjson=True) # Verifying output dictionary show_bgp_json is empty or not if not bool(show_bgp_json): errormsg = "BGP is not running" @@ -897,35 +896,37 @@ def clear_bgp_and_verify(tgen, topo, router): if dest_link in data: neighbor_ip = data[dest_link][addr_type].split("/")[0] if addr_type == "ipv4": - ipv4_data = show_bgp_json["ipv4Unicast"][ - "peers"] + ipv4_data = show_bgp_json["ipv4Unicast"]["peers"] nh_state = ipv4_data[neighbor_ip]["state"] # Peer up time dictionary - peer_uptime_before_clear_bgp[bgp_neighbor] = \ - ipv4_data[neighbor_ip]["peerUptimeEstablishedEpoch"] + peer_uptime_before_clear_bgp[bgp_neighbor] = ipv4_data[ + neighbor_ip + ]["peerUptimeEstablishedEpoch"] else: - ipv6_data = show_bgp_json["ipv6Unicast"][ - "peers"] + ipv6_data = show_bgp_json["ipv6Unicast"]["peers"] nh_state = ipv6_data[neighbor_ip]["state"] # Peer up time dictionary - peer_uptime_before_clear_bgp[bgp_neighbor] = \ - ipv6_data[neighbor_ip]["peerUptimeEstablishedEpoch"] + peer_uptime_before_clear_bgp[bgp_neighbor] = ipv6_data[ + neighbor_ip + ]["peerUptimeEstablishedEpoch"] if nh_state == "Established": no_of_peer += 1 if no_of_peer == total_peer: - logger.info("BGP is Converged for router %s before bgp" - " clear", router) + logger.info("BGP is Converged for router %s before bgp" " clear", router) break else: - logger.info("BGP is not yet Converged for router %s " - "before bgp clear", router) + logger.info( + "BGP is not yet Converged for router %s " "before bgp clear", router + ) else: - errormsg = "TIMEOUT!! BGP is not converged in 30 seconds for" \ - " router {}".format(router) + errormsg = ( + "TIMEOUT!! BGP is not converged in 30 seconds for" + " router {}".format(router) + ) return errormsg logger.info(peer_uptime_before_clear_bgp) @@ -942,13 +943,14 @@ def clear_bgp_and_verify(tgen, topo, router): for retry in range(31): sleeptime = 3 # Waiting for BGP to converge - logger.info("Waiting for %s sec for BGP to converge on router" - " %s...", sleeptime, router) + logger.info( + "Waiting for %s sec for BGP to converge on router" " %s...", + sleeptime, + router, + ) sleep(sleeptime) - - show_bgp_json = run_frr_cmd(rnode, "show bgp summary json", - isjson=True) + show_bgp_json = run_frr_cmd(rnode, "show bgp summary json", isjson=True) # Verifying output dictionary show_bgp_json is empty or not if not bool(show_bgp_json): errormsg = "BGP is not running" @@ -975,44 +977,46 @@ def clear_bgp_and_verify(tgen, topo, router): data = topo["routers"][bgp_neighbor]["links"] if dest_link in data: - neighbor_ip = data[dest_link][addr_type].\ - split("/")[0] + neighbor_ip = data[dest_link][addr_type].split("/")[0] if addr_type == "ipv4": - ipv4_data = show_bgp_json["ipv4Unicast"][ - "peers"] + ipv4_data = show_bgp_json["ipv4Unicast"]["peers"] nh_state = ipv4_data[neighbor_ip]["state"] - peer_uptime_after_clear_bgp[bgp_neighbor] = \ - ipv4_data[neighbor_ip]["peerUptimeEstablishedEpoch"] + peer_uptime_after_clear_bgp[bgp_neighbor] = ipv4_data[ + neighbor_ip + ]["peerUptimeEstablishedEpoch"] else: - ipv6_data = show_bgp_json["ipv6Unicast"][ - "peers"] + ipv6_data = show_bgp_json["ipv6Unicast"]["peers"] nh_state = ipv6_data[neighbor_ip]["state"] # Peer up time dictionary - peer_uptime_after_clear_bgp[bgp_neighbor] = \ - ipv6_data[neighbor_ip]["peerUptimeEstablishedEpoch"] + peer_uptime_after_clear_bgp[bgp_neighbor] = ipv6_data[ + neighbor_ip + ]["peerUptimeEstablishedEpoch"] if nh_state == "Established": no_of_peer += 1 if no_of_peer == total_peer: - logger.info("BGP is Converged for router %s after bgp clear", - router) + logger.info("BGP is Converged for router %s after bgp clear", router) break else: - logger.info("BGP is not yet Converged for router %s after" - " bgp clear", router) + logger.info( + "BGP is not yet Converged for router %s after" " bgp clear", router + ) else: - errormsg = "TIMEOUT!! BGP is not converged in 30 seconds for" \ - " router {}".format(router) + errormsg = ( + "TIMEOUT!! BGP is not converged in 30 seconds for" + " router {}".format(router) + ) return errormsg logger.info(peer_uptime_after_clear_bgp) # Comparing peerUptimeEstablishedEpoch dictionaries if peer_uptime_before_clear_bgp != peer_uptime_after_clear_bgp: - logger.info("BGP neighborship is reset after clear BGP on router %s", - router) + logger.info("BGP neighborship is reset after clear BGP on router %s", router) else: - errormsg = "BGP neighborship is not reset after clear bgp on router" \ - " {}".format(router) + errormsg = ( + "BGP neighborship is not reset after clear bgp on router" + " {}".format(router) + ) return errormsg logger.debug("Exiting lib API: clear_bgp_and_verify()") @@ -1060,11 +1064,11 @@ def verify_bgp_timers_and_functionality(tgen, topo, input_dict): rnode = router_list[router] - logger.info("Verifying bgp timers functionality, DUT is %s:", - router) + logger.info("Verifying bgp timers functionality, DUT is %s:", router) - show_ip_bgp_neighbor_json = \ - run_frr_cmd(rnode, "show ip bgp neighbor json", isjson=True) + show_ip_bgp_neighbor_json = run_frr_cmd( + rnode, "show ip bgp neighbor json", isjson=True + ) bgp_addr_type = input_dict[router]["bgp"]["address_family"] @@ -1072,8 +1076,7 @@ def verify_bgp_timers_and_functionality(tgen, topo, input_dict): if not check_address_types(addr_type): continue - bgp_neighbors = bgp_addr_type[addr_type]["unicast"][ - "neighbor"] + bgp_neighbors = bgp_addr_type[addr_type]["unicast"]["neighbor"] for bgp_neighbor, peer_data in bgp_neighbors.iteritems(): for dest_link, peer_dict in peer_data["dest_link"].iteritems(): data = topo["routers"][bgp_neighbor]["links"] @@ -1082,32 +1085,41 @@ def verify_bgp_timers_and_functionality(tgen, topo, input_dict): holddowntimer = peer_dict["holddowntimer"] if dest_link in data: - neighbor_ip = data[dest_link][addr_type]. \ - split("/")[0] + neighbor_ip = data[dest_link][addr_type].split("/")[0] neighbor_intf = data[dest_link]["interface"] # Verify HoldDownTimer for neighbor - bgpHoldTimeMsecs = show_ip_bgp_neighbor_json[ - neighbor_ip]["bgpTimerHoldTimeMsecs"] + bgpHoldTimeMsecs = show_ip_bgp_neighbor_json[neighbor_ip][ + "bgpTimerHoldTimeMsecs" + ] if bgpHoldTimeMsecs != holddowntimer * 1000: - errormsg = "Verifying holddowntimer for bgp " \ - "neighbor {} under dut {}, found: {} " \ - "but expected: {}".format( - neighbor_ip, router, - bgpHoldTimeMsecs, - holddowntimer * 1000) + errormsg = ( + "Verifying holddowntimer for bgp " + "neighbor {} under dut {}, found: {} " + "but expected: {}".format( + neighbor_ip, + router, + bgpHoldTimeMsecs, + holddowntimer * 1000, + ) + ) return errormsg # Verify KeepAliveTimer for neighbor - bgpKeepAliveTimeMsecs = show_ip_bgp_neighbor_json[ - neighbor_ip]["bgpTimerKeepAliveIntervalMsecs"] + bgpKeepAliveTimeMsecs = show_ip_bgp_neighbor_json[neighbor_ip][ + "bgpTimerKeepAliveIntervalMsecs" + ] if bgpKeepAliveTimeMsecs != keepalivetimer * 1000: - errormsg = "Verifying keepalivetimer for bgp " \ - "neighbor {} under dut {}, found: {} " \ - "but expected: {}".format( - neighbor_ip, router, - bgpKeepAliveTimeMsecs, - keepalivetimer * 1000) + errormsg = ( + "Verifying keepalivetimer for bgp " + "neighbor {} under dut {}, found: {} " + "but expected: {}".format( + neighbor_ip, + router, + bgpKeepAliveTimeMsecs, + keepalivetimer * 1000, + ) + ) return errormsg #################### @@ -1120,40 +1132,50 @@ def verify_bgp_timers_and_functionality(tgen, topo, input_dict): # Wait till keep alive time logger.info("=" * 20) logger.info("Scenario 1:") - logger.info("Shutdown and bring up peer interface: %s " - "in keep alive time : %s sec and verify " - " BGP neighborship is intact in %s sec ", - neighbor_intf, keepalivetimer, - (holddowntimer - keepalivetimer)) + logger.info( + "Shutdown and bring up peer interface: %s " + "in keep alive time : %s sec and verify " + " BGP neighborship is intact in %s sec ", + neighbor_intf, + keepalivetimer, + (holddowntimer - keepalivetimer), + ) logger.info("=" * 20) logger.info("Waiting for %s sec..", keepalivetimer) sleep(keepalivetimer) # Shutting down peer ineterface - logger.info("Shutting down interface %s on router %s", - neighbor_intf, bgp_neighbor) + logger.info( + "Shutting down interface %s on router %s", + neighbor_intf, + bgp_neighbor, + ) topotest.interface_set_status( - router_list[bgp_neighbor], neighbor_intf, - ifaceaction=False) + router_list[bgp_neighbor], neighbor_intf, ifaceaction=False + ) # Bringing up peer interface sleep(5) - logger.info("Bringing up interface %s on router %s..", - neighbor_intf, bgp_neighbor) + logger.info( + "Bringing up interface %s on router %s..", + neighbor_intf, + bgp_neighbor, + ) topotest.interface_set_status( - router_list[bgp_neighbor], neighbor_intf, - ifaceaction=True) + router_list[bgp_neighbor], neighbor_intf, ifaceaction=True + ) # Verifying BGP neighborship is intact in # (holddown - keepalive) time - for timer in range(keepalivetimer, holddowntimer, - int(holddowntimer / 3)): + for timer in range( + keepalivetimer, holddowntimer, int(holddowntimer / 3) + ): logger.info("Waiting for %s sec..", keepalivetimer) sleep(keepalivetimer) sleep(2) - show_bgp_json = \ - run_frr_cmd(rnode, "show bgp summary json", - isjson=True) + show_bgp_json = run_frr_cmd( + rnode, "show bgp summary json", isjson=True + ) if addr_type == "ipv4": ipv4_data = show_bgp_json["ipv4Unicast"]["peers"] @@ -1162,17 +1184,22 @@ def verify_bgp_timers_and_functionality(tgen, topo, input_dict): ipv6_data = show_bgp_json["ipv6Unicast"]["peers"] nh_state = ipv6_data[neighbor_ip]["state"] - if timer == \ - (holddowntimer - keepalivetimer): + if timer == (holddowntimer - keepalivetimer): if nh_state != "Established": - errormsg = "BGP neighborship has not gone " \ - "down in {} sec for neighbor {}" \ - .format(timer, bgp_neighbor) + errormsg = ( + "BGP neighborship has not gone " + "down in {} sec for neighbor {}".format( + timer, bgp_neighbor + ) + ) return errormsg else: - logger.info("BGP neighborship is intact in %s" - " sec for neighbor %s", - timer, bgp_neighbor) + logger.info( + "BGP neighborship is intact in %s" + " sec for neighbor %s", + timer, + bgp_neighbor, + ) #################### # Shutting down peer interface and verifying that BGP @@ -1180,27 +1207,36 @@ def verify_bgp_timers_and_functionality(tgen, topo, input_dict): #################### logger.info("=" * 20) logger.info("Scenario 2:") - logger.info("Shutdown peer interface: %s and verify BGP" - " neighborship has gone down in hold down " - "time %s sec", neighbor_intf, holddowntimer) + logger.info( + "Shutdown peer interface: %s and verify BGP" + " neighborship has gone down in hold down " + "time %s sec", + neighbor_intf, + holddowntimer, + ) logger.info("=" * 20) - logger.info("Shutting down interface %s on router %s..", - neighbor_intf, bgp_neighbor) - topotest.interface_set_status(router_list[bgp_neighbor], - neighbor_intf, - ifaceaction=False) + logger.info( + "Shutting down interface %s on router %s..", + neighbor_intf, + bgp_neighbor, + ) + topotest.interface_set_status( + router_list[bgp_neighbor], neighbor_intf, ifaceaction=False + ) # Verifying BGP neighborship is going down in holddown time - for timer in range(keepalivetimer, - (holddowntimer + keepalivetimer), - int(holddowntimer / 3)): + for timer in range( + keepalivetimer, + (holddowntimer + keepalivetimer), + int(holddowntimer / 3), + ): logger.info("Waiting for %s sec..", keepalivetimer) sleep(keepalivetimer) sleep(2) - show_bgp_json = \ - run_frr_cmd(rnode, "show bgp summary json", - isjson=True) + show_bgp_json = run_frr_cmd( + rnode, "show bgp summary json", isjson=True + ) if addr_type == "ipv4": ipv4_data = show_bgp_json["ipv4Unicast"]["peers"] @@ -1211,22 +1247,29 @@ def verify_bgp_timers_and_functionality(tgen, topo, input_dict): if timer == holddowntimer: if nh_state == "Established": - errormsg = "BGP neighborship has not gone " \ - "down in {} sec for neighbor {}" \ - .format(timer, bgp_neighbor) + errormsg = ( + "BGP neighborship has not gone " + "down in {} sec for neighbor {}".format( + timer, bgp_neighbor + ) + ) return errormsg else: - logger.info("BGP neighborship has gone down in" - " %s sec for neighbor %s", - timer, bgp_neighbor) + logger.info( + "BGP neighborship has gone down in" + " %s sec for neighbor %s", + timer, + bgp_neighbor, + ) logger.debug("Exiting lib API: verify_bgp_timers_and_functionality()") return True @retry(attempts=3, wait=4, return_is_str=True) -def verify_bgp_attributes(tgen, addr_type, dut, static_routes, rmap_name, - input_dict, seq_id=None): +def verify_bgp_attributes( + tgen, addr_type, dut, static_routes, rmap_name, input_dict, seq_id=None +): """ API will verify BGP attributes set by Route-map for given prefix and DUT. it will run "show bgp ipv4/ipv6 {prefix_address} json" command @@ -1288,7 +1331,7 @@ def verify_bgp_attributes(tgen, addr_type, dut, static_routes, rmap_name, if router != dut: continue - logger.info('Verifying BGP set attributes for dut {}:'.format(router)) + logger.info("Verifying BGP set attributes for dut {}:".format(router)) for static_route in static_routes: cmd = "show bgp {} {} json".format(addr_type, static_route) @@ -1297,8 +1340,7 @@ def verify_bgp_attributes(tgen, addr_type, dut, static_routes, rmap_name, dict_to_test = [] tmp_list = [] for rmap_router in input_dict.keys(): - for rmap, values in input_dict[rmap_router][ - "route_maps"].items(): + for rmap, values in input_dict[rmap_router]["route_maps"].items(): if rmap == rmap_name: dict_to_test = values for rmap_dict in values: @@ -1307,8 +1349,7 @@ def verify_bgp_attributes(tgen, addr_type, dut, static_routes, rmap_name, seq_id = [seq_id] if "seq_id" in rmap_dict: - rmap_seq_id = \ - rmap_dict["seq_id"] + rmap_seq_id = rmap_dict["seq_id"] for _seq_id in seq_id: if _seq_id == rmap_seq_id: tmp_list.append(rmap_dict) @@ -1318,55 +1359,56 @@ def verify_bgp_attributes(tgen, addr_type, dut, static_routes, rmap_name, for rmap_dict in dict_to_test: if "set" in rmap_dict: for criteria in rmap_dict["set"].keys(): - if criteria not in show_bgp_json[ - "paths"][0]: - errormsg = ("BGP attribute: {}" - " is not found in" - " cli: {} output " - "in router {}". - format(criteria, - cmd, - router)) + if criteria not in show_bgp_json["paths"][0]: + errormsg = ( + "BGP attribute: {}" + " is not found in" + " cli: {} output " + "in router {}".format(criteria, cmd, router) + ) return errormsg - if rmap_dict["set"][criteria] == \ - show_bgp_json["paths"][0][ - criteria]: - logger.info("Verifying BGP " - "attribute {} for" - " route: {} in " - "router: {}, found" - " expected value:" - " {}". - format(criteria, - static_route, - dut, - rmap_dict[ - "set"][ - criteria])) + if ( + rmap_dict["set"][criteria] + == show_bgp_json["paths"][0][criteria] + ): + logger.info( + "Verifying BGP " + "attribute {} for" + " route: {} in " + "router: {}, found" + " expected value:" + " {}".format( + criteria, + static_route, + dut, + rmap_dict["set"][criteria], + ) + ) else: - errormsg = \ - ("Failed: Verifying BGP " - "attribute {} for route:" - " {} in router: {}, " - " expected value: {} but" - " found: {}". - format(criteria, - static_route, - dut, - rmap_dict["set"] - [criteria], - show_bgp_json[ - 'paths'][ - 0][criteria])) + errormsg = ( + "Failed: Verifying BGP " + "attribute {} for route:" + " {} in router: {}, " + " expected value: {} but" + " found: {}".format( + criteria, + static_route, + dut, + rmap_dict["set"][criteria], + show_bgp_json["paths"][0][criteria], + ) + ) return errormsg logger.debug("Exiting lib API: verify_bgp_attributes()") return True + @retry(attempts=4, wait=2, return_is_str=True, initial_wait=2) -def verify_best_path_as_per_bgp_attribute(tgen, addr_type, router, input_dict, - attribute): +def verify_best_path_as_per_bgp_attribute( + tgen, addr_type, router, input_dict, attribute +): """ API is to verify best path according to BGP attributes for given routes. "show bgp ipv4/6 json" command will be run and verify best path according @@ -1445,38 +1487,36 @@ def verify_best_path_as_per_bgp_attribute(tgen, addr_type, router, input_dict, # AS_PATH attribute if attribute == "path": # Find next_hop for the route have minimum as_path - _next_hop = min(attribute_dict, key=lambda x: len(set( - attribute_dict[x]))) + _next_hop = min( + attribute_dict, key=lambda x: len(set(attribute_dict[x])) + ) compare = "SHORTEST" # LOCAL_PREF attribute elif attribute == "locPrf": # Find next_hop for the route have highest local preference - _next_hop = max(attribute_dict, key=(lambda k: - attribute_dict[k])) + _next_hop = max(attribute_dict, key=(lambda k: attribute_dict[k])) compare = "HIGHEST" # WEIGHT attribute elif attribute == "weight": # Find next_hop for the route have highest weight - _next_hop = max(attribute_dict, key=(lambda k: - attribute_dict[k])) + _next_hop = max(attribute_dict, key=(lambda k: attribute_dict[k])) compare = "HIGHEST" # ORIGIN attribute elif attribute == "origin": # Find next_hop for the route have IGP as origin, - # - rule is IGP>EGP>INCOMPLETE - _next_hop = [key for (key, value) in - attribute_dict.iteritems() - if value == "IGP"][0] + _next_hop = [ + key for (key, value) in attribute_dict.iteritems() if value == "IGP" + ][0] compare = "" # MED attribute elif attribute == "metric": # Find next_hop for the route have LOWEST MED - _next_hop = min(attribute_dict, key=(lambda k: - attribute_dict[k])) + _next_hop = min(attribute_dict, key=(lambda k: attribute_dict[k])) compare = "LOWEST" # Show ip route @@ -1489,8 +1529,7 @@ def verify_best_path_as_per_bgp_attribute(tgen, addr_type, router, input_dict, # Verifying output dictionary rib_routes_json is not empty if not bool(rib_routes_json): - errormsg = "No route found in RIB of router {}..". \ - format(router) + errormsg = "No route found in RIB of router {}..".format(router) return errormsg st_found = False @@ -1499,31 +1538,41 @@ def verify_best_path_as_per_bgp_attribute(tgen, addr_type, router, input_dict, if route in rib_routes_json: st_found = True # Verify next_hop in rib_routes_json - if rib_routes_json[route][0]["nexthops"][0]["ip"] in \ - attribute_dict: + if rib_routes_json[route][0]["nexthops"][0]["ip"] in attribute_dict: nh_found = True else: - errormsg = "Incorrect Nexthop for BGP route {} in " \ - "RIB of router {}, Expected: {}, Found:" \ - " {}\n".format(route, router, - rib_routes_json[route][0][ - "nexthops"][0]["ip"], - _next_hop) + errormsg = ( + "Incorrect Nexthop for BGP route {} in " + "RIB of router {}, Expected: {}, Found:" + " {}\n".format( + route, + router, + rib_routes_json[route][0]["nexthops"][0]["ip"], + _next_hop, + ) + ) return errormsg if st_found and nh_found: logger.info( "Best path for prefix: %s with next_hop: %s is " "installed according to %s %s: (%s) in RIB of " - "router %s", route, _next_hop, compare, - attribute, attribute_dict[_next_hop], router) + "router %s", + route, + _next_hop, + compare, + attribute, + attribute_dict[_next_hop], + router, + ) logger.debug("Exiting lib API: verify_best_path_as_per_bgp_attribute()") return True -def verify_best_path_as_per_admin_distance(tgen, addr_type, router, input_dict, - attribute): +def verify_best_path_as_per_admin_distance( + tgen, addr_type, router, input_dict, attribute +): """ API is to verify best path according to admin distance for given route. "show ip/ipv6 route json" command will be run and verify @@ -1574,7 +1623,8 @@ def verify_best_path_as_per_admin_distance(tgen, addr_type, router, input_dict, for routes_from_router in input_dict.keys(): sh_ip_route_json = router_list[routes_from_router].vtysh_cmd( - command, isjson=True) + command, isjson=True + ) networks = input_dict[routes_from_router]["static_routes"] for network in networks: route = network["network"] @@ -1590,8 +1640,7 @@ def verify_best_path_as_per_admin_distance(tgen, addr_type, router, input_dict, attribute_dict[next_hop_ip] = route_attribute["distance"] # Find next_hop for the route have LOWEST Admin Distance - _next_hop = min(attribute_dict, key=(lambda k: - attribute_dict[k])) + _next_hop = min(attribute_dict, key=(lambda k: attribute_dict[k])) compare = "LOWEST" # Show ip route @@ -1608,21 +1657,25 @@ def verify_best_path_as_per_admin_distance(tgen, addr_type, router, input_dict, if route in rib_routes_json: st_found = True # Verify next_hop in rib_routes_json - if rib_routes_json[route][0]["nexthops"][0]["ip"] == \ - _next_hop: + if rib_routes_json[route][0]["nexthops"][0]["ip"] == _next_hop: nh_found = True else: - errormsg = ("Nexthop {} is Missing for BGP route {}" - " in RIB of router {}\n".format(_next_hop, - route, router)) + errormsg = ( + "Nexthop {} is Missing for BGP route {}" + " in RIB of router {}\n".format(_next_hop, route, router) + ) return errormsg if st_found and nh_found: - logger.info("Best path for prefix: %s is installed according" - " to %s %s: (%s) in RIB of router %s", route, - compare, attribute, - attribute_dict[_next_hop], router) + logger.info( + "Best path for prefix: %s is installed according" + " to %s %s: (%s) in RIB of router %s", + route, + compare, + attribute, + attribute_dict[_next_hop], + router, + ) - logger.info( - "Exiting lib API: verify_best_path_as_per_admin_distance()") + logger.info("Exiting lib API: verify_best_path_as_per_admin_distance()") return True diff --git a/tests/topotests/lib/bgprib.py b/tests/topotests/lib/bgprib.py index 5a81036643..3d92718c78 100644 --- a/tests/topotests/lib/bgprib.py +++ b/tests/topotests/lib/bgprib.py @@ -16,14 +16,14 @@ # with this program; see the file COPYING; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# +# # want_rd_routes = [ # {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1'}, # {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1'}, -# +# # {'rd':'10:3', 'p':'5.1.0.0/24', 'n':'3.3.3.3'}, # ] -# +# # ribRequireVpnRoutes('r2','Customer routes',want_rd_routes) # # want_unicast_routes = [ @@ -34,116 +34,133 @@ # ribRequireUnicastRoutes('r1','ipv4','','Customer routes in default',want_unicast_routes) # -from lutil import luCommand,luResult +from lutil import luCommand, luResult import json import re # gpz: get rib in json form and compare against desired routes class BgpRib: - def routes_include_wanted(self,pfxtbl,want,debug): - # helper function to RequireVpnRoutes - for pfx in pfxtbl.iterkeys(): - if debug: - print 'trying pfx ' + pfx - if pfx != want['p']: - if debug: - print 'want pfx=' + want['p'] + ', not ' + pfx - continue - if debug: - print 'have pfx=' + pfx - for r in pfxtbl[pfx]: - if debug: - print 'trying route' - nexthops = r['nexthops'] - for nh in nexthops: - if debug: - print 'trying nh ' + nh['ip'] - if nh['ip'] == want['n']: - if debug: - print 'found ' + want['n'] - return 1 - else: - if debug: - print 'want nh=' + want['n'] + ', not ' + nh['ip'] - if debug: - print 'missing route: pfx=' + want['p'] + ', nh=' + want['n'] - return 0 + def routes_include_wanted(self, pfxtbl, want, debug): + # helper function to RequireVpnRoutes + for pfx in pfxtbl.iterkeys(): + if debug: + print "trying pfx " + pfx + if pfx != want["p"]: + if debug: + print "want pfx=" + want["p"] + ", not " + pfx + continue + if debug: + print "have pfx=" + pfx + for r in pfxtbl[pfx]: + if debug: + print "trying route" + nexthops = r["nexthops"] + for nh in nexthops: + if debug: + print "trying nh " + nh["ip"] + if nh["ip"] == want["n"]: + if debug: + print "found " + want["n"] + return 1 + else: + if debug: + print "want nh=" + want["n"] + ", not " + nh["ip"] + if debug: + print "missing route: pfx=" + want["p"] + ", nh=" + want["n"] + return 0 def RequireVpnRoutes(self, target, title, wantroutes, debug=0): - import json + import json + logstr = "RequireVpnRoutes " + str(wantroutes) - #non json form for humans - luCommand(target,'vtysh -c "show bgp ipv4 vpn"','.','None','Get VPN RIB (non-json)') - ret = luCommand(target,'vtysh -c "show bgp ipv4 vpn json"','.*','None','Get VPN RIB (json)') - if re.search(r'^\s*$', ret): + # non json form for humans + luCommand( + target, + 'vtysh -c "show bgp ipv4 vpn"', + ".", + "None", + "Get VPN RIB (non-json)", + ) + ret = luCommand( + target, + 'vtysh -c "show bgp ipv4 vpn json"', + ".*", + "None", + "Get VPN RIB (json)", + ) + if re.search(r"^\s*$", ret): # degenerate case: empty json means no routes if len(wantroutes) > 0: luResult(target, False, title, logstr) return luResult(target, True, title, logstr) - rib = json.loads(ret) - rds = rib['routes']['routeDistinguishers'] - for want in wantroutes: - found = 0 - if debug: - print "want rd " + want['rd'] - for rd in rds.iterkeys(): - if rd != want['rd']: - continue - if debug: - print "found rd " + rd - table = rds[rd] - if self.routes_include_wanted(table,want,debug): - found = 1 - break - if not found: - luResult(target, False, title, logstr) - return - luResult(target, True, title, logstr) + rib = json.loads(ret) + rds = rib["routes"]["routeDistinguishers"] + for want in wantroutes: + found = 0 + if debug: + print "want rd " + want["rd"] + for rd in rds.iterkeys(): + if rd != want["rd"]: + continue + if debug: + print "found rd " + rd + table = rds[rd] + if self.routes_include_wanted(table, want, debug): + found = 1 + break + if not found: + luResult(target, False, title, logstr) + return + luResult(target, True, title, logstr) - def RequireUnicastRoutes(self,target,afi,vrf,title,wantroutes,debug=0): + def RequireUnicastRoutes(self, target, afi, vrf, title, wantroutes, debug=0): logstr = "RequireVpnRoutes " + str(wantroutes) - vrfstr = '' - if vrf != '': - vrfstr = 'vrf %s' % (vrf) + vrfstr = "" + if vrf != "": + vrfstr = "vrf %s" % (vrf) - if (afi != 'ipv4') and (afi != 'ipv6'): - print "ERROR invalid afi"; + if (afi != "ipv4") and (afi != "ipv6"): + print "ERROR invalid afi" - cmdstr = 'show bgp %s %s unicast' % (vrfstr, afi) - #non json form for humans - cmd = 'vtysh -c "%s"' % cmdstr - luCommand(target,cmd,'.','None','Get %s %s RIB (non-json)' % (vrfstr, afi)) + cmdstr = "show bgp %s %s unicast" % (vrfstr, afi) + # non json form for humans + cmd = 'vtysh -c "%s"' % cmdstr + luCommand(target, cmd, ".", "None", "Get %s %s RIB (non-json)" % (vrfstr, afi)) cmd = 'vtysh -c "%s json"' % cmdstr - ret = luCommand(target,cmd,'.*','None','Get %s %s RIB (json)' % (vrfstr, afi)) - if re.search(r'^\s*$', ret): + ret = luCommand( + target, cmd, ".*", "None", "Get %s %s RIB (json)" % (vrfstr, afi) + ) + if re.search(r"^\s*$", ret): # degenerate case: empty json means no routes if len(wantroutes) > 0: luResult(target, False, title, logstr) return luResult(target, True, title, logstr) - rib = json.loads(ret) + rib = json.loads(ret) try: - table = rib['routes'] - # KeyError: 'routes' probably means missing/bad VRF + table = rib["routes"] + # KeyError: 'routes' probably means missing/bad VRF except KeyError as err: - if vrf != '': - errstr = '-script ERROR: check if wrong vrf (%s)' % (vrf) + if vrf != "": + errstr = "-script ERROR: check if wrong vrf (%s)" % (vrf) else: - errstr = '-script ERROR: check if vrf missing' - luResult(target, False, title + errstr, logstr) - return - for want in wantroutes: - if not self.routes_include_wanted(table,want,debug): - luResult(target, False, title, logstr) - return - luResult(target, True, title, logstr) + errstr = "-script ERROR: check if vrf missing" + luResult(target, False, title + errstr, logstr) + return + for want in wantroutes: + if not self.routes_include_wanted(table, want, debug): + luResult(target, False, title, logstr) + return + luResult(target, True, title, logstr) -BgpRib=BgpRib() +BgpRib = BgpRib() + def bgpribRequireVpnRoutes(target, title, wantroutes, debug=0): BgpRib.RequireVpnRoutes(target, title, wantroutes, debug) + def bgpribRequireUnicastRoutes(target, afi, vrf, title, wantroutes, debug=0): BgpRib.RequireUnicastRoutes(target, afi, vrf, title, wantroutes, debug) diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index 8a9d2d64c9..5ee59070cc 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -79,9 +79,9 @@ if config.has_option("topogen", "frrtest_log_dir"): frrtest_log_file = frrtest_log_dir + logfile_name + str(time_stamp) print("frrtest_log_file..", frrtest_log_file) - logger = logger_config.get_logger(name="test_execution_logs", - log_level=loglevel, - target=frrtest_log_file) + logger = logger_config.get_logger( + name="test_execution_logs", log_level=loglevel, target=frrtest_log_file + ) print("Logs will be sent to logfile: {}".format(frrtest_log_file)) if config.has_option("topogen", "show_router_config"): @@ -94,10 +94,7 @@ ADDRESS_TYPES = os.environ.get("ADDRESS_TYPES") # Saves sequence id numbers -SEQ_ID = { - "prefix_lists": {}, - "route_maps": {} -} +SEQ_ID = {"prefix_lists": {}, "route_maps": {}} def get_seq_id(obj_type, router, obj_name): @@ -145,6 +142,7 @@ def set_seq_id(obj_type, router, id, obj_name): class InvalidCLIError(Exception): """Raise when the CLI command is wrong""" + pass @@ -169,16 +167,19 @@ def run_frr_cmd(rnode, cmd, isjson=False): else: print_data = ret_data - logger.info('Output for command [ %s] on router %s:\n%s', - cmd.rstrip("json"), rnode.name, print_data) + logger.info( + "Output for command [ %s] on router %s:\n%s", + cmd.rstrip("json"), + rnode.name, + print_data, + ) return ret_data else: - raise InvalidCLIError('No actual cmd passed') + raise InvalidCLIError("No actual cmd passed") -def create_common_configuration(tgen, router, data, config_type=None, - build=False): +def create_common_configuration(tgen, router, data, config_type=None, build=False): """ API to create object of class FRRConfig and also create frr_json.conf file. It will create interface and common configurations and save it to @@ -201,15 +202,17 @@ def create_common_configuration(tgen, router, data, config_type=None, fname = "{}/{}/{}".format(TMPDIR, router, FRRCFG_FILE) - config_map = OrderedDict({ - "general_config": "! FRR General Config\n", - "interface_config": "! Interfaces Config\n", - "static_route": "! Static Route Config\n", - "prefix_list": "! Prefix List Config\n", - "bgp_community_list": "! Community List Config\n", - "route_maps": "! Route Maps Config\n", - "bgp": "! BGP Config\n" - }) + config_map = OrderedDict( + { + "general_config": "! FRR General Config\n", + "interface_config": "! Interfaces Config\n", + "static_route": "! Static Route Config\n", + "prefix_list": "! Prefix List Config\n", + "bgp_community_list": "! Community List Config\n", + "route_maps": "! Route Maps Config\n", + "bgp": "! BGP Config\n", + } + ) if build: mode = "a" @@ -225,8 +228,9 @@ def create_common_configuration(tgen, router, data, config_type=None, frr_cfg_fd.write("\n") except IOError as err: - logger.error("Unable to open FRR Config File. error(%s): %s" % - (err.errno, err.strerror)) + logger.error( + "Unable to open FRR Config File. error(%s): %s" % (err.errno, err.strerror) + ) return False finally: frr_cfg_fd.close() @@ -257,8 +261,7 @@ def reset_config_on_routers(tgen, routerName=None): continue router = router_list[rname] - logger.info("Configuring router %s to initial test configuration", - rname) + logger.info("Configuring router %s to initial test configuration", rname) cfg = router.run("vtysh -c 'show running'") fname = "{}/{}/frr.sav".format(TMPDIR, rname) dname = "{}/{}/delta.conf".format(TMPDIR, rname) @@ -266,9 +269,11 @@ def reset_config_on_routers(tgen, routerName=None): for line in cfg.split("\n"): line = line.strip() - if (line == "Building configuration..." or - line == "Current configuration:" or - not line): + if ( + line == "Building configuration..." + or line == "Current configuration:" + or not line + ): continue f.write(line) f.write("\n") @@ -279,37 +284,39 @@ def reset_config_on_routers(tgen, routerName=None): init_cfg_file = "{}/{}/frr_json_initial.conf".format(TMPDIR, rname) tempdir = mkdtemp() - with open(os.path.join(tempdir, 'vtysh.conf'), 'w') as fd: + with open(os.path.join(tempdir, "vtysh.conf"), "w") as fd: pass - command = "/usr/lib/frr/frr-reload.py --confdir {} --input {} --test {} > {}". \ - format(tempdir, run_cfg_file, init_cfg_file, dname) - result = call(command, shell=True, stderr=SUB_STDOUT, - stdout=SUB_PIPE) + command = "/usr/lib/frr/frr-reload.py --confdir {} --input {} --test {} > {}".format( + tempdir, run_cfg_file, init_cfg_file, dname + ) + result = call(command, shell=True, stderr=SUB_STDOUT, stdout=SUB_PIPE) - os.unlink(os.path.join(tempdir, 'vtysh.conf')) + os.unlink(os.path.join(tempdir, "vtysh.conf")) os.rmdir(tempdir) # Assert if command fail if result > 0: - logger.error("Delta file creation failed. Command executed %s", - command) - with open(run_cfg_file, 'r') as fd: - logger.info('Running configuration saved in %s is:\n%s', - run_cfg_file, fd.read()) - with open(init_cfg_file, 'r') as fd: - logger.info('Test configuration saved in %s is:\n%s', - init_cfg_file, fd.read()) + logger.error("Delta file creation failed. Command executed %s", command) + with open(run_cfg_file, "r") as fd: + logger.info( + "Running configuration saved in %s is:\n%s", run_cfg_file, fd.read() + ) + with open(init_cfg_file, "r") as fd: + logger.info( + "Test configuration saved in %s is:\n%s", init_cfg_file, fd.read() + ) - err_cmd = ['/usr/bin/vtysh', '-m', '-f', run_cfg_file] + err_cmd = ["/usr/bin/vtysh", "-m", "-f", run_cfg_file] result = Popen(err_cmd, stdout=SUB_PIPE, stderr=SUB_PIPE) output = result.communicate() for out_data in output: - temp_data = out_data.decode('utf-8').lower() + temp_data = out_data.decode("utf-8").lower() for out_err in ERROR_LIST: if out_err.lower() in temp_data: - logger.error("Found errors while validating data in" - " %s", run_cfg_file) + logger.error( + "Found errors while validating data in" " %s", run_cfg_file + ) raise InvalidCLIError(out_data) raise InvalidCLIError("Unknown error in %s", output) @@ -319,18 +326,19 @@ def reset_config_on_routers(tgen, routerName=None): t_delta = f.read() for line in t_delta.split("\n"): line = line.strip() - if (line == "Lines To Delete" or - line == "===============" or - line == "Lines To Add" or - line == "============" or - not line): + if ( + line == "Lines To Delete" + or line == "===============" + or line == "Lines To Add" + or line == "============" + or not line + ): continue delta.write(line) delta.write("\n") delta.write("end\n") - output = router.vtysh_multicmd(delta.getvalue(), - pretty_output=False) + output = router.vtysh_multicmd(delta.getvalue(), pretty_output=False) delta.close() delta = StringIO.StringIO() @@ -343,8 +351,7 @@ def reset_config_on_routers(tgen, routerName=None): # Router current configuration to log file or console if # "show_router_config" is defined in "pytest.ini" if show_router_config: - logger.info("Configuration on router {} after config reset:". - format(rname)) + logger.info("Configuration on router {} after config reset:".format(rname)) logger.info(delta.getvalue()) delta.close() @@ -373,12 +380,13 @@ def load_config_to_router(tgen, routerName, save_bkup=False): router = router_list[rname] try: frr_cfg_file = "{}/{}/{}".format(TMPDIR, rname, FRRCFG_FILE) - frr_cfg_bkup = "{}/{}/{}".format(TMPDIR, rname, - FRRCFG_BKUP_FILE) + frr_cfg_bkup = "{}/{}/{}".format(TMPDIR, rname, FRRCFG_BKUP_FILE) with open(frr_cfg_file, "r+") as cfg: data = cfg.read() - logger.info("Applying following configuration on router" - " {}:\n{}".format(rname, data)) + logger.info( + "Applying following configuration on router" + " {}:\n{}".format(rname, data) + ) if save_bkup: with open(frr_cfg_bkup, "w") as bkup: bkup.write(data) @@ -390,8 +398,10 @@ def load_config_to_router(tgen, routerName, save_bkup=False): cfg.truncate(0) except IOError as err: - errormsg = ("Unable to open config File. error(%s):" - " %s", (err.errno, err.strerror)) + errormsg = ( + "Unable to open config File. error(%s):" " %s", + (err.errno, err.strerror), + ) return errormsg # Router current configuration to log file or console if @@ -418,8 +428,9 @@ def start_topology(tgen): # Starting deamons router_list = tgen.routers() - ROUTER_LIST = sorted(router_list.keys(), - key=lambda x: int(re_search('\d+', x).group(0))) + ROUTER_LIST = sorted( + router_list.keys(), key=lambda x: int(re_search("\d+", x).group(0)) + ) TMPDIR = os.path.join(LOGDIR, tgen.modname) router_list = tgen.routers() @@ -430,31 +441,27 @@ def start_topology(tgen): # Creating router named dir and empty zebra.conf bgpd.conf files # inside the current directory - if os.path.isdir('{}'.format(rname)): + if os.path.isdir("{}".format(rname)): os.system("rm -rf {}".format(rname)) - os.mkdir('{}'.format(rname)) - os.system('chmod -R go+rw {}'.format(rname)) - os.chdir('{}/{}'.format(TMPDIR, rname)) - os.system('touch zebra.conf bgpd.conf') + os.mkdir("{}".format(rname)) + os.system("chmod -R go+rw {}".format(rname)) + os.chdir("{}/{}".format(TMPDIR, rname)) + os.system("touch zebra.conf bgpd.conf") else: - os.mkdir('{}'.format(rname)) - os.system('chmod -R go+rw {}'.format(rname)) - os.chdir('{}/{}'.format(TMPDIR, rname)) - os.system('touch zebra.conf bgpd.conf') + os.mkdir("{}".format(rname)) + os.system("chmod -R go+rw {}".format(rname)) + os.chdir("{}/{}".format(TMPDIR, rname)) + os.system("touch zebra.conf bgpd.conf") except IOError as (errno, strerror): logger.error("I/O error({0}): {1}".format(errno, strerror)) # Loading empty zebra.conf file to router, to start the zebra deamon router.load_config( - TopoRouter.RD_ZEBRA, - '{}/{}/zebra.conf'.format(TMPDIR, rname) + TopoRouter.RD_ZEBRA, "{}/{}/zebra.conf".format(TMPDIR, rname) ) # Loading empty bgpd.conf file to router, to start the bgp deamon - router.load_config( - TopoRouter.RD_BGP, - '{}/{}/bgpd.conf'.format(TMPDIR, rname) - ) + router.load_config(TopoRouter.RD_BGP, "{}/{}/bgpd.conf".format(TMPDIR, rname)) # Starting routers logger.info("Starting all routers once topology is created") @@ -483,6 +490,7 @@ def number_to_column(routerName): # Common APIs, will be used by all protocols ############################################# + def validate_ip_address(ip_address): """ Validates the type of ip address @@ -518,8 +526,9 @@ def validate_ip_address(ip_address): return "ipv6" if not v4 and not v6: - raise Exception("InvalidIpAddr", "%s is neither valid IPv4 or IPv6" - " address" % ip_address) + raise Exception( + "InvalidIpAddr", "%s is neither valid IPv4 or IPv6" " address" % ip_address + ) def check_address_types(addr_type=None): @@ -542,8 +551,11 @@ def check_address_types(addr_type=None): return addr_types if addr_type not in addr_types: - logger.error("{} not in supported/configured address types {}". - format(addr_type, addr_types)) + logger.error( + "{} not in supported/configured address types {}".format( + addr_type, addr_types + ) + ) return False return True @@ -589,8 +601,7 @@ def generate_ips(network, no_of_ips): return ipaddress_list -def find_interface_with_greater_ip(topo, router, loopback=True, - interface=True): +def find_interface_with_greater_ip(topo, router, loopback=True, interface=True): """ Returns highest interface ip for ipv4/ipv6. If loopback is there then it will return highest IP from loopback IPs otherwise from physical @@ -608,12 +619,14 @@ def find_interface_with_greater_ip(topo, router, loopback=True, if loopback: if "type" in data and data["type"] == "loopback": lo_exists = True - ip_address = topo["routers"][router]["links"][ - destRouterLink]["ipv4"].split("/")[0] + ip_address = topo["routers"][router]["links"][destRouterLink][ + "ipv4" + ].split("/")[0] lo_list.append(ip_address) if interface: - ip_address = topo["routers"][router]["links"][ - destRouterLink]["ipv4"].split("/")[0] + ip_address = topo["routers"][router]["links"][destRouterLink]["ipv4"].split( + "/" + )[0] interfaces_list.append(ip_address) if lo_exists: @@ -625,17 +638,17 @@ def find_interface_with_greater_ip(topo, router, loopback=True, def write_test_header(tc_name): """ Display message at beginning of test case""" count = 20 - logger.info("*"*(len(tc_name)+count)) + logger.info("*" * (len(tc_name) + count)) step("START -> Testcase : %s" % tc_name, reset=True) - logger.info("*"*(len(tc_name)+count)) + logger.info("*" * (len(tc_name) + count)) def write_test_footer(tc_name): """ Display message at end of test case""" count = 21 - logger.info("="*(len(tc_name)+count)) + logger.info("=" * (len(tc_name) + count)) logger.info("Testcase : %s -> PASSED", tc_name) - logger.info("="*(len(tc_name)+count)) + logger.info("=" * (len(tc_name) + count)) def interface_status(tgen, topo, input_dict): @@ -664,8 +677,8 @@ def interface_status(tgen, topo, input_dict): global frr_cfg for router in input_dict.keys(): - interface_list = input_dict[router]['interface_list'] - status = input_dict[router].setdefault('status', 'up') + interface_list = input_dict[router]["interface_list"] + status = input_dict[router].setdefault("status", "up") for intf in interface_list: rnode = tgen.routers()[router] interface_set_status(rnode, intf, status) @@ -698,11 +711,10 @@ def retry(attempts=3, wait=2, return_is_str=True, initial_wait=0): """ def _retry(func): - @wraps(func) def func_retry(*args, **kwargs): - _wait = kwargs.pop('wait', wait) - _attempts = kwargs.pop('attempts', attempts) + _wait = kwargs.pop("wait", wait) + _attempts = kwargs.pop("attempts", attempts) _attempts = int(_attempts) if _attempts < 0: raise ValueError("attempts must be 0 or greater") @@ -711,11 +723,11 @@ def retry(attempts=3, wait=2, return_is_str=True, initial_wait=0): logger.info("Waiting for [%s]s as initial delay", initial_wait) sleep(initial_wait) - _return_is_str = kwargs.pop('return_is_str', return_is_str) + _return_is_str = kwargs.pop("return_is_str", return_is_str) for i in range(1, _attempts + 1): try: - _expected = kwargs.setdefault('expected', True) - kwargs.pop('expected') + _expected = kwargs.setdefault("expected", True) + kwargs.pop("expected") ret = func(*args, **kwargs) logger.debug("Function returned %s" % ret) if return_is_str and isinstance(ret, bool) and _expected: @@ -727,17 +739,17 @@ def retry(attempts=3, wait=2, return_is_str=True, initial_wait=0): return ret except Exception as err: if _attempts == i: - logger.info("Max number of attempts (%r) reached", - _attempts) + logger.info("Max number of attempts (%r) reached", _attempts) raise else: logger.info("Function returned %s", err) if i < _attempts: - logger.info("Retry [#%r] after sleeping for %ss" - % (i, _wait)) + logger.info("Retry [#%r] after sleeping for %ss" % (i, _wait)) sleep(_wait) + func_retry._original = func return func_retry + return _retry @@ -745,6 +757,7 @@ class Stepper: """ Prints step number for the test case step being executed """ + count = 1 def __call__(self, msg, reset): @@ -795,24 +808,17 @@ def create_interfaces_cfg(tgen, topo, build=False): interface_name = destRouterLink else: interface_name = data["interface"] - interface_data.append("interface {}".format( - str(interface_name) - )) + interface_data.append("interface {}".format(str(interface_name))) if "ipv4" in data: intf_addr = c_data["links"][destRouterLink]["ipv4"] - interface_data.append("ip address {}".format( - intf_addr - )) + interface_data.append("ip address {}".format(intf_addr)) if "ipv6" in data: intf_addr = c_data["links"][destRouterLink]["ipv6"] - interface_data.append("ipv6 address {}".format( - intf_addr - )) + interface_data.append("ipv6 address {}".format(intf_addr)) - result = create_common_configuration(tgen, c_router, - interface_data, - "interface_config", - build=build) + result = create_common_configuration( + tgen, c_router, interface_data, "interface_config", build=build + ) except InvalidCLIError: # Traceback errormsg = traceback.format_exc() @@ -880,13 +886,10 @@ def create_static_routes(tgen, input_dict, build=False): del_action = static_route.setdefault("delete", False) # No of IPs no_of_ip = static_route.setdefault("no_of_ip", 1) - admin_distance = static_route.setdefault("admin_distance", - None) + admin_distance = static_route.setdefault("admin_distance", None) tag = static_route.setdefault("tag", None) - if "next_hop" not in static_route or \ - "network" not in static_route: - errormsg = "'next_hop' or 'network' missing in" \ - " input_dict" + if "next_hop" not in static_route or "network" not in static_route: + errormsg = "'next_hop' or 'network' missing in" " input_dict" return errormsg next_hop = static_route["next_hop"] @@ -914,10 +917,9 @@ def create_static_routes(tgen, input_dict, build=False): static_routes_list.append(cmd) - result = create_common_configuration(tgen, router, - static_routes_list, - "static_route", - build=build) + result = create_common_configuration( + tgen, router, static_routes_list, "static_route", build=build + ) except InvalidCLIError: # Traceback @@ -992,10 +994,8 @@ def create_prefix_lists(tgen, input_dict, build=False): for prefix_name, prefix_list in prefix_data.iteritems(): for prefix_dict in prefix_list: - if "action" not in prefix_dict or \ - "network" not in prefix_dict: - errormsg = "'action' or network' missing in" \ - " input_dict" + if "action" not in prefix_dict or "network" not in prefix_dict: + errormsg = "'action' or network' missing in" " input_dict" return errormsg network_addr = prefix_dict["network"] @@ -1005,11 +1005,9 @@ def create_prefix_lists(tgen, input_dict, build=False): seqid = prefix_dict.setdefault("seqid", None) del_action = prefix_dict.setdefault("delete", False) if seqid is None: - seqid = get_seq_id("prefix_lists", router, - prefix_name) + seqid = get_seq_id("prefix_lists", router, prefix_name) else: - set_seq_id("prefix_lists", router, seqid, - prefix_name) + set_seq_id("prefix_lists", router, seqid, prefix_name) if addr_type == "ipv4": protocol = "ip" @@ -1028,10 +1026,9 @@ def create_prefix_lists(tgen, input_dict, build=False): cmd = "no {}".format(cmd) config_data.append(cmd) - result = create_common_configuration(tgen, router, - config_data, - "prefix_list", - build=build) + result = create_common_configuration( + tgen, router, config_data, "prefix_list", build=build + ) except InvalidCLIError: # Traceback @@ -1137,8 +1134,7 @@ def create_route_maps(tgen, input_dict, build=False): logger.debug("route_maps not present in input_dict") continue rmap_data = [] - for rmap_name, rmap_value in \ - input_dict[router]["route_maps"].iteritems(): + for rmap_name, rmap_value in input_dict[router]["route_maps"].iteritems(): for rmap_dict in rmap_value: del_action = rmap_dict.setdefault("delete", False) @@ -1160,38 +1156,39 @@ def create_route_maps(tgen, input_dict, build=False): else: set_seq_id("route_maps", router, seq_id, rmap_name) - rmap_data.append("route-map {} {} {}".format( - rmap_name, rmap_action, seq_id - )) + rmap_data.append( + "route-map {} {} {}".format(rmap_name, rmap_action, seq_id) + ) if "continue" in rmap_dict: continue_to = rmap_dict["continue"] if continue_to: - rmap_data.append("on-match goto {}". - format(continue_to)) + rmap_data.append("on-match goto {}".format(continue_to)) else: - logger.error("In continue, 'route-map entry " - "sequence number' is not provided") + logger.error( + "In continue, 'route-map entry " + "sequence number' is not provided" + ) return False if "goto" in rmap_dict: go_to = rmap_dict["goto"] if go_to: - rmap_data.append("on-match goto {}". - format(go_to)) + rmap_data.append("on-match goto {}".format(go_to)) else: - logger.error("In goto, 'Goto Clause number' is not" - " provided") + logger.error( + "In goto, 'Goto Clause number' is not" " provided" + ) return False if "call" in rmap_dict: call_rmap = rmap_dict["call"] if call_rmap: - rmap_data.append("call {}". - format(call_rmap)) + rmap_data.append("call {}".format(call_rmap)) else: - logger.error("In call, 'destination Route-Map' is" - " not provided") + logger.error( + "In call, 'destination Route-Map' is" " not provided" + ) return False # Verifying if SET criteria is defined @@ -1199,24 +1196,22 @@ def create_route_maps(tgen, input_dict, build=False): set_data = rmap_dict["set"] ipv4_data = set_data.setdefault("ipv4", {}) ipv6_data = set_data.setdefault("ipv6", {}) - local_preference = set_data.setdefault("locPrf", - None) + local_preference = set_data.setdefault("locPrf", None) metric = set_data.setdefault("metric", None) as_path = set_data.setdefault("path", {}) weight = set_data.setdefault("weight", None) community = set_data.setdefault("community", {}) - large_community = set_data.setdefault( - "large_community", {}) - large_comm_list = set_data.setdefault( - "large_comm_list", {}) + large_community = set_data.setdefault("large_community", {}) + large_comm_list = set_data.setdefault("large_comm_list", {}) set_action = set_data.setdefault("set_action", None) nexthop = set_data.setdefault("nexthop", None) origin = set_data.setdefault("origin", None) # Local Preference if local_preference: - rmap_data.append("set local-preference {}". - format(local_preference)) + rmap_data.append( + "set local-preference {}".format(local_preference) + ) # Metric if metric: @@ -1231,8 +1226,9 @@ def create_route_maps(tgen, input_dict, build=False): as_num = as_path.setdefault("as_num", None) as_action = as_path.setdefault("as_action", None) if as_action and as_num: - rmap_data.append("set as-path {} {}". - format(as_action, as_num)) + rmap_data.append( + "set as-path {} {}".format(as_action, as_num) + ) # Community if community: @@ -1244,14 +1240,12 @@ def create_route_maps(tgen, input_dict, build=False): cmd = "{} {}".format(cmd, comm_action) rmap_data.append(cmd) else: - logger.error("In community, AS Num not" - " provided") + logger.error("In community, AS Num not" " provided") return False if large_community: num = large_community.setdefault("num", None) - comm_action = large_community.setdefault("action", - None) + comm_action = large_community.setdefault("action", None) if num: cmd = "set large-community {}".format(num) if comm_action: @@ -1259,13 +1253,13 @@ def create_route_maps(tgen, input_dict, build=False): rmap_data.append(cmd) else: - logger.error("In large_community, AS Num not" - " provided") + logger.error( + "In large_community, AS Num not" " provided" + ) return False if large_comm_list: id = large_comm_list.setdefault("id", None) - del_comm = large_comm_list.setdefault("delete", - None) + del_comm = large_comm_list.setdefault("delete", None) if id: cmd = "set large-comm-list {}".format(id) if del_comm: @@ -1273,43 +1267,36 @@ def create_route_maps(tgen, input_dict, build=False): rmap_data.append(cmd) else: - logger.error("In large_comm_list 'id' not" - " provided") + logger.error("In large_comm_list 'id' not" " provided") return False # Weight if weight: - rmap_data.append("set weight {}".format( - weight)) + rmap_data.append("set weight {}".format(weight)) if ipv6_data: nexthop = ipv6_data.setdefault("nexthop", None) if nexthop: - rmap_data.append("set ipv6 next-hop {}".format( - nexthop - )) + rmap_data.append("set ipv6 next-hop {}".format(nexthop)) # Adding MATCH and SET sequence to RMAP if defined if "match" in rmap_dict: match_data = rmap_dict["match"] ipv4_data = match_data.setdefault("ipv4", {}) ipv6_data = match_data.setdefault("ipv6", {}) - community = match_data.setdefault( - "community_list",{}) - large_community = match_data.setdefault( - "large_community", {} - ) + community = match_data.setdefault("community_list", {}) + large_community = match_data.setdefault("large_community", {}) large_community_list = match_data.setdefault( "large_community_list", {} ) if ipv4_data: # fetch prefix list data from rmap - prefix_name = \ - ipv4_data.setdefault("prefix_lists", - None) + prefix_name = ipv4_data.setdefault("prefix_lists", None) if prefix_name: - rmap_data.append("match ip address" - " prefix-list {}".format(prefix_name)) + rmap_data.append( + "match ip address" + " prefix-list {}".format(prefix_name) + ) # fetch tag data from rmap tag = ipv4_data.setdefault("tag", None) @@ -1318,16 +1305,19 @@ def create_route_maps(tgen, input_dict, build=False): # fetch large community data from rmap large_community_list = ipv4_data.setdefault( - "large_community_list",{}) + "large_community_list", {} + ) large_community = match_data.setdefault( - "large_community", {}) + "large_community", {} + ) if ipv6_data: - prefix_name = ipv6_data.setdefault("prefix_lists", - None) + prefix_name = ipv6_data.setdefault("prefix_lists", None) if prefix_name: - rmap_data.append("match ipv6 address" - " prefix-list {}".format(prefix_name)) + rmap_data.append( + "match ipv6 address" + " prefix-list {}".format(prefix_name) + ) # fetch tag data from rmap tag = ipv6_data.setdefault("tag", None) @@ -1336,54 +1326,64 @@ def create_route_maps(tgen, input_dict, build=False): # fetch large community data from rmap large_community_list = ipv6_data.setdefault( - "large_community_list",{}) + "large_community_list", {} + ) large_community = match_data.setdefault( - "large_community", {}) + "large_community", {} + ) if community: if "id" not in community: - logger.error("'id' is mandatory for " - "community-list in match" - " criteria") + logger.error( + "'id' is mandatory for " + "community-list in match" + " criteria" + ) return False cmd = "match community {}".format(community["id"]) - exact_match = community.setdefault("exact_match", - False) + exact_match = community.setdefault("exact_match", False) if exact_match: cmd = "{} exact-match".format(cmd) rmap_data.append(cmd) if large_community: if "id" not in large_community: - logger.error("'id' is mandatory for " - "large-community-list in match " - "criteria") + logger.error( + "'id' is mandatory for " + "large-community-list in match " + "criteria" + ) return False cmd = "match large-community {}".format( - large_community["id"]) + large_community["id"] + ) exact_match = large_community.setdefault( - "exact_match", False) + "exact_match", False + ) if exact_match: cmd = "{} exact-match".format(cmd) rmap_data.append(cmd) if large_community_list: if "id" not in large_community_list: - logger.error("'id' is mandatory for " - "large-community-list in match " - "criteria") + logger.error( + "'id' is mandatory for " + "large-community-list in match " + "criteria" + ) return False cmd = "match large-community {}".format( - large_community_list["id"]) + large_community_list["id"] + ) exact_match = large_community_list.setdefault( - "exact_match", False) + "exact_match", False + ) if exact_match: cmd = "{} exact-match".format(cmd) rmap_data.append(cmd) - result = create_common_configuration(tgen, router, - rmap_data, - "route_maps", - build=build) + result = create_common_configuration( + tgen, router, rmap_data, "route_maps", build=build + ) except InvalidCLIError: # Traceback @@ -1424,12 +1424,7 @@ def delete_route_maps(tgen, input_dict): rmap_data = input_dict[router] rmap_data["route_maps"] = {} for route_map_name in route_maps: - rmap_data["route_maps"].update({ - route_map_name: - [{ - "delete": True - }] - }) + rmap_data["route_maps"].update({route_map_name: [{"delete": True}]}) return create_route_maps(tgen, input_dict) @@ -1478,10 +1473,9 @@ def create_bgp_community_lists(tgen, input_dict, build=False): community_list = input_dict[router]["bgp_community_lists"] for community_dict in community_list: del_action = community_dict.setdefault("delete", False) - community_type = community_dict.setdefault("community_type", - None) + community_type = community_dict.setdefault("community_type", None) action = community_dict.setdefault("action", None) - value = community_dict.setdefault("value", '') + value = community_dict.setdefault("value", "") large = community_dict.setdefault("large", None) name = community_dict.setdefault("name", None) if large: @@ -1490,28 +1484,30 @@ def create_bgp_community_lists(tgen, input_dict, build=False): cmd = "bgp community-list" if not large and not (community_type and action and value): - errormsg = "community_type, action and value are " \ - "required in bgp_community_list" + errormsg = ( + "community_type, action and value are " + "required in bgp_community_list" + ) logger.error(errormsg) return False try: community_type = int(community_type) - cmd = "{} {} {} {}".format(cmd, community_type, action, - value) + cmd = "{} {} {} {}".format(cmd, community_type, action, value) except ValueError: cmd = "{} {} {} {} {}".format( - cmd, community_type, name, action, value) + cmd, community_type, name, action, value + ) if del_action: cmd = "no {}".format(cmd) config_data.append(cmd) - result = create_common_configuration(tgen, router, config_data, - "bgp_community_list", - build=build) + result = create_common_configuration( + tgen, router, config_data, "bgp_community_list", build=build + ) except InvalidCLIError: # Traceback @@ -1634,8 +1630,9 @@ def verify_rib(tgen, addr_type, dut, input_dict, next_hop=None, protocol=None): # Verifying output dictionary rib_routes_json is not empty if bool(rib_routes_json) is False: - errormsg = "No {} route found in rib of router {}..". \ - format(protocol, router) + errormsg = "No {} route found in rib of router {}..".format( + protocol, router + ) return errormsg if "static_routes" in input_dict[routerInput]: @@ -1665,47 +1662,62 @@ def verify_rib(tgen, addr_type, dut, input_dict, next_hop=None, protocol=None): if type(next_hop) is not list: next_hop = [next_hop] - found_hops = [rib_r["ip"] for rib_r in - rib_routes_json[st_rt][0][ - "nexthops"]] + found_hops = [ + rib_r["ip"] + for rib_r in rib_routes_json[st_rt][0]["nexthops"] + ] for nh in found_hops: nh_found = False if nh and nh in next_hop: nh_found = True else: - errormsg = ("Nexthop {} is Missing for {}" - " route {} in RIB of router" - " {}\n".format(next_hop, - protocol, - st_rt, dut)) + errormsg = ( + "Nexthop {} is Missing for {}" + " route {} in RIB of router" + " {}\n".format( + next_hop, protocol, st_rt, dut + ) + ) return errormsg else: missing_routes.append(st_rt) if nh_found: - logger.info("Found next_hop %s for all routes in RIB of" - " router %s\n", next_hop, dut) + logger.info( + "Found next_hop %s for all routes in RIB of" " router %s\n", + next_hop, + dut, + ) if not st_found and len(missing_routes) > 0: - errormsg = "Missing route in RIB of router {}, routes: " \ - "{}\n".format(dut, missing_routes) + errormsg = ( + "Missing route in RIB of router {}, routes: " + "{}\n".format(dut, missing_routes) + ) return errormsg - logger.info("Verified routes in router %s RIB, found routes" - " are: %s\n", dut, found_routes) + logger.info( + "Verified routes in router %s RIB, found routes" " are: %s\n", + dut, + found_routes, + ) continue if "bgp" in input_dict[routerInput]: - if 'advertise_networks' in input_dict[routerInput]["bgp"]\ - ["address_family"][addr_type]["unicast"]: + if ( + "advertise_networks" + in input_dict[routerInput]["bgp"]["address_family"][addr_type][ + "unicast" + ] + ): found_routes = [] missing_routes = [] - advertise_network = input_dict[routerInput]["bgp"]\ - ["address_family"][addr_type]["unicast"]\ - ["advertise_networks"] + advertise_network = input_dict[routerInput]["bgp"][ + "address_family" + ][addr_type]["unicast"]["advertise_networks"] for advertise_network_dict in advertise_network: start_ip = advertise_network_dict["network"] @@ -1730,34 +1742,43 @@ def verify_rib(tgen, addr_type, dut, input_dict, next_hop=None, protocol=None): next_hop = [next_hop] for index, nh in enumerate(next_hop): - if rib_routes_json[st_rt][0]\ - ['nexthops'][index]['ip'] == nh: + if ( + rib_routes_json[st_rt][0]["nexthops"][ + index + ]["ip"] + == nh + ): nh_found = True else: - errormsg=("Nexthop {} is Missing" - " for {} route {} in " - "RIB of router {}\n".\ - format(next_hop, - protocol, - st_rt, dut)) + errormsg = ( + "Nexthop {} is Missing" + " for {} route {} in " + "RIB of router {}\n".format( + next_hop, protocol, st_rt, dut + ) + ) return errormsg else: missing_routes.append(st_rt) if nh_found: - logger.info("Found next_hop {} for all routes in RIB" - " of router {}\n".format(next_hop, dut)) + logger.info( + "Found next_hop {} for all routes in RIB" + " of router {}\n".format(next_hop, dut) + ) if not found and len(missing_routes) > 0: - errormsg = ("Missing {} route in RIB of router {}, " - "routes: {} \n".\ - format(addr_type, dut, missing_routes)) + errormsg = ( + "Missing {} route in RIB of router {}, " + "routes: {} \n".format(addr_type, dut, missing_routes) + ) return errormsg - logger.info("Verified {} routes in router {} RIB, found" - " routes are: {}\n".\ - format(addr_type, dut, found_routes)) + logger.info( + "Verified {} routes in router {} RIB, found" + " routes are: {}\n".format(addr_type, dut, found_routes) + ) logger.debug("Exiting lib API: verify_rib()") return True @@ -1810,8 +1831,11 @@ def verify_admin_distance_for_static_routes(tgen, input_dict): command = "show ipv6 route json" show_ip_route_json = run_frr_cmd(rnode, command, isjson=True) - logger.info("Verifying admin distance for static route %s" - " under dut %s:", static_route, router) + logger.info( + "Verifying admin distance for static route %s" " under dut %s:", + static_route, + router, + ) network = static_route["network"] next_hop = static_route["next_hop"] admin_distance = static_route["admin_distance"] @@ -1819,23 +1843,32 @@ def verify_admin_distance_for_static_routes(tgen, input_dict): if network in show_ip_route_json: if route_data["nexthops"][0]["ip"] == next_hop: if route_data["distance"] != admin_distance: - errormsg = ("Verification failed: admin distance" - " for static route {} under dut {}," - " found:{} but expected:{}". - format(static_route, router, - route_data["distance"], - admin_distance)) + errormsg = ( + "Verification failed: admin distance" + " for static route {} under dut {}," + " found:{} but expected:{}".format( + static_route, + router, + route_data["distance"], + admin_distance, + ) + ) return errormsg else: - logger.info("Verification successful: admin" - " distance for static route %s under" - " dut %s, found:%s", static_route, - router, route_data["distance"]) + logger.info( + "Verification successful: admin" + " distance for static route %s under" + " dut %s, found:%s", + static_route, + router, + route_data["distance"], + ) else: - errormsg = ("Static route {} not found in " - "show_ip_route_json for dut {}". - format(network, router)) + errormsg = ( + "Static route {} not found in " + "show_ip_route_json for dut {}".format(network, router) + ) return errormsg logger.debug("Exiting lib API: verify_admin_distance_for_static_routes()") @@ -1885,12 +1918,17 @@ def verify_prefix_lists(tgen, input_dict): for prefix_list in prefix_lists_addr[addr_type].keys(): if prefix_list in show_prefix_list: - errormsg = ("Prefix list {} is/are present in the router" - " {}".format(prefix_list, router)) + errormsg = ( + "Prefix list {} is/are present in the router" + " {}".format(prefix_list, router) + ) return errormsg - logger.info("Prefix list %s is/are not present in the router" - " from router %s", prefix_list, router) + logger.info( + "Prefix list %s is/are not present in the router" " from router %s", + prefix_list, + router, + ) logger.debug("Exiting lib API: verify_prefix_lists()") return True @@ -1933,12 +1971,16 @@ def verify_route_maps(tgen, input_dict): route_maps = input_dict[router]["route_maps"] for route_map in route_maps: if route_map in show_route_maps: - errormsg = ("Route map {} is not deleted from router" - " {}".format(route_map, router)) + errormsg = "Route map {} is not deleted from router" " {}".format( + route_map, router + ) return errormsg - logger.info("Route map %s is/are deleted successfully from" - " router %s", route_maps, router) + logger.info( + "Route map %s is/are deleted successfully from" " router %s", + route_maps, + router, + ) logger.debug("Exiting lib API: verify_route_maps()") return True @@ -1977,47 +2019,60 @@ def verify_bgp_community(tgen, addr_type, router, network, input_dict=None): rnode = tgen.routers()[router] - logger.debug("Verifying BGP community attributes on dut %s: for %s " - "network %s", router, addr_type, network) + logger.debug( + "Verifying BGP community attributes on dut %s: for %s " "network %s", + router, + addr_type, + network, + ) for net in network: cmd = "show bgp {} {} json".format(addr_type, net) show_bgp_json = rnode.vtysh_cmd(cmd, isjson=True) logger.info(show_bgp_json) if "paths" not in show_bgp_json: - return "Prefix {} not found in BGP table of router: {}". \ - format(net, router) + return "Prefix {} not found in BGP table of router: {}".format(net, router) as_paths = show_bgp_json["paths"] found = False for i in range(len(as_paths)): - if "largeCommunity" in show_bgp_json["paths"][i] or \ - "community" in show_bgp_json["paths"][i]: + if ( + "largeCommunity" in show_bgp_json["paths"][i] + or "community" in show_bgp_json["paths"][i] + ): found = True - logger.info("Large Community attribute is found for route:" - " %s in router: %s", net, router) + logger.info( + "Large Community attribute is found for route:" " %s in router: %s", + net, + router, + ) if input_dict is not None: for criteria, comm_val in input_dict.items(): - show_val = show_bgp_json["paths"][i][criteria][ - "string"] + show_val = show_bgp_json["paths"][i][criteria]["string"] if comm_val == show_val: - logger.info("Verifying BGP %s for prefix: %s" - " in router: %s, found expected" - " value: %s", criteria, net, router, - comm_val) + logger.info( + "Verifying BGP %s for prefix: %s" + " in router: %s, found expected" + " value: %s", + criteria, + net, + router, + comm_val, + ) else: - errormsg = "Failed: Verifying BGP attribute" \ - " {} for route: {} in router: {}" \ - ", expected value: {} but found" \ - ": {}".format( - criteria, net, router, comm_val, - show_val) + errormsg = ( + "Failed: Verifying BGP attribute" + " {} for route: {} in router: {}" + ", expected value: {} but found" + ": {}".format(criteria, net, router, comm_val, show_val) + ) return errormsg if not found: errormsg = ( "Large Community attribute is not found for route: " - "{} in router: {} ".format(net, router)) + "{} in router: {} ".format(net, router) + ) return errormsg logger.debug("Exiting lib API: verify_bgp_community()") @@ -2057,25 +2112,24 @@ def verify_create_community_list(tgen, input_dict): rnode = tgen.routers()[router] - logger.info("Verifying large-community is created for dut %s:", - router) + logger.info("Verifying large-community is created for dut %s:", router) for comm_data in input_dict[router]["bgp_community_lists"]: comm_name = comm_data["name"] comm_type = comm_data["community_type"] - show_bgp_community = \ - run_frr_cmd(rnode, - "show bgp large-community-list {} detail". - format(comm_name)) + show_bgp_community = run_frr_cmd( + rnode, "show bgp large-community-list {} detail".format(comm_name) + ) # Verify community list and type - if comm_name in show_bgp_community and comm_type in \ - show_bgp_community: - logger.info("BGP %s large-community-list %s is" - " created", comm_type, comm_name) + if comm_name in show_bgp_community and comm_type in show_bgp_community: + logger.info( + "BGP %s large-community-list %s is" " created", comm_type, comm_name + ) else: - errormsg = "BGP {} large-community-list {} is not" \ - " created".format(comm_type, comm_name) + errormsg = "BGP {} large-community-list {} is not" " created".format( + comm_type, comm_name + ) return errormsg logger.debug("Exiting lib API: verify_create_community_list()") diff --git a/tests/topotests/lib/test/test_json.py b/tests/topotests/lib/test/test_json.py index 3927ba095d..ba118d607a 100755 --- a/tests/topotests/lib/test/test_json.py +++ b/tests/topotests/lib/test/test_json.py @@ -32,36 +32,37 @@ import pytest # Save the Current Working Directory to find lib files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../../')) +sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 from lib.topotest import json_cmp + def test_json_intersect_true(): "Test simple correct JSON intersections" dcomplete = { - 'i1': 'item1', - 'i2': 'item2', - 'i3': 'item3', - 'i100': 'item4', + "i1": "item1", + "i2": "item2", + "i3": "item3", + "i100": "item4", } dsub1 = { - 'i1': 'item1', - 'i3': 'item3', + "i1": "item1", + "i3": "item3", } dsub2 = { - 'i1': 'item1', - 'i2': 'item2', + "i1": "item1", + "i2": "item2", } dsub3 = { - 'i100': 'item4', - 'i2': 'item2', + "i100": "item4", + "i2": "item2", } dsub4 = { - 'i50': None, - 'i100': 'item4', + "i50": None, + "i100": "item4", } assert json_cmp(dcomplete, dsub1) is None @@ -69,99 +70,66 @@ def test_json_intersect_true(): assert json_cmp(dcomplete, dsub3) is None assert json_cmp(dcomplete, dsub4) is None + def test_json_intersect_false(): "Test simple incorrect JSON intersections" dcomplete = { - 'i1': 'item1', - 'i2': 'item2', - 'i3': 'item3', - 'i100': 'item4', + "i1": "item1", + "i2": "item2", + "i3": "item3", + "i100": "item4", } # Incorrect value for 'i1' dsub1 = { - 'i1': 'item3', - 'i3': 'item3', + "i1": "item3", + "i3": "item3", } # Non-existing key 'i5' dsub2 = { - 'i1': 'item1', - 'i5': 'item2', + "i1": "item1", + "i5": "item2", } # Key should not exist dsub3 = { - 'i100': None, + "i100": None, } assert json_cmp(dcomplete, dsub1) is not None assert json_cmp(dcomplete, dsub2) is not None assert json_cmp(dcomplete, dsub3) is not None + def test_json_intersect_multilevel_true(): "Test multi level correct JSON intersections" dcomplete = { - 'i1': 'item1', - 'i2': 'item2', - 'i3': { - 'i100': 'item100', + "i1": "item1", + "i2": "item2", + "i3": {"i100": "item100",}, + "i4": { + "i41": {"i411": "item411",}, + "i42": {"i421": "item421", "i422": "item422",}, }, - 'i4': { - 'i41': { - 'i411': 'item411', - }, - 'i42': { - 'i421': 'item421', - 'i422': 'item422', - } - } } dsub1 = { - 'i1': 'item1', - 'i3': { - 'i100': 'item100', - }, - 'i10': None, + "i1": "item1", + "i3": {"i100": "item100",}, + "i10": None, } dsub2 = { - 'i1': 'item1', - 'i2': 'item2', - 'i3': {}, + "i1": "item1", + "i2": "item2", + "i3": {}, } dsub3 = { - 'i2': 'item2', - 'i4': { - 'i41': { - 'i411': 'item411', - }, - 'i42': { - 'i422': 'item422', - 'i450': None, - } - } - } - dsub4 = { - 'i2': 'item2', - 'i4': { - 'i41': {}, - 'i42': { - 'i450': None, - } - } - } - dsub5 = { - 'i2': 'item2', - 'i3': { - 'i100': 'item100', - }, - 'i4': { - 'i42': { - 'i450': None, - } - } + "i2": "item2", + "i4": {"i41": {"i411": "item411",}, "i42": {"i422": "item422", "i450": None,}}, } + dsub4 = {"i2": "item2", "i4": {"i41": {}, "i42": {"i450": None,}}} + dsub5 = {"i2": "item2", "i3": {"i100": "item100",}, "i4": {"i42": {"i450": None,}}} assert json_cmp(dcomplete, dsub1) is None assert json_cmp(dcomplete, dsub2) is None @@ -169,78 +137,43 @@ def test_json_intersect_multilevel_true(): assert json_cmp(dcomplete, dsub4) is None assert json_cmp(dcomplete, dsub5) is None + def test_json_intersect_multilevel_false(): "Test multi level incorrect JSON intersections" dcomplete = { - 'i1': 'item1', - 'i2': 'item2', - 'i3': { - 'i100': 'item100', + "i1": "item1", + "i2": "item2", + "i3": {"i100": "item100",}, + "i4": { + "i41": {"i411": "item411",}, + "i42": {"i421": "item421", "i422": "item422",}, }, - 'i4': { - 'i41': { - 'i411': 'item411', - }, - 'i42': { - 'i421': 'item421', - 'i422': 'item422', - } - } } # Incorrect sub-level value dsub1 = { - 'i1': 'item1', - 'i3': { - 'i100': 'item00', - }, - 'i10': None, + "i1": "item1", + "i3": {"i100": "item00",}, + "i10": None, } # Inexistent sub-level dsub2 = { - 'i1': 'item1', - 'i2': 'item2', - 'i3': None, + "i1": "item1", + "i2": "item2", + "i3": None, } # Inexistent sub-level value dsub3 = { - 'i1': 'item1', - 'i3': { - 'i100': None, - }, + "i1": "item1", + "i3": {"i100": None,}, } # Inexistent sub-sub-level value - dsub4 = { - 'i4': { - 'i41': { - 'i412': 'item412', - }, - 'i42': { - 'i421': 'item421', - } - } - } + dsub4 = {"i4": {"i41": {"i412": "item412",}, "i42": {"i421": "item421",}}} # Invalid sub-sub-level value - dsub5 = { - 'i4': { - 'i41': { - 'i411': 'item411', - }, - 'i42': { - 'i421': 'item420000', - } - } - } + dsub5 = {"i4": {"i41": {"i411": "item411",}, "i42": {"i421": "item420000",}}} # sub-sub-level should be value - dsub6 = { - 'i4': { - 'i41': { - 'i411': 'item411', - }, - 'i42': 'foobar', - } - } + dsub6 = {"i4": {"i41": {"i411": "item411",}, "i42": "foobar",}} assert json_cmp(dcomplete, dsub1) is not None assert json_cmp(dcomplete, dsub2) is not None @@ -249,80 +182,54 @@ def test_json_intersect_multilevel_false(): assert json_cmp(dcomplete, dsub5) is not None assert json_cmp(dcomplete, dsub6) is not None + def test_json_with_list_sucess(): "Test successful json comparisons that have lists." dcomplete = { - 'list': [ - { - 'i1': 'item 1', - 'i2': 'item 2', - }, - { - 'i10': 'item 10', - }, - ], - 'i100': 'item 100', + "list": [{"i1": "item 1", "i2": "item 2",}, {"i10": "item 10",},], + "i100": "item 100", } # Test list type dsub1 = { - 'list': [], + "list": [], } # Test list correct list items dsub2 = { - 'list': [ - { - 'i1': 'item 1', - }, - ], - 'i100': 'item 100', + "list": [{"i1": "item 1",},], + "i100": "item 100", } # Test list correct list size dsub3 = { - 'list': [ - {}, {}, - ], + "list": [{}, {},], } assert json_cmp(dcomplete, dsub1) is None assert json_cmp(dcomplete, dsub2) is None assert json_cmp(dcomplete, dsub3) is None + def test_json_with_list_failure(): "Test failed json comparisons that have lists." dcomplete = { - 'list': [ - { - 'i1': 'item 1', - 'i2': 'item 2', - }, - { - 'i10': 'item 10', - }, - ], - 'i100': 'item 100', + "list": [{"i1": "item 1", "i2": "item 2",}, {"i10": "item 10",},], + "i100": "item 100", } # Test list type dsub1 = { - 'list': {}, + "list": {}, } # Test list incorrect list items dsub2 = { - 'list': [ - { - 'i1': 'item 2', - }, - ], - 'i100': 'item 100', + "list": [{"i1": "item 2",},], + "i100": "item 100", } # Test list correct list size dsub3 = { - 'list': [ - {}, {}, {}, - ], + "list": [{}, {}, {},], } assert json_cmp(dcomplete, dsub1) is not None @@ -334,53 +241,20 @@ def test_json_list_start_success(): "Test JSON encoded data that starts with a list that should succeed." dcomplete = [ - { - "id": 100, - "value": "abc", - }, - { - "id": 200, - "value": "abcd", - }, - { - "id": 300, - "value": "abcde", - }, + {"id": 100, "value": "abc",}, + {"id": 200, "value": "abcd",}, + {"id": 300, "value": "abcde",}, ] - dsub1 = [ - { - "id": 100, - "value": "abc", - } - ] + dsub1 = [{"id": 100, "value": "abc",}] - dsub2 = [ - { - "id": 100, - "value": "abc", - }, - { - "id": 200, - "value": "abcd", - } - ] + dsub2 = [{"id": 100, "value": "abc",}, {"id": 200, "value": "abcd",}] - dsub3 = [ - { - "id": 300, - "value": "abcde", - } - ] + dsub3 = [{"id": 300, "value": "abcde",}] - dsub4 = [ - ] + dsub4 = [] - dsub5 = [ - { - "id": 100, - } - ] + dsub5 = [{"id": 100,}] assert json_cmp(dcomplete, dsub1) is None assert json_cmp(dcomplete, dsub2) is None @@ -393,58 +267,18 @@ def test_json_list_start_failure(): "Test JSON encoded data that starts with a list that should fail." dcomplete = [ - { - "id": 100, - "value": "abc" - }, - { - "id": 200, - "value": "abcd" - }, - { - "id": 300, - "value": "abcde" - }, + {"id": 100, "value": "abc"}, + {"id": 200, "value": "abcd"}, + {"id": 300, "value": "abcde"}, ] - dsub1 = [ - { - "id": 100, - "value": "abcd", - } - ] + dsub1 = [{"id": 100, "value": "abcd",}] - dsub2 = [ - { - "id": 100, - "value": "abc", - }, - { - "id": 200, - "value": "abc", - } - ] + dsub2 = [{"id": 100, "value": "abc",}, {"id": 200, "value": "abc",}] - dsub3 = [ - { - "id": 100, - "value": "abc", - }, - { - "id": 350, - "value": "abcde", - } - ] + dsub3 = [{"id": 100, "value": "abc",}, {"id": 350, "value": "abcde",}] - dsub4 = [ - { - "value": "abcx", - }, - { - "id": 300, - "value": "abcde", - } - ] + dsub4 = [{"value": "abcx",}, {"id": 300, "value": "abcde",}] assert json_cmp(dcomplete, dsub1) is not None assert json_cmp(dcomplete, dsub2) is not None @@ -452,5 +286,5 @@ def test_json_list_start_failure(): assert json_cmp(dcomplete, dsub4) is not None -if __name__ == '__main__': +if __name__ == "__main__": sys.exit(pytest.main()) diff --git a/tests/topotests/lib/test/test_run_and_expect.py b/tests/topotests/lib/test/test_run_and_expect.py index 3c22c20e7b..d65d5baf37 100755 --- a/tests/topotests/lib/test/test_run_and_expect.py +++ b/tests/topotests/lib/test/test_run_and_expect.py @@ -32,11 +32,12 @@ import pytest # Save the Current Working Directory to find lib files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../../')) +sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 from lib.topotest import run_and_expect_type + def test_run_and_expect_type(): "Test basic `run_and_expect_type` functionality." @@ -45,12 +46,16 @@ def test_run_and_expect_type(): return True # Test value success. - success, value = run_and_expect_type(return_true, bool, count=1, wait=0, avalue=True) + success, value = run_and_expect_type( + return_true, bool, count=1, wait=0, avalue=True + ) assert success is True assert value is True # Test value failure. - success, value = run_and_expect_type(return_true, bool, count=1, wait=0, avalue=False) + success, value = run_and_expect_type( + return_true, bool, count=1, wait=0, avalue=False + ) assert success is False assert value is True @@ -70,5 +75,5 @@ def test_run_and_expect_type(): assert value is True -if __name__ == '__main__': +if __name__ == "__main__": sys.exit(pytest.main()) diff --git a/tests/topotests/lib/test/test_version.py b/tests/topotests/lib/test/test_version.py index 9204ac2084..7c2df00337 100755 --- a/tests/topotests/lib/test/test_version.py +++ b/tests/topotests/lib/test/test_version.py @@ -32,21 +32,22 @@ import pytest # Save the Current Working Directory to find lib files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../../')) +sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 from lib.topotest import version_cmp + def test_valid_versions(): "Test valid version compare results" - curver = '3.0' - samever = '3' - oldver = '2.0' - newver = '3.0.1' - newerver = '3.0.11' - vercustom = '3.0-dev' - verysmallinc = '3.0.0.0.0.0.0.1' + curver = "3.0" + samever = "3" + oldver = "2.0" + newver = "3.0.1" + newerver = "3.0.11" + vercustom = "3.0-dev" + verysmallinc = "3.0.0.0.0.0.0.1" assert version_cmp(curver, oldver) == 1 assert version_cmp(curver, newver) == -1 @@ -64,14 +65,15 @@ def test_valid_versions(): assert version_cmp(verysmallinc, verysmallinc) == 0 assert version_cmp(vercustom, verysmallinc) == -1 + def test_invalid_versions(): "Test invalid version strings" - curver = '3.0' - badver1 = '.1' - badver2 = '-1.0' - badver3 = '.' - badver4 = '3.-0.3' + curver = "3.0" + badver1 = ".1" + badver2 = "-1.0" + badver3 = "." + badver4 = "3.-0.3" with pytest.raises(ValueError): assert version_cmp(curver, badver1) @@ -79,9 +81,10 @@ def test_invalid_versions(): assert version_cmp(curver, badver3) assert version_cmp(curver, badver4) + def test_regression_1(): """ Test regression on the following type of comparison: '3.0.2' > '3' Expected result is 1. """ - assert version_cmp('3.0.2', '3') == 1 + assert version_cmp("3.0.2", "3") == 1 diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 6859f5a076..6a6bbc7c78 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -70,6 +70,7 @@ CWD = os.path.dirname(os.path.realpath(__file__)) # all test functions without declaring a test local variable. global_tgen = None + def get_topogen(topo=None): """ Helper function to retrieve Topogen. Must be called with `topo` when called @@ -79,31 +80,34 @@ def get_topogen(topo=None): global_tgen.topo = topo return global_tgen + def set_topogen(tgen): "Helper function to set Topogen" # pylint: disable=W0603 global global_tgen global_tgen = tgen + # # Main class: topology builder # # Topogen configuration defaults tgen_defaults = { - 'verbosity': 'info', - 'frrdir': '/usr/lib/frr', - 'quaggadir': '/usr/lib/quagga', - 'routertype': 'frr', - 'memleak_path': None, + "verbosity": "info", + "frrdir": "/usr/lib/frr", + "quaggadir": "/usr/lib/quagga", + "routertype": "frr", + "memleak_path": None, } + class Topogen(object): "A topology test builder helper." - CONFIG_SECTION = 'topogen' + CONFIG_SECTION = "topogen" - def __init__(self, cls, modname='unnamed'): + def __init__(self, cls, modname="unnamed"): """ Topogen initialization function, takes the following arguments: * `cls`: the topology class that is child of mininet.topo @@ -117,16 +121,16 @@ class Topogen(object): self.switchn = 1 self.modname = modname self.errorsd = {} - self.errors = '' + self.errors = "" self.peern = 1 self._init_topo(cls) - logger.info('loading topology: {}'.format(self.modname)) + logger.info("loading topology: {}".format(self.modname)) @staticmethod def _mininet_reset(): "Reset the mininet environment" # Clean up the mininet environment - os.system('mn -c > /dev/null 2>&1') + os.system("mn -c > /dev/null 2>&1") def _init_topo(self, cls): """ @@ -138,10 +142,10 @@ class Topogen(object): # Test for MPLS Kernel modules available self.hasmpls = False - if not topotest.module_present('mpls-router'): - logger.info('MPLS tests will not run (missing mpls-router kernel module)') - elif not topotest.module_present('mpls-iptunnel'): - logger.info('MPLS tests will not run (missing mpls-iptunnel kernel module)') + if not topotest.module_present("mpls-router"): + logger.info("MPLS tests will not run (missing mpls-router kernel module)") + elif not topotest.module_present("mpls-iptunnel"): + logger.info("MPLS tests will not run (missing mpls-iptunnel kernel module)") else: self.hasmpls = True # Load the default topology configurations @@ -160,7 +164,7 @@ class Topogen(object): topotests. """ self.config = configparser.ConfigParser(tgen_defaults) - pytestini_path = os.path.join(CWD, '../pytest.ini') + pytestini_path = os.path.join(CWD, "../pytest.ini") self.config.read(pytestini_path) def add_router(self, name=None, cls=topotest.Router, **params): @@ -173,15 +177,15 @@ class Topogen(object): Returns a TopoRouter. """ if name is None: - name = 'r{}'.format(self.routern) + name = "r{}".format(self.routern) if name in self.gears: - raise KeyError('router already exists') + raise KeyError("router already exists") - params['frrdir'] = self.config.get(self.CONFIG_SECTION, 'frrdir') - params['quaggadir'] = self.config.get(self.CONFIG_SECTION, 'quaggadir') - params['memleak_path'] = self.config.get(self.CONFIG_SECTION, 'memleak_path') - if not params.has_key('routertype'): - params['routertype'] = self.config.get(self.CONFIG_SECTION, 'routertype') + params["frrdir"] = self.config.get(self.CONFIG_SECTION, "frrdir") + params["quaggadir"] = self.config.get(self.CONFIG_SECTION, "quaggadir") + params["memleak_path"] = self.config.get(self.CONFIG_SECTION, "memleak_path") + if not params.has_key("routertype"): + params["routertype"] = self.config.get(self.CONFIG_SECTION, "routertype") self.gears[name] = TopoRouter(self, cls, name, **params) self.routern += 1 @@ -195,9 +199,9 @@ class Topogen(object): Returns the switch name and number. """ if name is None: - name = 's{}'.format(self.switchn) + name = "s{}".format(self.switchn) if name in self.gears: - raise KeyError('switch already exists') + raise KeyError("switch already exists") self.gears[name] = TopoSwitch(self, cls, name) self.switchn += 1 @@ -211,9 +215,9 @@ class Topogen(object): * `defaultRoute`: the peer default route (e.g. 'via 1.2.3.1') """ if name is None: - name = 'peer{}'.format(self.peern) + name = "peer{}".format(self.peern) if name in self.gears: - raise KeyError('exabgp peer already exists') + raise KeyError("exabgp peer already exists") self.gears[name] = TopoExaBGP(self, name, ip=ip, defaultRoute=defaultRoute) self.peern += 1 @@ -228,9 +232,9 @@ class Topogen(object): * TopoSwitch """ if not isinstance(node1, TopoGear): - raise ValueError('invalid node1 type') + raise ValueError("invalid node1 type") if not isinstance(node2, TopoGear): - raise ValueError('invalid node2 type') + raise ValueError("invalid node2 type") if ifname1 is None: ifname1 = node1.new_link() @@ -239,8 +243,7 @@ class Topogen(object): node1.register_link(ifname1, node2, ifname2) node2.register_link(ifname2, node1, ifname1) - self.topo.addLink(node1.name, node2.name, - intfName1=ifname1, intfName2=ifname2) + self.topo.addLink(node1.name, node2.name, intfName1=ifname1, intfName2=ifname2) def get_gears(self, geartype): """ @@ -262,8 +265,11 @@ class Topogen(object): # Do stuff ``` """ - return dict((name, gear) for name, gear in self.gears.iteritems() - if isinstance(gear, geartype)) + return dict( + (name, gear) + for name, gear in self.gears.iteritems() + if isinstance(gear, geartype) + ) def routers(self): """ @@ -291,16 +297,16 @@ class Topogen(object): """ # If log_level is not specified use the configuration. if log_level is None: - log_level = self.config.get(self.CONFIG_SECTION, 'verbosity') + log_level = self.config.get(self.CONFIG_SECTION, "verbosity") # Set python logger level logger_config.set_log_level(log_level) # Run mininet - if log_level == 'debug': + if log_level == "debug": setLogLevel(log_level) - logger.info('starting topology: {}'.format(self.modname)) + logger.info("starting topology: {}".format(self.modname)) self.net.start() def start_router(self, router=None): @@ -326,7 +332,7 @@ class Topogen(object): first is a simple kill with no sleep, the second will sleep if not killed and try with a different signal. """ - logger.info('stopping topology: {}'.format(self.modname)) + logger.info("stopping topology: {}".format(self.modname)) errors = "" for gear in self.gears.values(): gear.stop(False, False) @@ -344,7 +350,8 @@ class Topogen(object): """ if not sys.stdin.isatty(): raise EnvironmentError( - 'you must run pytest with \'-s\' in order to use mininet CLI') + "you must run pytest with '-s' in order to use mininet CLI" + ) CLI(self.net) @@ -354,8 +361,9 @@ class Topogen(object): if self.routers_have_failure(): return False - memleak_file = (os.environ.get('TOPOTESTS_CHECK_MEMLEAK') or - self.config.get(self.CONFIG_SECTION, 'memleak_path')) + memleak_file = os.environ.get("TOPOTESTS_CHECK_MEMLEAK") or self.config.get( + self.CONFIG_SECTION, "memleak_path" + ) if memleak_file is None: return False return True @@ -382,7 +390,7 @@ class Topogen(object): code = len(self.errorsd) self.errorsd[code] = message - self.errors += '\n{}: {}'.format(code, message) + self.errors += "\n{}: {}".format(code, message) def has_errors(self): "Returns whether errors exist or not." @@ -393,23 +401,25 @@ class Topogen(object): if self.has_errors(): return True - errors = '' + errors = "" router_list = self.routers().values() for router in router_list: result = router.check_router_running() - if result != '': - errors += result + '\n' + if result != "": + errors += result + "\n" - if errors != '': - self.set_error(errors, 'router_error') + if errors != "": + self.set_error(errors, "router_error") assert False, errors return True return False + # # Topology gears (equipment) # + class TopoGear(object): "Abstract class for type checking" @@ -421,11 +431,11 @@ class TopoGear(object): self.linkn = 0 def __str__(self): - links = '' + links = "" for myif, dest in self.links.iteritems(): _, destif = dest - if links != '': - links += ',' + if links != "": + links += "," links += '"{}"<->"{}"'.format(myif, destif) return 'TopoGear'.format(self.name, links) @@ -462,20 +472,22 @@ class TopoGear(object): enabled: whether we should enable or disable the interface """ if myif not in self.links.keys(): - raise KeyError('interface doesn\'t exists') + raise KeyError("interface doesn't exists") if enabled is True: - operation = 'up' + operation = "up" else: - operation = 'down' + operation = "down" - logger.info('setting node "{}" link "{}" to state "{}"'.format( - self.name, myif, operation - )) - extract='' + logger.info( + 'setting node "{}" link "{}" to state "{}"'.format( + self.name, myif, operation + ) + ) + extract = "" if netns is not None: - extract = 'ip netns exec {} '.format(netns) - return self.run('{}ip link set dev {} {}'.format(extract, myif, operation)) + extract = "ip netns exec {} ".format(netns) + return self.run("{}ip link set dev {} {}".format(extract, myif, operation)) def peer_link_enable(self, myif, enabled=True, netns=None): """ @@ -487,7 +499,7 @@ class TopoGear(object): peer disables their interface our interface status changes to no link. """ if myif not in self.links.keys(): - raise KeyError('interface doesn\'t exists') + raise KeyError("interface doesn't exists") node, nodeif = self.links[myif] node.link_enable(nodeif, enabled, netns) @@ -498,7 +510,7 @@ class TopoGear(object): NOTE: This function should only be called by Topogen. """ - ifname = '{}-eth{}'.format(self.name, self.linkn) + ifname = "{}-eth{}".format(self.name, self.linkn) self.linkn += 1 return ifname @@ -509,10 +521,11 @@ class TopoGear(object): NOTE: This function should only be called by Topogen. """ if myif in self.links.keys(): - raise KeyError('interface already exists') + raise KeyError("interface already exists") self.links[myif] = (node, nodeif) + class TopoRouter(TopoGear): """ Router abstraction. @@ -520,11 +533,11 @@ class TopoRouter(TopoGear): # The default required directories by Quagga/FRR PRIVATE_DIRS = [ - '/etc/frr', - '/etc/quagga', - '/var/run/frr', - '/var/run/quagga', - '/var/log' + "/etc/frr", + "/etc/quagga", + "/var/run/frr", + "/var/run/quagga", + "/var/log", ] # Router Daemon enumeration definition. @@ -543,20 +556,20 @@ class TopoRouter(TopoGear): RD_BFD = 13 RD_SHARP = 14 RD = { - RD_ZEBRA: 'zebra', - RD_RIP: 'ripd', - RD_RIPNG: 'ripngd', - RD_OSPF: 'ospfd', - RD_OSPF6: 'ospf6d', - RD_ISIS: 'isisd', - RD_BGP: 'bgpd', - RD_PIM: 'pimd', - RD_LDP: 'ldpd', - RD_EIGRP: 'eigrpd', - RD_NHRP: 'nhrpd', - RD_STATIC: 'staticd', - RD_BFD: 'bfdd', - RD_SHARP: 'sharpd', + RD_ZEBRA: "zebra", + RD_RIP: "ripd", + RD_RIPNG: "ripngd", + RD_OSPF: "ospfd", + RD_OSPF6: "ospf6d", + RD_ISIS: "isisd", + RD_BGP: "bgpd", + RD_PIM: "pimd", + RD_LDP: "ldpd", + RD_EIGRP: "eigrpd", + RD_NHRP: "nhrpd", + RD_STATIC: "staticd", + RD_BFD: "bfdd", + RD_SHARP: "sharpd", } def __init__(self, tgen, cls, name, **params): @@ -574,34 +587,34 @@ class TopoRouter(TopoGear): self.name = name self.cls = cls self.options = {} - self.routertype = params.get('routertype', 'frr') - if not params.has_key('privateDirs'): - params['privateDirs'] = self.PRIVATE_DIRS + self.routertype = params.get("routertype", "frr") + if not params.has_key("privateDirs"): + params["privateDirs"] = self.PRIVATE_DIRS - self.options['memleak_path'] = params.get('memleak_path', None) + self.options["memleak_path"] = params.get("memleak_path", None) # Create new log directory - self.logdir = '/tmp/topotests/{}'.format(self.tgen.modname) + self.logdir = "/tmp/topotests/{}".format(self.tgen.modname) # Clean up before starting new log files: avoids removing just created # log files. self._prepare_tmpfiles() # Propagate the router log directory - params['logdir'] = self.logdir + params["logdir"] = self.logdir - #setup the per node directory - dir = '{}/{}'.format(self.logdir, self.name) - os.system('mkdir -p ' + dir) - os.system('chmod -R go+rw /tmp/topotests') + # setup the per node directory + dir = "{}/{}".format(self.logdir, self.name) + os.system("mkdir -p " + dir) + os.system("chmod -R go+rw /tmp/topotests") # Open router log file - logfile = '{0}/{1}.log'.format(self.logdir, name) + logfile = "{0}/{1}.log".format(self.logdir, name) self.logger = logger_config.get_logger(name=name, target=logfile) self.tgen.topo.addNode(self.name, cls=self.cls, **params) def __str__(self): gear = super(TopoRouter, self).__str__() - gear += ' TopoRouter<>' + gear += " TopoRouter<>" return gear def _prepare_tmpfiles(self): @@ -622,9 +635,9 @@ class TopoRouter(TopoGear): os.chmod(self.logdir, 0o1777) # Try to find relevant old logfiles in /tmp and delete them - map(os.remove, glob.glob('{}/{}/*.log'.format(self.logdir, self.name))) + map(os.remove, glob.glob("{}/{}/*.log".format(self.logdir, self.name))) # Remove old core files - map(os.remove, glob.glob('{}/{}/*.dmp'.format(self.logdir, self.name))) + map(os.remove, glob.glob("{}/{}/*.dmp".format(self.logdir, self.name))) def check_capability(self, daemon, param): """ @@ -651,7 +664,7 @@ class TopoRouter(TopoGear): """ Run a series of checks and returns a status string. """ - self.logger.info('checking if daemons are running') + self.logger.info("checking if daemons are running") return self.tgen.net[self.name].checkRouterRunning() def start(self): @@ -663,7 +676,7 @@ class TopoRouter(TopoGear): * Start daemons (e.g. FRR/Quagga) * Configure daemon logging files """ - self.logger.debug('starting') + self.logger.debug("starting") nrouter = self.tgen.net[self.name] result = nrouter.startRouter(self.tgen) @@ -672,15 +685,17 @@ class TopoRouter(TopoGear): for daemon, enabled in nrouter.daemons.iteritems(): if enabled == 0: continue - self.vtysh_cmd('configure terminal\nlog commands\nlog file {}.log'.format( - daemon), daemon=daemon) + self.vtysh_cmd( + "configure terminal\nlog commands\nlog file {}.log".format(daemon), + daemon=daemon, + ) - if result != '': + if result != "": self.tgen.set_error(result) else: # Enable MPLS processing on all interfaces. for interface in self.links.keys(): - set_sysctl(nrouter, 'net.mpls.conf.{}.input'.format(interface), 1) + set_sysctl(nrouter, "net.mpls.conf.{}.input".format(interface), 1) return result @@ -689,7 +704,7 @@ class TopoRouter(TopoGear): Stop router: * Kill daemons """ - self.logger.debug('stopping') + self.logger.debug("stopping") return self.tgen.net[self.name].stopRouter(wait, assertOnError) def vtysh_cmd(self, command, isjson=False, daemon=None): @@ -701,25 +716,26 @@ class TopoRouter(TopoGear): return output for each command. See vtysh_multicmd() for more details. """ # Detect multi line commands - if command.find('\n') != -1: + if command.find("\n") != -1: return self.vtysh_multicmd(command, daemon=daemon) - dparam = '' + dparam = "" if daemon is not None: - dparam += '-d {}'.format(daemon) + dparam += "-d {}".format(daemon) vtysh_command = 'vtysh {} -c "{}" 2>/dev/null'.format(dparam, command) output = self.run(vtysh_command) - self.logger.info('\nvtysh command => {}\nvtysh output <= {}'.format( - command, output)) + self.logger.info( + "\nvtysh command => {}\nvtysh output <= {}".format(command, output) + ) if isjson is False: return output try: return json.loads(output) except ValueError: - logger.warning('vtysh_cmd: failed to convert json output') + logger.warning("vtysh_cmd: failed to convert json output") return {} def vtysh_multicmd(self, commands, pretty_output=True, daemon=None): @@ -734,21 +750,22 @@ class TopoRouter(TopoGear): # Prepare the temporary file that will hold the commands fname = topotest.get_file(commands) - dparam = '' + dparam = "" if daemon is not None: - dparam += '-d {}'.format(daemon) + dparam += "-d {}".format(daemon) # Run the commands and delete the temporary file if pretty_output: - vtysh_command = 'vtysh {} < {}'.format(dparam, fname) + vtysh_command = "vtysh {} < {}".format(dparam, fname) else: - vtysh_command = 'vtysh {} -f {}'.format(dparam, fname) + vtysh_command = "vtysh {} -f {}".format(dparam, fname) res = self.run(vtysh_command) os.unlink(fname) - self.logger.info('\nvtysh command => "{}"\nvtysh output <= "{}"'.format( - vtysh_command, res)) + self.logger.info( + '\nvtysh command => "{}"\nvtysh output <= "{}"'.format(vtysh_command, res) + ) return res @@ -760,27 +777,29 @@ class TopoRouter(TopoGear): NOTE: to run this you must have the environment variable TOPOTESTS_CHECK_MEMLEAK set or memleak_path configured in `pytest.ini`. """ - memleak_file = os.environ.get('TOPOTESTS_CHECK_MEMLEAK') or self.options['memleak_path'] + memleak_file = ( + os.environ.get("TOPOTESTS_CHECK_MEMLEAK") or self.options["memleak_path"] + ) if memleak_file is None: return self.stop() - self.logger.info('running memory leak report') + self.logger.info("running memory leak report") self.tgen.net[self.name].report_memory_leaks(memleak_file, testname) def version_info(self): "Get equipment information from 'show version'." - output = self.vtysh_cmd('show version').split('\n')[0] - columns = topotest.normalize_text(output).split(' ') + output = self.vtysh_cmd("show version").split("\n")[0] + columns = topotest.normalize_text(output).split(" ") try: return { - 'type': columns[0], - 'version': columns[1], + "type": columns[0], + "version": columns[1], } except IndexError: return { - 'type': None, - 'version': None, + "type": None, + "version": None, } def has_version(self, cmpop, version): @@ -802,19 +821,21 @@ class TopoRouter(TopoGear): Compares router type with `rtype`. Returns `True` if the type matches, otherwise `false`. """ - curtype = self.version_info()['type'] + curtype = self.version_info()["type"] return rtype == curtype def has_mpls(self): nrouter = self.tgen.net[self.name] return nrouter.hasmpls + class TopoSwitch(TopoGear): """ Switch abstraction. Has the following properties: * cls: switch class that will be used to instantiate * name: switch name """ + # pylint: disable=too-few-public-methods def __init__(self, tgen, cls, name): @@ -827,9 +848,10 @@ class TopoSwitch(TopoGear): def __str__(self): gear = super(TopoSwitch, self).__str__() - gear += ' TopoSwitch<>' + gear += " TopoSwitch<>" return gear + class TopoHost(TopoGear): "Host abstraction." # pylint: disable=too-few-public-methods @@ -853,18 +875,21 @@ class TopoHost(TopoGear): def __str__(self): gear = super(TopoHost, self).__str__() gear += ' TopoHost'.format( - self.options['ip'], self.options['defaultRoute'], - str(self.options['privateDirs'])) + self.options["ip"], + self.options["defaultRoute"], + str(self.options["privateDirs"]), + ) return gear + class TopoExaBGP(TopoHost): "ExaBGP peer abstraction." # pylint: disable=too-few-public-methods PRIVATE_DIRS = [ - '/etc/exabgp', - '/var/run/exabgp', - '/var/log', + "/etc/exabgp", + "/var/run/exabgp", + "/var/log", ] def __init__(self, tgen, name, **params): @@ -878,13 +903,13 @@ class TopoExaBGP(TopoHost): has a privateDirs already defined and contains functions to handle ExaBGP things. """ - params['privateDirs'] = self.PRIVATE_DIRS + params["privateDirs"] = self.PRIVATE_DIRS super(TopoExaBGP, self).__init__(tgen, name, **params) self.tgen.topo.addHost(name, **params) def __str__(self): gear = super(TopoExaBGP, self).__str__() - gear += ' TopoExaBGP<>'.format() + gear += " TopoExaBGP<>".format() return gear def start(self, peer_dir, env_file=None): @@ -895,22 +920,22 @@ class TopoExaBGP(TopoHost): * Make all python files runnable * Run ExaBGP with env file `env_file` and configuration peer*/exabgp.cfg """ - self.run('mkdir /etc/exabgp') - self.run('chmod 755 /etc/exabgp') - self.run('cp {}/* /etc/exabgp/'.format(peer_dir)) + self.run("mkdir /etc/exabgp") + self.run("chmod 755 /etc/exabgp") + self.run("cp {}/* /etc/exabgp/".format(peer_dir)) if env_file is not None: - self.run('cp {} /etc/exabgp/exabgp.env'.format(env_file)) - self.run('chmod 644 /etc/exabgp/*') - self.run('chmod a+x /etc/exabgp/*.py') - self.run('chown -R exabgp:exabgp /etc/exabgp') - output = self.run('exabgp -e /etc/exabgp/exabgp.env /etc/exabgp/exabgp.cfg') + self.run("cp {} /etc/exabgp/exabgp.env".format(env_file)) + self.run("chmod 644 /etc/exabgp/*") + self.run("chmod a+x /etc/exabgp/*.py") + self.run("chown -R exabgp:exabgp /etc/exabgp") + output = self.run("exabgp -e /etc/exabgp/exabgp.env /etc/exabgp/exabgp.cfg") if output == None or len(output) == 0: - output = '' - logger.info('{} exabgp started, output={}'.format(self.name, output)) + output = "" + logger.info("{} exabgp started, output={}".format(self.name, output)) def stop(self, wait=True, assertOnError=True): "Stop ExaBGP peer and kill the daemon" - self.run('kill `cat /var/run/exabgp/exabgp.pid`') + self.run("kill `cat /var/run/exabgp/exabgp.pid`") return "" @@ -928,160 +953,189 @@ def diagnose_env_linux(): ret = True # Test log path exists before installing handler. - if not os.path.isdir('/tmp'): - logger.warning('could not find /tmp for logs') + if not os.path.isdir("/tmp"): + logger.warning("could not find /tmp for logs") else: - os.system('mkdir /tmp/topotests') + os.system("mkdir /tmp/topotests") # Log diagnostics to file so it can be examined later. - fhandler = logging.FileHandler(filename='/tmp/topotests/diagnostics.txt') + fhandler = logging.FileHandler(filename="/tmp/topotests/diagnostics.txt") fhandler.setLevel(logging.DEBUG) fhandler.setFormatter( - logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s') + logging.Formatter(fmt="%(asctime)s %(levelname)s: %(message)s") ) logger.addHandler(fhandler) - logger.info('Running environment diagnostics') + logger.info("Running environment diagnostics") # Load configuration config = configparser.ConfigParser(tgen_defaults) - pytestini_path = os.path.join(CWD, '../pytest.ini') + pytestini_path = os.path.join(CWD, "../pytest.ini") config.read(pytestini_path) # Assert that we are running as root if os.getuid() != 0: - logger.error('you must run topotest as root') + logger.error("you must run topotest as root") ret = False # Assert that we have mininet - if os.system('which mn >/dev/null 2>/dev/null') != 0: - logger.error('could not find mininet binary (mininet is not installed)') + if os.system("which mn >/dev/null 2>/dev/null") != 0: + logger.error("could not find mininet binary (mininet is not installed)") ret = False # Assert that we have iproute installed - if os.system('which ip >/dev/null 2>/dev/null') != 0: - logger.error('could not find ip binary (iproute is not installed)') + if os.system("which ip >/dev/null 2>/dev/null") != 0: + logger.error("could not find ip binary (iproute is not installed)") ret = False # Assert that we have gdb installed - if os.system('which gdb >/dev/null 2>/dev/null') != 0: - logger.error('could not find gdb binary (gdb is not installed)') + if os.system("which gdb >/dev/null 2>/dev/null") != 0: + logger.error("could not find gdb binary (gdb is not installed)") ret = False # Assert that FRR utilities exist - frrdir = config.get('topogen', 'frrdir') + frrdir = config.get("topogen", "frrdir") hasfrr = False if not os.path.isdir(frrdir): - logger.error('could not find {} directory'.format(frrdir)) + logger.error("could not find {} directory".format(frrdir)) ret = False else: hasfrr = True try: - pwd.getpwnam('frr')[2] + pwd.getpwnam("frr")[2] except KeyError: logger.warning('could not find "frr" user') try: - grp.getgrnam('frr')[2] + grp.getgrnam("frr")[2] except KeyError: logger.warning('could not find "frr" group') try: - if 'frr' not in grp.getgrnam('frrvty').gr_mem: - logger.error('"frr" user and group exist, but user is not under "frrvty"') + if "frr" not in grp.getgrnam("frrvty").gr_mem: + logger.error( + '"frr" user and group exist, but user is not under "frrvty"' + ) except KeyError: logger.warning('could not find "frrvty" group') - for fname in ['zebra', 'ospfd', 'ospf6d', 'bgpd', 'ripd', 'ripngd', - 'isisd', 'pimd', 'ldpd']: + for fname in [ + "zebra", + "ospfd", + "ospf6d", + "bgpd", + "ripd", + "ripngd", + "isisd", + "pimd", + "ldpd", + ]: path = os.path.join(frrdir, fname) if not os.path.isfile(path): # LDPd is an exception - if fname == 'ldpd': - logger.info('could not find {} in {}'.format(fname, frrdir) + - '(LDPd tests will not run)') + if fname == "ldpd": + logger.info( + "could not find {} in {}".format(fname, frrdir) + + "(LDPd tests will not run)" + ) continue - logger.warning('could not find {} in {}'.format(fname, frrdir)) + logger.warning("could not find {} in {}".format(fname, frrdir)) ret = False else: - if fname != 'zebra': + if fname != "zebra": continue - os.system( - '{} -v 2>&1 >/tmp/topotests/frr_zebra.txt'.format(path) - ) + os.system("{} -v 2>&1 >/tmp/topotests/frr_zebra.txt".format(path)) # Assert that Quagga utilities exist - quaggadir = config.get('topogen', 'quaggadir') + quaggadir = config.get("topogen", "quaggadir") if hasfrr: # if we have frr, don't check for quagga pass elif not os.path.isdir(quaggadir): - logger.info('could not find {} directory (quagga tests will not run)'.format(quaggadir)) + logger.info( + "could not find {} directory (quagga tests will not run)".format(quaggadir) + ) else: ret = True try: - pwd.getpwnam('quagga')[2] + pwd.getpwnam("quagga")[2] except KeyError: logger.info('could not find "quagga" user') try: - grp.getgrnam('quagga')[2] + grp.getgrnam("quagga")[2] except KeyError: logger.info('could not find "quagga" group') try: - if 'quagga' not in grp.getgrnam('quaggavty').gr_mem: - logger.error('"quagga" user and group exist, but user is not under "quaggavty"') + if "quagga" not in grp.getgrnam("quaggavty").gr_mem: + logger.error( + '"quagga" user and group exist, but user is not under "quaggavty"' + ) except KeyError: logger.warning('could not find "quaggavty" group') - for fname in ['zebra', 'ospfd', 'ospf6d', 'bgpd', 'ripd', 'ripngd', - 'isisd', 'pimd']: + for fname in [ + "zebra", + "ospfd", + "ospf6d", + "bgpd", + "ripd", + "ripngd", + "isisd", + "pimd", + ]: path = os.path.join(quaggadir, fname) if not os.path.isfile(path): - logger.warning('could not find {} in {}'.format(fname, quaggadir)) + logger.warning("could not find {} in {}".format(fname, quaggadir)) ret = False else: - if fname != 'zebra': + if fname != "zebra": continue - os.system( - '{} -v 2>&1 >/tmp/topotests/quagga_zebra.txt'.format(path) - ) + os.system("{} -v 2>&1 >/tmp/topotests/quagga_zebra.txt".format(path)) # Test MPLS availability krel = platform.release() - if topotest.version_cmp(krel, '4.5') < 0: - logger.info('LDPd tests will not run (have kernel "{}", but it requires 4.5)'.format(krel)) + if topotest.version_cmp(krel, "4.5") < 0: + logger.info( + 'LDPd tests will not run (have kernel "{}", but it requires 4.5)'.format( + krel + ) + ) # Test for MPLS Kernel modules available - if not topotest.module_present('mpls-router', load=False) != 0: - logger.info('LDPd tests will not run (missing mpls-router kernel module)') - if not topotest.module_present('mpls-iptunnel', load=False) != 0: - logger.info('LDPd tests will not run (missing mpls-iptunnel kernel module)') + if not topotest.module_present("mpls-router", load=False) != 0: + logger.info("LDPd tests will not run (missing mpls-router kernel module)") + if not topotest.module_present("mpls-iptunnel", load=False) != 0: + logger.info("LDPd tests will not run (missing mpls-iptunnel kernel module)") # TODO remove me when we start supporting exabgp >= 4 try: - output = subprocess.check_output(['exabgp', '-v']) - line = output.split('\n')[0] - version = line.split(' ')[2] - if topotest.version_cmp(version, '4') >= 0: - logger.warning('BGP topologies are still using exabgp version 3, expect failures') + output = subprocess.check_output(["exabgp", "-v"]) + line = output.split("\n")[0] + version = line.split(" ")[2] + if topotest.version_cmp(version, "4") >= 0: + logger.warning( + "BGP topologies are still using exabgp version 3, expect failures" + ) # We want to catch all exceptions # pylint: disable=W0702 except: - logger.warning('failed to find exabgp or returned error') + logger.warning("failed to find exabgp or returned error") # After we logged the output to file, remove the handler. logger.removeHandler(fhandler) return ret + def diagnose_env_freebsd(): return True + def diagnose_env(): if sys.platform.startswith("linux"): return diagnose_env_linux() diff --git a/tests/topotests/lib/topojson.py b/tests/topotests/lib/topojson.py index fff5a1e82f..b25317ba7f 100644 --- a/tests/topotests/lib/topojson.py +++ b/tests/topotests/lib/topojson.py @@ -29,13 +29,14 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from lib.common_config import ( - number_to_row, number_to_column, + number_to_row, + number_to_column, load_config_to_router, create_interfaces_cfg, create_static_routes, create_prefix_lists, create_route_maps, - create_bgp_community_lists + create_bgp_community_lists, ) from lib.bgp import create_router_bgp @@ -53,56 +54,69 @@ def build_topo_from_json(tgen, topo): * `topo`: json file data """ - ROUTER_LIST = sorted(topo['routers'].keys(), - key=lambda x: int(re_search('\d+', x).group(0))) + ROUTER_LIST = sorted( + topo["routers"].keys(), key=lambda x: int(re_search("\d+", x).group(0)) + ) listRouters = ROUTER_LIST[:] for routerN in ROUTER_LIST: - logger.info('Topo: Add router {}'.format(routerN)) + logger.info("Topo: Add router {}".format(routerN)) tgen.add_router(routerN) listRouters.append(routerN) - if 'ipv4base' in topo: - ipv4Next = ipaddr.IPv4Address(topo['link_ip_start']['ipv4']) - ipv4Step = 2 ** (32 - topo['link_ip_start']['v4mask']) - if topo['link_ip_start']['v4mask'] < 32: + if "ipv4base" in topo: + ipv4Next = ipaddr.IPv4Address(topo["link_ip_start"]["ipv4"]) + ipv4Step = 2 ** (32 - topo["link_ip_start"]["v4mask"]) + if topo["link_ip_start"]["v4mask"] < 32: ipv4Next += 1 - if 'ipv6base' in topo: - ipv6Next = ipaddr.IPv6Address(topo['link_ip_start']['ipv6']) - ipv6Step = 2 ** (128 - topo['link_ip_start']['v6mask']) - if topo['link_ip_start']['v6mask'] < 127: + if "ipv6base" in topo: + ipv6Next = ipaddr.IPv6Address(topo["link_ip_start"]["ipv6"]) + ipv6Step = 2 ** (128 - topo["link_ip_start"]["v6mask"]) + if topo["link_ip_start"]["v6mask"] < 127: ipv6Next += 1 for router in listRouters: - topo['routers'][router]['nextIfname'] = 0 + topo["routers"][router]["nextIfname"] = 0 while listRouters != []: curRouter = listRouters.pop(0) # Physical Interfaces - if 'links' in topo['routers'][curRouter]: + if "links" in topo["routers"][curRouter]: + def link_sort(x): - if x == 'lo': + if x == "lo": return 0 - elif 'link' in x: - return int(x.split('-link')[1]) + elif "link" in x: + return int(x.split("-link")[1]) else: - return int(re_search('\d+', x).group(0)) - for destRouterLink, data in sorted(topo['routers'][curRouter]['links']. \ - iteritems(), - key=lambda x: link_sort(x[0])): - currRouter_lo_json = \ - topo['routers'][curRouter]['links'][destRouterLink] + return int(re_search("\d+", x).group(0)) + + for destRouterLink, data in sorted( + topo["routers"][curRouter]["links"].iteritems(), + key=lambda x: link_sort(x[0]), + ): + currRouter_lo_json = topo["routers"][curRouter]["links"][destRouterLink] # Loopback interfaces - if 'type' in data and data['type'] == 'loopback': - if 'ipv4' in currRouter_lo_json and \ - currRouter_lo_json['ipv4'] == 'auto': - currRouter_lo_json['ipv4'] = '{}{}.{}/{}'. \ - format(topo['lo_prefix']['ipv4'], number_to_row(curRouter), \ - number_to_column(curRouter), topo['lo_prefix']['v4mask']) - if 'ipv6' in currRouter_lo_json and \ - currRouter_lo_json['ipv6'] == 'auto': - currRouter_lo_json['ipv6'] = '{}{}:{}/{}'. \ - format(topo['lo_prefix']['ipv6'], number_to_row(curRouter), \ - number_to_column(curRouter), topo['lo_prefix']['v6mask']) + if "type" in data and data["type"] == "loopback": + if ( + "ipv4" in currRouter_lo_json + and currRouter_lo_json["ipv4"] == "auto" + ): + currRouter_lo_json["ipv4"] = "{}{}.{}/{}".format( + topo["lo_prefix"]["ipv4"], + number_to_row(curRouter), + number_to_column(curRouter), + topo["lo_prefix"]["v4mask"], + ) + if ( + "ipv6" in currRouter_lo_json + and currRouter_lo_json["ipv6"] == "auto" + ): + currRouter_lo_json["ipv6"] = "{}{}:{}/{}".format( + topo["lo_prefix"]["ipv6"], + number_to_row(curRouter), + number_to_column(curRouter), + topo["lo_prefix"]["v6mask"], + ) if "-" in destRouterLink: # Spliting and storing destRouterLink data in tempList @@ -119,52 +133,63 @@ def build_topo_from_json(tgen, topo): curRouterLink = curRouter if destRouter in listRouters: - currRouter_link_json = \ - topo['routers'][curRouter]['links'][destRouterLink] - destRouter_link_json = \ - topo['routers'][destRouter]['links'][curRouterLink] + currRouter_link_json = topo["routers"][curRouter]["links"][ + destRouterLink + ] + destRouter_link_json = topo["routers"][destRouter]["links"][ + curRouterLink + ] # Assigning name to interfaces - currRouter_link_json['interface'] = \ - '{}-{}-eth{}'.format(curRouter, destRouter, topo['routers'] \ - [curRouter]['nextIfname']) - destRouter_link_json['interface'] = \ - '{}-{}-eth{}'.format(destRouter, curRouter, topo['routers'] \ - [destRouter]['nextIfname']) + currRouter_link_json["interface"] = "{}-{}-eth{}".format( + curRouter, destRouter, topo["routers"][curRouter]["nextIfname"] + ) + destRouter_link_json["interface"] = "{}-{}-eth{}".format( + destRouter, curRouter, topo["routers"][destRouter]["nextIfname"] + ) - topo['routers'][curRouter]['nextIfname'] += 1 - topo['routers'][destRouter]['nextIfname'] += 1 + topo["routers"][curRouter]["nextIfname"] += 1 + topo["routers"][destRouter]["nextIfname"] += 1 # Linking routers to each other as defined in JSON file - tgen.gears[curRouter].add_link(tgen.gears[destRouter], - topo['routers'][curRouter]['links'][destRouterLink] \ - ['interface'], topo['routers'][destRouter]['links'] \ - [curRouterLink]['interface']) + tgen.gears[curRouter].add_link( + tgen.gears[destRouter], + topo["routers"][curRouter]["links"][destRouterLink][ + "interface" + ], + topo["routers"][destRouter]["links"][curRouterLink][ + "interface" + ], + ) # IPv4 - if 'ipv4' in currRouter_link_json: - if currRouter_link_json['ipv4'] == 'auto': - currRouter_link_json['ipv4'] = \ - '{}/{}'.format(ipv4Next, topo['link_ip_start'][ \ - 'v4mask']) - destRouter_link_json['ipv4'] = \ - '{}/{}'.format(ipv4Next + 1, topo['link_ip_start'][ \ - 'v4mask']) + if "ipv4" in currRouter_link_json: + if currRouter_link_json["ipv4"] == "auto": + currRouter_link_json["ipv4"] = "{}/{}".format( + ipv4Next, topo["link_ip_start"]["v4mask"] + ) + destRouter_link_json["ipv4"] = "{}/{}".format( + ipv4Next + 1, topo["link_ip_start"]["v4mask"] + ) ipv4Next += ipv4Step # IPv6 - if 'ipv6' in currRouter_link_json: - if currRouter_link_json['ipv6'] == 'auto': - currRouter_link_json['ipv6'] = \ - '{}/{}'.format(ipv6Next, topo['link_ip_start'][ \ - 'v6mask']) - destRouter_link_json['ipv6'] = \ - '{}/{}'.format(ipv6Next + 1, topo['link_ip_start'][ \ - 'v6mask']) + if "ipv6" in currRouter_link_json: + if currRouter_link_json["ipv6"] == "auto": + currRouter_link_json["ipv6"] = "{}/{}".format( + ipv6Next, topo["link_ip_start"]["v6mask"] + ) + destRouter_link_json["ipv6"] = "{}/{}".format( + ipv6Next + 1, topo["link_ip_start"]["v6mask"] + ) ipv6Next = ipaddr.IPv6Address(int(ipv6Next) + ipv6Step) - logger.debug("Generated link data for router: %s\n%s", curRouter, - json_dumps(topo["routers"][curRouter]["links"], - indent=4, sort_keys=True)) + logger.debug( + "Generated link data for router: %s\n%s", + curRouter, + json_dumps( + topo["routers"][curRouter]["links"], indent=4, sort_keys=True + ), + ) def build_config_from_json(tgen, topo, save_bkup=True): @@ -176,27 +201,27 @@ def build_config_from_json(tgen, topo, save_bkup=True): * `topo`: json file data """ - func_dict = OrderedDict([ - ("links", create_interfaces_cfg), - ("static_routes", create_static_routes), - ("prefix_lists", create_prefix_lists), - ("bgp_community_list", create_bgp_community_lists), - ("route_maps", create_route_maps), - ("bgp", create_router_bgp) - ]) + func_dict = OrderedDict( + [ + ("links", create_interfaces_cfg), + ("static_routes", create_static_routes), + ("prefix_lists", create_prefix_lists), + ("bgp_community_list", create_bgp_community_lists), + ("route_maps", create_route_maps), + ("bgp", create_router_bgp), + ] + ) data = topo["routers"] for func_type in func_dict.keys(): - logger.info('Checking for {} configuration in input data'.format( - func_type)) + logger.info("Checking for {} configuration in input data".format(func_type)) func_dict.get(func_type)(tgen, data, build=True) - for router in sorted(topo['routers'].keys()): - logger.debug('Configuring router {}...'.format(router)) + for router in sorted(topo["routers"].keys()): + logger.debug("Configuring router {}...".format(router)) result = load_config_to_router(tgen, router, save_bkup) if not result: logger.info("Failed while configuring {}".format(router)) pytest.exit(1) - diff --git a/tests/topotests/lib/topolog.py b/tests/topotests/lib/topolog.py index f149f34eb3..0dfa870930 100644 --- a/tests/topotests/lib/topolog.py +++ b/tests/topotests/lib/topolog.py @@ -31,22 +31,25 @@ import logging # Helper dictionary to convert Topogen logging levels to Python's logging. DEBUG_TOPO2LOGGING = { - 'debug': logging.DEBUG, - 'info': logging.INFO, - 'output': logging.INFO, - 'warning': logging.WARNING, - 'error': logging.ERROR, - 'critical': logging.CRITICAL, + "debug": logging.DEBUG, + "info": logging.INFO, + "output": logging.INFO, + "warning": logging.WARNING, + "error": logging.ERROR, + "critical": logging.CRITICAL, } + class InfoFilter(logging.Filter): def filter(self, rec): return rec.levelno in (logging.DEBUG, logging.INFO) + # # Logger class definition # + class Logger(object): """ Logger class that encapsulates logging functions, internaly it uses Python @@ -58,32 +61,32 @@ class Logger(object): def __init__(self): # Create default global logger self.log_level = logging.INFO - self.logger = logging.Logger('topolog', level=self.log_level) + self.logger = logging.Logger("topolog", level=self.log_level) handler_stdout = logging.StreamHandler(sys.stdout) handler_stdout.setLevel(logging.DEBUG) handler_stdout.addFilter(InfoFilter()) handler_stdout.setFormatter( - logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s') + logging.Formatter(fmt="%(asctime)s %(levelname)s: %(message)s") ) handler_stderr = logging.StreamHandler() handler_stderr.setLevel(logging.WARNING) handler_stderr.setFormatter( - logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s') + logging.Formatter(fmt="%(asctime)s %(levelname)s: %(message)s") ) self.logger.addHandler(handler_stdout) self.logger.addHandler(handler_stderr) # Handle more loggers - self.loggers = {'topolog': self.logger} + self.loggers = {"topolog": self.logger} def set_log_level(self, level): "Set the logging level" self.log_level = DEBUG_TOPO2LOGGING.get(level) self.logger.setLevel(self.log_level) - def get_logger(self, name='topolog', log_level=None, target=sys.stdout): + def get_logger(self, name="topolog", log_level=None, target=sys.stdout): """ Get a new logger entry. Allows creating different loggers for formating, filtering or handling (file, stream or stdout/stderr). @@ -100,12 +103,13 @@ class Logger(object): handler = logging.StreamHandler(stream=target) handler.setFormatter( - logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s') + logging.Formatter(fmt="%(asctime)s %(levelname)s: %(message)s") ) nlogger.addHandler(handler) self.loggers[name] = nlogger return nlogger + # # Global variables # diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index 9e1d344687..fab101cb25 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -50,6 +50,7 @@ from mininet.log import setLogLevel, info from mininet.cli import CLI from mininet.link import Intf + class json_cmp_result(object): "json_cmp result class for better assertion messages" @@ -66,7 +67,7 @@ class json_cmp_result(object): return len(self.errors) > 0 def __str__(self): - return '\n'.join(self.errors) + return "\n".join(self.errors) def json_diff(d1, d2): @@ -74,12 +75,12 @@ def json_diff(d1, d2): Returns a string with the difference between JSON data. """ json_format_opts = { - 'indent': 4, - 'sort_keys': True, + "indent": 4, + "sort_keys": True, } dstr1 = json.dumps(d1, **json_format_opts) dstr2 = json.dumps(d2, **json_format_opts) - return difflines(dstr2, dstr1, title1='Expected value', title2='Current value', n=0) + return difflines(dstr2, dstr1, title1="Expected value", title2="Current value", n=0) def _json_list_cmp(list1, list2, parent, result): @@ -87,18 +88,21 @@ def _json_list_cmp(list1, list2, parent, result): # Check second list2 type if not isinstance(list1, type([])) or not isinstance(list2, type([])): result.add_error( - '{} has different type than expected '.format(parent) + - '(have {}, expected {}):\n{}'.format( - type(list1), type(list2), json_diff(list1, list2))) + "{} has different type than expected ".format(parent) + + "(have {}, expected {}):\n{}".format( + type(list1), type(list2), json_diff(list1, list2) + ) + ) return # Check list size if len(list2) > len(list1): result.add_error( - '{} too few items '.format(parent) + - '(have {}, expected {}:\n {})'.format( - len(list1), len(list2), - json_diff(list1, list2))) + "{} too few items ".format(parent) + + "(have {}, expected {}:\n {})".format( + len(list1), len(list2), json_diff(list1, list2) + ) + ) return # List all unmatched items errors @@ -106,7 +110,7 @@ def _json_list_cmp(list1, list2, parent, result): for expected in list2: matched = False for value in list1: - if json_cmp({'json': value}, {'json': expected}) is None: + if json_cmp({"json": value}, {"json": expected}) is None: matched = True break @@ -116,8 +120,8 @@ def _json_list_cmp(list1, list2, parent, result): # If there are unmatched items, error out. if unmatched: result.add_error( - '{} value is different (\n{})'.format( - parent, json_diff(list1, list2))) + "{} value is different (\n{})".format(parent, json_diff(list1, list2)) + ) def json_cmp(d1, d2): @@ -131,7 +135,7 @@ def json_cmp(d1, d2): Note: key absence can be tested by adding a key with value `None`. """ - squeue = [(d1, d2, 'json')] + squeue = [(d1, d2, "json")] result = json_cmp_result() for s in squeue: @@ -150,23 +154,33 @@ def json_cmp(d1, d2): s2_req = set([key for key in nd2 if nd2[key] is not None]) diff = s2_req - s1 if diff != set({}): - result.add_error('expected key(s) {} in {} (have {}):\n{}'.format( - str(list(diff)), parent, str(list(s1)), json_diff(nd1, nd2))) + result.add_error( + "expected key(s) {} in {} (have {}):\n{}".format( + str(list(diff)), parent, str(list(s1)), json_diff(nd1, nd2) + ) + ) for key in s2.intersection(s1): # Test for non existence of key in d2 if nd2[key] is None: - result.add_error('"{}" should not exist in {} (have {}):\n{}'.format( - key, parent, str(s1), json_diff(nd1[key], nd2[key]))) + result.add_error( + '"{}" should not exist in {} (have {}):\n{}'.format( + key, parent, str(s1), json_diff(nd1[key], nd2[key]) + ) + ) continue # If nd1 key is a dict, we have to recurse in it later. if isinstance(nd2[key], type({})): if not isinstance(nd1[key], type({})): result.add_error( - '{}["{}"] has different type than expected '.format(parent, key) + - '(have {}, expected {}):\n{}'.format( - type(nd1[key]), type(nd2[key]), json_diff(nd1[key], nd2[key]))) + '{}["{}"] has different type than expected '.format(parent, key) + + "(have {}, expected {}):\n{}".format( + type(nd1[key]), + type(nd2[key]), + json_diff(nd1[key], nd2[key]), + ) + ) continue nparent = '{}["{}"]'.format(parent, key) squeue.append((nd1[key], nd2[key], nparent)) @@ -181,7 +195,9 @@ def json_cmp(d1, d2): if nd1[key] != nd2[key]: result.add_error( '{}["{}"] value is different (\n{})'.format( - parent, key, json_diff(nd1[key], nd2[key]))) + parent, key, json_diff(nd1[key], nd2[key]) + ) + ) continue if result.has_errors(): @@ -194,10 +210,12 @@ def router_output_cmp(router, cmd, expected): """ Runs `cmd` in router and compares the output with `expected`. """ - return difflines(normalize_text(router.vtysh_cmd(cmd)), - normalize_text(expected), - title1="Current output", - title2="Expected output") + return difflines( + normalize_text(router.vtysh_cmd(cmd)), + normalize_text(expected), + title1="Current output", + title2="Expected output", + ) def router_json_cmp(router, cmd, data): @@ -232,7 +250,9 @@ def run_and_expect(func, what, count=20, wait=3): logger.info( "'{}' polling started (interval {} secs, maximum wait {} secs)".format( - func_name, wait, int(wait * count))) + func_name, wait, int(wait * count) + ) + ) while count > 0: result = func() @@ -242,13 +262,17 @@ def run_and_expect(func, what, count=20, wait=3): continue end_time = time.time() - logger.info("'{}' succeeded after {:.2f} seconds".format( - func_name, end_time - start_time)) + logger.info( + "'{}' succeeded after {:.2f} seconds".format( + func_name, end_time - start_time + ) + ) return (True, result) end_time = time.time() - logger.error("'{}' failed after {:.2f} seconds".format( - func_name, end_time - start_time)) + logger.error( + "'{}' failed after {:.2f} seconds".format(func_name, end_time - start_time) + ) return (False, result) @@ -273,12 +297,16 @@ def run_and_expect_type(func, etype, count=20, wait=3, avalue=None): logger.info( "'{}' polling started (interval {} secs, maximum wait {} secs)".format( - func_name, wait, int(wait * count))) + func_name, wait, int(wait * count) + ) + ) while count > 0: result = func() if not isinstance(result, etype): - logger.debug("Expected result type '{}' got '{}' instead".format(etype, type(result))) + logger.debug( + "Expected result type '{}' got '{}' instead".format(etype, type(result)) + ) time.sleep(wait) count -= 1 continue @@ -290,13 +318,17 @@ def run_and_expect_type(func, etype, count=20, wait=3, avalue=None): continue end_time = time.time() - logger.info("'{}' succeeded after {:.2f} seconds".format( - func_name, end_time - start_time)) + logger.info( + "'{}' succeeded after {:.2f} seconds".format( + func_name, end_time - start_time + ) + ) return (True, result) end_time = time.time() - logger.error("'{}' failed after {:.2f} seconds".format( - func_name, end_time - start_time)) + logger.error( + "'{}' failed after {:.2f} seconds".format(func_name, end_time - start_time) + ) return (False, result) @@ -305,12 +337,15 @@ def int2dpid(dpid): try: dpid = hex(dpid)[2:] - dpid = '0'*(16-len(dpid))+dpid + dpid = "0" * (16 - len(dpid)) + dpid return dpid except IndexError: - raise Exception('Unable to derive default datapath ID - ' - 'please either specify a dpid or use a ' - 'canonical switch name such as s23.') + raise Exception( + "Unable to derive default datapath ID - " + "please either specify a dpid or use a " + "canonical switch name such as s23." + ) + def pid_exists(pid): "Check whether pid exists in the current process table." @@ -333,70 +368,78 @@ def pid_exists(pid): else: return True + def get_textdiff(text1, text2, title1="", title2="", **opts): "Returns empty string if same or formatted diff" - diff = '\n'.join(difflib.unified_diff(text1, text2, - fromfile=title1, tofile=title2, **opts)) + diff = "\n".join( + difflib.unified_diff(text1, text2, fromfile=title1, tofile=title2, **opts) + ) # Clean up line endings diff = os.linesep.join([s for s in diff.splitlines() if s]) return diff -def difflines(text1, text2, title1='', title2='', **opts): + +def difflines(text1, text2, title1="", title2="", **opts): "Wrapper for get_textdiff to avoid string transformations." - text1 = ('\n'.join(text1.rstrip().splitlines()) + '\n').splitlines(1) - text2 = ('\n'.join(text2.rstrip().splitlines()) + '\n').splitlines(1) + text1 = ("\n".join(text1.rstrip().splitlines()) + "\n").splitlines(1) + text2 = ("\n".join(text2.rstrip().splitlines()) + "\n").splitlines(1) return get_textdiff(text1, text2, title1, title2, **opts) + def get_file(content): """ Generates a temporary file in '/tmp' with `content` and returns the file name. """ - fde = tempfile.NamedTemporaryFile(mode='w', delete=False) + fde = tempfile.NamedTemporaryFile(mode="w", delete=False) fname = fde.name fde.write(content) fde.close() return fname + def normalize_text(text): """ Strips formating spaces/tabs, carriage returns and trailing whitespace. """ - text = re.sub(r'[ \t]+', ' ', text) - text = re.sub(r'\r', '', text) + text = re.sub(r"[ \t]+", " ", text) + text = re.sub(r"\r", "", text) # Remove whitespace in the middle of text. - text = re.sub(r'[ \t]+\n', '\n', text) + text = re.sub(r"[ \t]+\n", "\n", text) # Remove whitespace at the end of the text. text = text.rstrip() return text + def module_present_linux(module, load): """ Returns whether `module` is present. If `load` is true, it will try to load it via modprobe. """ - with open('/proc/modules', 'r') as modules_file: - if module.replace('-','_') in modules_file.read(): + with open("/proc/modules", "r") as modules_file: + if module.replace("-", "_") in modules_file.read(): return True - cmd = '/sbin/modprobe {}{}'.format('' if load else '-n ', - module) + cmd = "/sbin/modprobe {}{}".format("" if load else "-n ", module) if os.system(cmd) != 0: return False else: return True + def module_present_freebsd(module, load): return True + def module_present(module, load=True): if sys.platform.startswith("linux"): return module_present_linux(module, load) elif sys.platform.startswith("freebsd"): return module_present_freebsd(module, load) + def version_cmp(v1, v2): """ Compare two version strings and returns: @@ -407,15 +450,15 @@ def version_cmp(v1, v2): Raises `ValueError` if versions are not well formated. """ - vregex = r'(?P\d+(\.(\d+))*)' + vregex = r"(?P\d+(\.(\d+))*)" v1m = re.match(vregex, v1) v2m = re.match(vregex, v2) if v1m is None or v2m is None: raise ValueError("got a invalid version string") # Split values - v1g = v1m.group('whole').split('.') - v2g = v2m.group('whole').split('.') + v1g = v1m.group("whole").split(".") + v2g = v2m.group("whole").split(".") # Get the longest version string vnum = len(v1g) @@ -452,35 +495,42 @@ def version_cmp(v1, v2): return -1 return 0 + def interface_set_status(node, ifacename, ifaceaction=False, vrf_name=None): if ifaceaction: - str_ifaceaction = 'no shutdown' + str_ifaceaction = "no shutdown" else: - str_ifaceaction = 'shutdown' + str_ifaceaction = "shutdown" if vrf_name == None: - cmd = 'vtysh -c \"configure terminal\" -c \"interface {0}\" -c \"{1}\"'.format(ifacename, str_ifaceaction) + cmd = 'vtysh -c "configure terminal" -c "interface {0}" -c "{1}"'.format( + ifacename, str_ifaceaction + ) else: - cmd = 'vtysh -c \"configure terminal\" -c \"interface {0} vrf {1}\" -c \"{2}\"'.format(ifacename, vrf_name, str_ifaceaction) + cmd = 'vtysh -c "configure terminal" -c "interface {0} vrf {1}" -c "{2}"'.format( + ifacename, vrf_name, str_ifaceaction + ) node.run(cmd) + def ip4_route_zebra(node, vrf_name=None): """ Gets an output of 'show ip route' command. It can be used with comparing the output to a reference """ if vrf_name == None: - tmp = node.vtysh_cmd('show ip route') + tmp = node.vtysh_cmd("show ip route") else: - tmp = node.vtysh_cmd('show ip route vrf {0}'.format(vrf_name)) + tmp = node.vtysh_cmd("show ip route vrf {0}".format(vrf_name)) output = re.sub(r" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", tmp) lines = output.splitlines() header_found = False while lines and (not lines[0].strip() or not header_found): - if '> - selected route' in lines[0]: + if "> - selected route" in lines[0]: header_found = True lines = lines[1:] - return '\n'.join(lines) + return "\n".join(lines) + def ip6_route_zebra(node, vrf_name=None): """ @@ -489,40 +539,42 @@ def ip6_route_zebra(node, vrf_name=None): """ if vrf_name == None: - tmp = node.vtysh_cmd('show ipv6 route') + tmp = node.vtysh_cmd("show ipv6 route") else: - tmp = node.vtysh_cmd('show ipv6 route vrf {0}'.format(vrf_name)) + tmp = node.vtysh_cmd("show ipv6 route vrf {0}".format(vrf_name)) # Mask out timestamp output = re.sub(r" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", tmp) # Mask out the link-local addresses - output = re.sub(r'fe80::[^ ]+,', 'fe80::XXXX:XXXX:XXXX:XXXX,', output) + output = re.sub(r"fe80::[^ ]+,", "fe80::XXXX:XXXX:XXXX:XXXX,", output) lines = output.splitlines() header_found = False while lines and (not lines[0].strip() or not header_found): - if '> - selected route' in lines[0]: + if "> - selected route" in lines[0]: header_found = True lines = lines[1:] - return '\n'.join(lines) + return "\n".join(lines) def proto_name_to_number(protocol): return { - 'bgp': '186', - 'isis': '187', - 'ospf': '188', - 'rip': '189', - 'ripng': '190', - 'nhrp': '191', - 'eigrp': '192', - 'ldp': '193', - 'sharp': '194', - 'pbr': '195', - 'static': '196' - }.get(protocol, protocol) # default return same as input + "bgp": "186", + "isis": "187", + "ospf": "188", + "rip": "189", + "ripng": "190", + "nhrp": "191", + "eigrp": "192", + "ldp": "193", + "sharp": "194", + "pbr": "195", + "static": "196", + }.get( + protocol, protocol + ) # default return same as input def ip4_route(node): @@ -543,28 +595,29 @@ def ip4_route(node): } } """ - output = normalize_text(node.run('ip route')).splitlines() + output = normalize_text(node.run("ip route")).splitlines() result = {} for line in output: - columns = line.split(' ') + columns = line.split(" ") route = result[columns[0]] = {} prev = None for column in columns: - if prev == 'dev': - route['dev'] = column - if prev == 'via': - route['via'] = column - if prev == 'proto': + if prev == "dev": + route["dev"] = column + if prev == "via": + route["via"] = column + if prev == "proto": # translate protocol names back to numbers - route['proto'] = proto_name_to_number(column) - if prev == 'metric': - route['metric'] = column - if prev == 'scope': - route['scope'] = column + route["proto"] = proto_name_to_number(column) + if prev == "metric": + route["metric"] = column + if prev == "scope": + route["scope"] = column prev = column return result + def ip6_route(node): """ Gets a structured return of the command 'ip -6 route'. It can be used in @@ -582,80 +635,103 @@ def ip6_route(node): } } """ - output = normalize_text(node.run('ip -6 route')).splitlines() + output = normalize_text(node.run("ip -6 route")).splitlines() result = {} for line in output: - columns = line.split(' ') + columns = line.split(" ") route = result[columns[0]] = {} prev = None for column in columns: - if prev == 'dev': - route['dev'] = column - if prev == 'via': - route['via'] = column - if prev == 'proto': + if prev == "dev": + route["dev"] = column + if prev == "via": + route["via"] = column + if prev == "proto": # translate protocol names back to numbers - route['proto'] = proto_name_to_number(column) - if prev == 'metric': - route['metric'] = column - if prev == 'pref': - route['pref'] = column + route["proto"] = proto_name_to_number(column) + if prev == "metric": + route["metric"] = column + if prev == "pref": + route["pref"] = column prev = column return result + def sleep(amount, reason=None): """ Sleep wrapper that registers in the log the amount of sleep """ if reason is None: - logger.info('Sleeping for {} seconds'.format(amount)) + logger.info("Sleeping for {} seconds".format(amount)) else: - logger.info(reason + ' ({} seconds)'.format(amount)) + logger.info(reason + " ({} seconds)".format(amount)) time.sleep(amount) + def checkAddressSanitizerError(output, router, component): "Checks for AddressSanitizer in output. If found, then logs it and returns true, false otherwise" - addressSantizerError = re.search('(==[0-9]+==)ERROR: AddressSanitizer: ([^\s]*) ', output) + addressSantizerError = re.search( + "(==[0-9]+==)ERROR: AddressSanitizer: ([^\s]*) ", output + ) if addressSantizerError: - sys.stderr.write("%s: %s triggered an exception by AddressSanitizer\n" % (router, component)) + sys.stderr.write( + "%s: %s triggered an exception by AddressSanitizer\n" % (router, component) + ) # Sanitizer Error found in log pidMark = addressSantizerError.group(1) - addressSantizerLog = re.search('%s(.*)%s' % (pidMark, pidMark), output, re.DOTALL) + addressSantizerLog = re.search( + "%s(.*)%s" % (pidMark, pidMark), output, re.DOTALL + ) if addressSantizerLog: - callingTest = os.path.basename(sys._current_frames().values()[0].f_back.f_back.f_globals['__file__']) + callingTest = os.path.basename( + sys._current_frames().values()[0].f_back.f_back.f_globals["__file__"] + ) callingProc = sys._getframe(2).f_code.co_name with open("/tmp/AddressSanitzer.txt", "a") as addrSanFile: - sys.stderr.write('\n'.join(addressSantizerLog.group(1).splitlines()) + '\n') + sys.stderr.write( + "\n".join(addressSantizerLog.group(1).splitlines()) + "\n" + ) addrSanFile.write("## Error: %s\n\n" % addressSantizerError.group(2)) - addrSanFile.write("### AddressSanitizer error in topotest `%s`, test `%s`, router `%s`\n\n" % (callingTest, callingProc, router)) - addrSanFile.write(' '+ '\n '.join(addressSantizerLog.group(1).splitlines()) + '\n') + addrSanFile.write( + "### AddressSanitizer error in topotest `%s`, test `%s`, router `%s`\n\n" + % (callingTest, callingProc, router) + ) + addrSanFile.write( + " " + + "\n ".join(addressSantizerLog.group(1).splitlines()) + + "\n" + ) addrSanFile.write("\n---------------\n") return True return False + def addRouter(topo, name): "Adding a FRRouter (or Quagga) to Topology" - MyPrivateDirs = ['/etc/frr', - '/etc/quagga', - '/var/run/frr', - '/var/run/quagga', - '/var/log'] + MyPrivateDirs = [ + "/etc/frr", + "/etc/quagga", + "/var/run/frr", + "/var/run/quagga", + "/var/log", + ] if sys.platform.startswith("linux"): return topo.addNode(name, cls=LinuxRouter, privateDirs=MyPrivateDirs) elif sys.platform.startswith("freebsd"): return topo.addNode(name, cls=FreeBSDRouter, privateDirs=MyPrivateDirs) + def set_sysctl(node, sysctl, value): "Set a sysctl value and return None on success or an error string" - valuestr = '{}'.format(value) + valuestr = "{}".format(value) command = "sysctl {0}={1}".format(sysctl, valuestr) cmdret = node.cmd(command) - matches = re.search(r'([^ ]+) = ([^\s]+)', cmdret) + matches = re.search(r"([^ ]+) = ([^\s]+)", cmdret) if matches is None: return cmdret if matches.group(1) != sysctl: @@ -665,6 +741,7 @@ def set_sysctl(node, sysctl, value): return None + def assert_sysctl(node, sysctl, value): "Set and assert that the sysctl is set with the specified value." assert set_sysctl(node, sysctl, value) is None @@ -675,65 +752,81 @@ class Router(Node): def __init__(self, name, **params): super(Router, self).__init__(name, **params) - self.logdir = params.get('logdir') + self.logdir = params.get("logdir") # Backward compatibility: # Load configuration defaults like topogen. - self.config_defaults = configparser.ConfigParser({ - 'verbosity': 'info', - 'frrdir': '/usr/lib/frr', - 'quaggadir': '/usr/lib/quagga', - 'routertype': 'frr', - 'memleak_path': None, - }) + self.config_defaults = configparser.ConfigParser( + { + "verbosity": "info", + "frrdir": "/usr/lib/frr", + "quaggadir": "/usr/lib/quagga", + "routertype": "frr", + "memleak_path": None, + } + ) self.config_defaults.read( - os.path.join(os.path.dirname(os.path.realpath(__file__)), - '../pytest.ini') + os.path.join(os.path.dirname(os.path.realpath(__file__)), "../pytest.ini") ) # If this topology is using old API and doesn't have logdir # specified, then attempt to generate an unique logdir. if self.logdir is None: - cur_test = os.environ['PYTEST_CURRENT_TEST'] - self.logdir = ('/tmp/topotests/' + - cur_test[0:cur_test.find(".py")].replace('/', '.')) + cur_test = os.environ["PYTEST_CURRENT_TEST"] + self.logdir = "/tmp/topotests/" + cur_test[ + 0 : cur_test.find(".py") + ].replace("/", ".") # If the logdir is not created, then create it and set the # appropriated permissions. if not os.path.isdir(self.logdir): - os.system('mkdir -p ' + self.logdir + '/' + name) - os.system('chmod -R go+rw /tmp/topotests') + os.system("mkdir -p " + self.logdir + "/" + name) + os.system("chmod -R go+rw /tmp/topotests") self.daemondir = None self.hasmpls = False - self.routertype = 'frr' - self.daemons = {'zebra': 0, 'ripd': 0, 'ripngd': 0, 'ospfd': 0, - 'ospf6d': 0, 'isisd': 0, 'bgpd': 0, 'pimd': 0, - 'ldpd': 0, 'eigrpd': 0, 'nhrpd': 0, 'staticd': 0, - 'bfdd': 0, 'sharpd': 0} - self.daemons_options = {'zebra': ''} + self.routertype = "frr" + self.daemons = { + "zebra": 0, + "ripd": 0, + "ripngd": 0, + "ospfd": 0, + "ospf6d": 0, + "isisd": 0, + "bgpd": 0, + "pimd": 0, + "ldpd": 0, + "eigrpd": 0, + "nhrpd": 0, + "staticd": 0, + "bfdd": 0, + "sharpd": 0, + } + self.daemons_options = {"zebra": ""} self.reportCores = True self.version = None def _config_frr(self, **params): "Configure FRR binaries" - self.daemondir = params.get('frrdir') + self.daemondir = params.get("frrdir") if self.daemondir is None: - self.daemondir = self.config_defaults.get('topogen', 'frrdir') + self.daemondir = self.config_defaults.get("topogen", "frrdir") - zebra_path = os.path.join(self.daemondir, 'zebra') + zebra_path = os.path.join(self.daemondir, "zebra") if not os.path.isfile(zebra_path): raise Exception("FRR zebra binary doesn't exist at {}".format(zebra_path)) def _config_quagga(self, **params): "Configure Quagga binaries" - self.daemondir = params.get('quaggadir') + self.daemondir = params.get("quaggadir") if self.daemondir is None: - self.daemondir = self.config_defaults.get('topogen', 'quaggadir') + self.daemondir = self.config_defaults.get("topogen", "quaggadir") - zebra_path = os.path.join(self.daemondir, 'zebra') + zebra_path = os.path.join(self.daemondir, "zebra") if not os.path.isfile(zebra_path): - raise Exception("Quagga zebra binary doesn't exist at {}".format(zebra_path)) + raise Exception( + "Quagga zebra binary doesn't exist at {}".format(zebra_path) + ) # pylint: disable=W0221 # Some params are only meaningful for the parent class. @@ -741,28 +834,27 @@ class Router(Node): super(Router, self).config(**params) # User did not specify the daemons directory, try to autodetect it. - self.daemondir = params.get('daemondir') + self.daemondir = params.get("daemondir") if self.daemondir is None: - self.routertype = params.get('routertype', - self.config_defaults.get( - 'topogen', - 'routertype')) - if self.routertype == 'quagga': + self.routertype = params.get( + "routertype", self.config_defaults.get("topogen", "routertype") + ) + if self.routertype == "quagga": self._config_quagga(**params) else: self._config_frr(**params) else: # Test the provided path - zpath = os.path.join(self.daemondir, 'zebra') + zpath = os.path.join(self.daemondir, "zebra") if not os.path.isfile(zpath): - raise Exception('No zebra binary found in {}'.format(zpath)) + raise Exception("No zebra binary found in {}".format(zpath)) # Allow user to specify routertype when the path was specified. - if params.get('routertype') is not None: - self.routertype = params.get('routertype') + if params.get("routertype") is not None: + self.routertype = params.get("routertype") - self.cmd('ulimit -c unlimited') + self.cmd("ulimit -c unlimited") # Set ownership of config files - self.cmd('chown {0}:{0}vty /etc/{0}'.format(self.routertype)) + self.cmd("chown {0}:{0}vty /etc/{0}".format(self.routertype)) def terminate(self): # Delete Running Quagga or FRR Daemons @@ -772,62 +864,66 @@ class Router(Node): # self.cmd('kill -7 `cat %s`' % d.rstrip()) # self.waitOutput() # Disable forwarding - set_sysctl(self, 'net.ipv4.ip_forward', 0) - set_sysctl(self, 'net.ipv6.conf.all.forwarding', 0) + set_sysctl(self, "net.ipv4.ip_forward", 0) + set_sysctl(self, "net.ipv6.conf.all.forwarding", 0) super(Router, self).terminate() - os.system('chmod -R go+rw /tmp/topotests') + os.system("chmod -R go+rw /tmp/topotests") - def stopRouter(self, wait=True, assertOnError=True, minErrorVersion='5.1'): + def stopRouter(self, wait=True, assertOnError=True, minErrorVersion="5.1"): # Stop Running Quagga or FRR Daemons - rundaemons = self.cmd('ls -1 /var/run/%s/*.pid' % self.routertype) + rundaemons = self.cmd("ls -1 /var/run/%s/*.pid" % self.routertype) errors = "" if re.search(r"No such file or directory", rundaemons): return errors if rundaemons is not None: numRunning = 0 for d in StringIO.StringIO(rundaemons): - daemonpid = self.cmd('cat %s' % d.rstrip()).rstrip() - if (daemonpid.isdigit() and pid_exists(int(daemonpid))): - logger.info('{}: stopping {}'.format( - self.name, - os.path.basename(d.rstrip().rsplit(".", 1)[0]) - )) - self.cmd('kill -TERM %s' % daemonpid) + daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip() + if daemonpid.isdigit() and pid_exists(int(daemonpid)): + logger.info( + "{}: stopping {}".format( + self.name, os.path.basename(d.rstrip().rsplit(".", 1)[0]) + ) + ) + self.cmd("kill -TERM %s" % daemonpid) self.waitOutput() if pid_exists(int(daemonpid)): numRunning += 1 if wait and numRunning > 0: - sleep(2, '{}: waiting for daemons stopping'.format(self.name)) + sleep(2, "{}: waiting for daemons stopping".format(self.name)) # 2nd round of kill if daemons didn't exit for d in StringIO.StringIO(rundaemons): - daemonpid = self.cmd('cat %s' % d.rstrip()).rstrip() - if (daemonpid.isdigit() and pid_exists(int(daemonpid))): - logger.info('{}: killing {}'.format( - self.name, - os.path.basename(d.rstrip().rsplit(".", 1)[0]) - )) - self.cmd('kill -7 %s' % daemonpid) + daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip() + if daemonpid.isdigit() and pid_exists(int(daemonpid)): + logger.info( + "{}: killing {}".format( + self.name, + os.path.basename(d.rstrip().rsplit(".", 1)[0]), + ) + ) + self.cmd("kill -7 %s" % daemonpid) self.waitOutput() - self.cmd('rm -- {}'.format(d.rstrip())) + self.cmd("rm -- {}".format(d.rstrip())) if wait: - errors = self.checkRouterCores(reportOnce=True) - if self.checkRouterVersion('<', minErrorVersion): - #ignore errors in old versions - errors = "" - if assertOnError and len(errors) > 0: - assert "Errors found - details follow:" == 0, errors + errors = self.checkRouterCores(reportOnce=True) + if self.checkRouterVersion("<", minErrorVersion): + # ignore errors in old versions + errors = "" + if assertOnError and len(errors) > 0: + assert "Errors found - details follow:" == 0, errors return errors def removeIPs(self): for interface in self.intfNames(): - self.cmd('ip address flush', interface) + self.cmd("ip address flush", interface) def checkCapability(self, daemon, param): if param is not None: daemon_path = os.path.join(self.daemondir, daemon) - daemon_search_option = param.replace('-','') - output = self.cmd('{0} -h | grep {1}'.format( - daemon_path, daemon_search_option)) + daemon_search_option = param.replace("-", "") + output = self.cmd( + "{0} -h | grep {1}".format(daemon_path, daemon_search_option) + ) if daemon_search_option not in output: return False return True @@ -839,74 +935,89 @@ class Router(Node): if param is not None: self.daemons_options[daemon] = param if source is None: - self.cmd('touch /etc/%s/%s.conf' % (self.routertype, daemon)) + self.cmd("touch /etc/%s/%s.conf" % (self.routertype, daemon)) self.waitOutput() else: - self.cmd('cp %s /etc/%s/%s.conf' % (source, self.routertype, daemon)) + self.cmd("cp %s /etc/%s/%s.conf" % (source, self.routertype, daemon)) self.waitOutput() - self.cmd('chmod 640 /etc/%s/%s.conf' % (self.routertype, daemon)) + self.cmd("chmod 640 /etc/%s/%s.conf" % (self.routertype, daemon)) self.waitOutput() - self.cmd('chown %s:%s /etc/%s/%s.conf' % (self.routertype, self.routertype, self.routertype, daemon)) + self.cmd( + "chown %s:%s /etc/%s/%s.conf" + % (self.routertype, self.routertype, self.routertype, daemon) + ) self.waitOutput() - if (daemon == 'zebra') and (self.daemons['staticd'] == 0): + if (daemon == "zebra") and (self.daemons["staticd"] == 0): # Add staticd with zebra - if it exists - staticd_path = os.path.join(self.daemondir, 'staticd') + staticd_path = os.path.join(self.daemondir, "staticd") if os.path.isfile(staticd_path): - self.daemons['staticd'] = 1 - self.daemons_options['staticd'] = '' + self.daemons["staticd"] = 1 + self.daemons_options["staticd"] = "" # Auto-Started staticd has no config, so it will read from zebra config else: - logger.info('No daemon {} known'.format(daemon)) + logger.info("No daemon {} known".format(daemon)) # print "Daemons after:", self.daemons def startRouter(self, tgen=None): # Disable integrated-vtysh-config - self.cmd('echo "no service integrated-vtysh-config" >> /etc/%s/vtysh.conf' % self.routertype) - self.cmd('chown %s:%svty /etc/%s/vtysh.conf' % (self.routertype, self.routertype, self.routertype)) + self.cmd( + 'echo "no service integrated-vtysh-config" >> /etc/%s/vtysh.conf' + % self.routertype + ) + self.cmd( + "chown %s:%svty /etc/%s/vtysh.conf" + % (self.routertype, self.routertype, self.routertype) + ) # TODO remove the following lines after all tests are migrated to Topogen. # Try to find relevant old logfiles in /tmp and delete them - map(os.remove, glob.glob('{}/{}/*.log'.format(self.logdir, self.name))) + map(os.remove, glob.glob("{}/{}/*.log".format(self.logdir, self.name))) # Remove old core files - map(os.remove, glob.glob('{}/{}/*.dmp'.format(self.logdir, self.name))) + map(os.remove, glob.glob("{}/{}/*.dmp".format(self.logdir, self.name))) # Remove IP addresses from OS first - we have them in zebra.conf self.removeIPs() # If ldp is used, check for LDP to be compiled and Linux Kernel to be 4.5 or higher # No error - but return message and skip all the tests - if self.daemons['ldpd'] == 1: - ldpd_path = os.path.join(self.daemondir, 'ldpd') + if self.daemons["ldpd"] == 1: + ldpd_path = os.path.join(self.daemondir, "ldpd") if not os.path.isfile(ldpd_path): logger.info("LDP Test, but no ldpd compiled or installed") return "LDP Test, but no ldpd compiled or installed" - if version_cmp(platform.release(), '4.5') < 0: + if version_cmp(platform.release(), "4.5") < 0: logger.info("LDP Test need Linux Kernel 4.5 minimum") return "LDP Test need Linux Kernel 4.5 minimum" # Check if have mpls if tgen != None: self.hasmpls = tgen.hasmpls if self.hasmpls != True: - logger.info("LDP/MPLS Tests will be skipped, platform missing module(s)") + logger.info( + "LDP/MPLS Tests will be skipped, platform missing module(s)" + ) else: # Test for MPLS Kernel modules available self.hasmpls = False - if not module_present('mpls-router'): - logger.info('MPLS tests will not run (missing mpls-router kernel module)') - elif not module_present('mpls-iptunnel'): - logger.info('MPLS tests will not run (missing mpls-iptunnel kernel module)') + if not module_present("mpls-router"): + logger.info( + "MPLS tests will not run (missing mpls-router kernel module)" + ) + elif not module_present("mpls-iptunnel"): + logger.info( + "MPLS tests will not run (missing mpls-iptunnel kernel module)" + ) else: self.hasmpls = True if self.hasmpls != True: return "LDP/MPLS Tests need mpls kernel modules" - self.cmd('echo 100000 > /proc/sys/net/mpls/platform_labels') + self.cmd("echo 100000 > /proc/sys/net/mpls/platform_labels") - if self.daemons['eigrpd'] == 1: - eigrpd_path = os.path.join(self.daemondir, 'eigrpd') + if self.daemons["eigrpd"] == 1: + eigrpd_path = os.path.join(self.daemondir, "eigrpd") if not os.path.isfile(eigrpd_path): logger.info("EIGRP Test, but no eigrpd compiled or installed") return "EIGRP Test, but no eigrpd compiled or installed" - if self.daemons['bfdd'] == 1: - bfdd_path = os.path.join(self.daemondir, 'bfdd') + if self.daemons["bfdd"] == 1: + bfdd_path = os.path.join(self.daemondir, "bfdd") if not os.path.isfile(bfdd_path): logger.info("BFD Test, but no bfdd compiled or installed") return "BFD Test, but no bfdd compiled or installed" @@ -917,52 +1028,65 @@ class Router(Node): def restartRouter(self): # Starts actual daemons without init (ie restart) # cd to per node directory - self.cmd('cd {}/{}'.format(self.logdir, self.name)) - self.cmd('umask 000') - #Re-enable to allow for report per run + self.cmd("cd {}/{}".format(self.logdir, self.name)) + self.cmd("umask 000") + # Re-enable to allow for report per run self.reportCores = True if self.version == None: - self.version = self.cmd(os.path.join(self.daemondir, 'bgpd')+' -v').split()[2] - logger.info('{}: running version: {}'.format(self.name,self.version)) + self.version = self.cmd( + os.path.join(self.daemondir, "bgpd") + " -v" + ).split()[2] + logger.info("{}: running version: {}".format(self.name, self.version)) # Start Zebra first - if self.daemons['zebra'] == 1: - zebra_path = os.path.join(self.daemondir, 'zebra') - zebra_option = self.daemons_options['zebra'] - self.cmd('{0} {1} > zebra.out 2> zebra.err &'.format( - zebra_path, zebra_option, self.logdir, self.name - )) + if self.daemons["zebra"] == 1: + zebra_path = os.path.join(self.daemondir, "zebra") + zebra_option = self.daemons_options["zebra"] + self.cmd( + "{0} {1} > zebra.out 2> zebra.err &".format( + zebra_path, zebra_option, self.logdir, self.name + ) + ) self.waitOutput() - logger.debug('{}: {} zebra started'.format(self, self.routertype)) - sleep(1, '{}: waiting for zebra to start'.format(self.name)) + logger.debug("{}: {} zebra started".format(self, self.routertype)) + sleep(1, "{}: waiting for zebra to start".format(self.name)) # Start staticd next if required - if self.daemons['staticd'] == 1: - staticd_path = os.path.join(self.daemondir, 'staticd') - staticd_option = self.daemons_options['staticd'] - self.cmd('{0} {1} > staticd.out 2> staticd.err &'.format( - staticd_path, staticd_option, self.logdir, self.name - )) + if self.daemons["staticd"] == 1: + staticd_path = os.path.join(self.daemondir, "staticd") + staticd_option = self.daemons_options["staticd"] + self.cmd( + "{0} {1} > staticd.out 2> staticd.err &".format( + staticd_path, staticd_option, self.logdir, self.name + ) + ) self.waitOutput() - logger.debug('{}: {} staticd started'.format(self, self.routertype)) - # Fix Link-Local Addresses + logger.debug("{}: {} staticd started".format(self, self.routertype)) + # Fix Link-Local Addresses # Somehow (on Mininet only), Zebra removes the IPv6 Link-Local addresses on start. Fix this - self.cmd('for i in `ls /sys/class/net/` ; do mac=`cat /sys/class/net/$i/address`; IFS=\':\'; set $mac; unset IFS; ip address add dev $i scope link fe80::$(printf %02x $((0x$1 ^ 2)))$2:${3}ff:fe$4:$5$6/64; done') + self.cmd( + "for i in `ls /sys/class/net/` ; do mac=`cat /sys/class/net/$i/address`; IFS=':'; set $mac; unset IFS; ip address add dev $i scope link fe80::$(printf %02x $((0x$1 ^ 2)))$2:${3}ff:fe$4:$5$6/64; done" + ) # Now start all the other daemons for daemon in self.daemons: # Skip disabled daemons and zebra - if self.daemons[daemon] == 0 or daemon == 'zebra' or daemon == 'staticd': + if self.daemons[daemon] == 0 or daemon == "zebra" or daemon == "staticd": continue daemon_path = os.path.join(self.daemondir, daemon) - self.cmd('{0} {1} > {2}.out 2> {2}.err &'.format( - daemon_path, self.daemons_options.get(daemon, ''), daemon - )) + self.cmd( + "{0} {1} > {2}.out 2> {2}.err &".format( + daemon_path, self.daemons_options.get(daemon, ""), daemon + ) + ) self.waitOutput() - logger.debug('{}: {} {} started'.format(self, self.routertype, daemon)) + logger.debug("{}: {} {} started".format(self, self.routertype, daemon)) + def getStdErr(self, daemon): - return self.getLog('err', daemon) + return self.getLog("err", daemon) + def getStdOut(self, daemon): - return self.getLog('out', daemon) + return self.getLog("out", daemon) + def getLog(self, log, daemon): - return self.cmd('cat {}/{}/{}.{}'.format(self.logdir, self.name, daemon, log)) + return self.cmd("cat {}/{}/{}.{}".format(self.logdir, self.name, daemon, log)) def checkRouterCores(self, reportLeaks=True, reportOnce=False): if reportOnce and not self.reportCores: @@ -970,33 +1094,62 @@ class Router(Node): reportMade = False traces = "" for daemon in self.daemons: - if (self.daemons[daemon] == 1): + if self.daemons[daemon] == 1: # Look for core file - corefiles = glob.glob('{}/{}/{}_core*.dmp'.format( - self.logdir, self.name, daemon)) - if (len(corefiles) > 0): + corefiles = glob.glob( + "{}/{}/{}_core*.dmp".format(self.logdir, self.name, daemon) + ) + if len(corefiles) > 0: daemon_path = os.path.join(self.daemondir, daemon) - backtrace = subprocess.check_output([ - "gdb {} {} --batch -ex bt 2> /dev/null".format(daemon_path, corefiles[0]) - ], shell=True) - sys.stderr.write("\n%s: %s crashed. Core file found - Backtrace follows:\n" % (self.name, daemon)) + backtrace = subprocess.check_output( + [ + "gdb {} {} --batch -ex bt 2> /dev/null".format( + daemon_path, corefiles[0] + ) + ], + shell=True, + ) + sys.stderr.write( + "\n%s: %s crashed. Core file found - Backtrace follows:\n" + % (self.name, daemon) + ) sys.stderr.write("%s" % backtrace) - traces = traces + "\n%s: %s crashed. Core file found - Backtrace follows:\n%s" % (self.name, daemon, backtrace) + traces = ( + traces + + "\n%s: %s crashed. Core file found - Backtrace follows:\n%s" + % (self.name, daemon, backtrace) + ) reportMade = True elif reportLeaks: log = self.getStdErr(daemon) if "memstats" in log: - sys.stderr.write("%s: %s has memory leaks:\n" % (self.name, daemon)) - traces = traces + "\n%s: %s has memory leaks:\n" % (self.name, daemon) + sys.stderr.write( + "%s: %s has memory leaks:\n" % (self.name, daemon) + ) + traces = traces + "\n%s: %s has memory leaks:\n" % ( + self.name, + daemon, + ) log = re.sub("core_handler: ", "", log) - log = re.sub(r"(showing active allocations in memory group [a-zA-Z0-9]+)", r"\n ## \1", log) + log = re.sub( + r"(showing active allocations in memory group [a-zA-Z0-9]+)", + r"\n ## \1", + log, + ) log = re.sub("memstats: ", " ", log) sys.stderr.write(log) reportMade = True # Look for AddressSanitizer Errors and append to /tmp/AddressSanitzer.txt if found - if checkAddressSanitizerError(self.getStdErr(daemon), self.name, daemon): - sys.stderr.write("%s: Daemon %s killed by AddressSanitizer" % (self.name, daemon)) - traces = traces + "\n%s: Daemon %s killed by AddressSanitizer" % (self.name, daemon) + if checkAddressSanitizerError( + self.getStdErr(daemon), self.name, daemon + ): + sys.stderr.write( + "%s: Daemon %s killed by AddressSanitizer" % (self.name, daemon) + ) + traces = traces + "\n%s: Daemon %s killed by AddressSanitizer" % ( + self.name, + daemon, + ) reportMade = True if reportMade: self.reportCores = False @@ -1007,7 +1160,9 @@ class Router(Node): global fatal_error - daemonsRunning = self.cmd('vtysh -c "show logging" | grep "Logging configuration for"') + daemonsRunning = self.cmd( + 'vtysh -c "show logging" | grep "Logging configuration for"' + ) # Look for AddressSanitizer Errors in vtysh output and append to /tmp/AddressSanitzer.txt if found if checkAddressSanitizerError(daemonsRunning, self.name, "vtysh"): return "%s: vtysh killed by AddressSanitizer" % (self.name) @@ -1016,32 +1171,59 @@ class Router(Node): if (self.daemons[daemon] == 1) and not (daemon in daemonsRunning): sys.stderr.write("%s: Daemon %s not running\n" % (self.name, daemon)) if daemon is "staticd": - sys.stderr.write("You may have a copy of staticd installed but are attempting to test against\n") - sys.stderr.write("a version of FRR that does not have staticd, please cleanup the install dir\n") + sys.stderr.write( + "You may have a copy of staticd installed but are attempting to test against\n" + ) + sys.stderr.write( + "a version of FRR that does not have staticd, please cleanup the install dir\n" + ) # Look for core file - corefiles = glob.glob('{}/{}/{}_core*.dmp'.format( - self.logdir, self.name, daemon)) - if (len(corefiles) > 0): + corefiles = glob.glob( + "{}/{}/{}_core*.dmp".format(self.logdir, self.name, daemon) + ) + if len(corefiles) > 0: daemon_path = os.path.join(self.daemondir, daemon) - backtrace = subprocess.check_output([ - "gdb {} {} --batch -ex bt 2> /dev/null".format(daemon_path, corefiles[0]) - ], shell=True) - sys.stderr.write("\n%s: %s crashed. Core file found - Backtrace follows:\n" % (self.name, daemon)) + backtrace = subprocess.check_output( + [ + "gdb {} {} --batch -ex bt 2> /dev/null".format( + daemon_path, corefiles[0] + ) + ], + shell=True, + ) + sys.stderr.write( + "\n%s: %s crashed. Core file found - Backtrace follows:\n" + % (self.name, daemon) + ) sys.stderr.write("%s\n" % backtrace) else: # No core found - If we find matching logfile in /tmp, then print last 20 lines from it. - if os.path.isfile('{}/{}/{}.log'.format(self.logdir, self.name, daemon)): - log_tail = subprocess.check_output([ - "tail -n20 {}/{}/{}.log 2> /dev/null".format( - self.logdir, self.name, daemon) - ], shell=True) - sys.stderr.write("\nFrom %s %s %s log file:\n" % (self.routertype, self.name, daemon)) + if os.path.isfile( + "{}/{}/{}.log".format(self.logdir, self.name, daemon) + ): + log_tail = subprocess.check_output( + [ + "tail -n20 {}/{}/{}.log 2> /dev/null".format( + self.logdir, self.name, daemon + ) + ], + shell=True, + ) + sys.stderr.write( + "\nFrom %s %s %s log file:\n" + % (self.routertype, self.name, daemon) + ) sys.stderr.write("%s\n" % log_tail) # Look for AddressSanitizer Errors and append to /tmp/AddressSanitzer.txt if found - if checkAddressSanitizerError(self.getStdErr(daemon), self.name, daemon): - return "%s: Daemon %s not running - killed by AddressSanitizer" % (self.name, daemon) + if checkAddressSanitizerError( + self.getStdErr(daemon), self.name, daemon + ): + return "%s: Daemon %s not running - killed by AddressSanitizer" % ( + self.name, + daemon, + ) return "%s: Daemon %s not running" % (self.name, daemon) return "" @@ -1061,25 +1243,27 @@ class Router(Node): # Make sure we have version information first if self.version == None: - self.version = self.cmd(os.path.join(self.daemondir, 'bgpd')+' -v').split()[2] - logger.info('{}: running version: {}'.format(self.name,self.version)) + self.version = self.cmd( + os.path.join(self.daemondir, "bgpd") + " -v" + ).split()[2] + logger.info("{}: running version: {}".format(self.name, self.version)) rversion = self.version if rversion is None: return False result = version_cmp(rversion, version) - if cmpop == '>=': + if cmpop == ">=": return result >= 0 - if cmpop == '>': + if cmpop == ">": return result > 0 - if cmpop == '=': + if cmpop == "=": return result == 0 - if cmpop == '<': + if cmpop == "<": return result < 0 - if cmpop == '<': + if cmpop == "<": return result < 0 - if cmpop == '<=': + if cmpop == "<=": return result <= 0 def get_ipv6_linklocal(self): @@ -1087,37 +1271,41 @@ class Router(Node): linklocal = [] - ifaces = self.cmd('ip -6 address') + ifaces = self.cmd("ip -6 address") # Fix newlines (make them all the same) - ifaces = ('\n'.join(ifaces.splitlines()) + '\n').splitlines() - interface="" - ll_per_if_count=0 + ifaces = ("\n".join(ifaces.splitlines()) + "\n").splitlines() + interface = "" + ll_per_if_count = 0 for line in ifaces: - m = re.search('[0-9]+: ([^:@]+)[@if0-9:]+ <', line) + m = re.search("[0-9]+: ([^:@]+)[@if0-9:]+ <", line) if m: interface = m.group(1) ll_per_if_count = 0 - m = re.search('inet6 (fe80::[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+)[/0-9]* scope link', line) + m = re.search( + "inet6 (fe80::[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+)[/0-9]* scope link", + line, + ) if m: local = m.group(1) ll_per_if_count += 1 - if (ll_per_if_count > 1): + if ll_per_if_count > 1: linklocal += [["%s-%s" % (interface, ll_per_if_count), local]] else: linklocal += [[interface, local]] return linklocal + def daemon_available(self, daemon): "Check if specified daemon is installed (and for ldp if kernel supports MPLS)" daemon_path = os.path.join(self.daemondir, daemon) if not os.path.isfile(daemon_path): return False - if (daemon == 'ldpd'): - if version_cmp(platform.release(), '4.5') < 0: + if daemon == "ldpd": + if version_cmp(platform.release(), "4.5") < 0: return False - if not module_present('mpls-router', load=False): + if not module_present("mpls-router", load=False): return False - if not module_present('mpls-iptunnel', load=False): + if not module_present("mpls-iptunnel", load=False): return False return True @@ -1125,18 +1313,20 @@ class Router(Node): "Return the type of Router (frr or quagga)" return self.routertype + def report_memory_leaks(self, filename_prefix, testscript): "Report Memory Leaks to file prefixed with given string" leakfound = False filename = filename_prefix + re.sub(r"\.py", "", testscript) + ".txt" for daemon in self.daemons: - if (self.daemons[daemon] == 1): + if self.daemons[daemon] == 1: log = self.getStdErr(daemon) if "memstats" in log: # Found memory leak - logger.info('\nRouter {} {} StdErr Log:\n{}'.format( - self.name, daemon, log)) + logger.info( + "\nRouter {} {} StdErr Log:\n{}".format(self.name, daemon, log) + ) if not leakfound: leakfound = True # Check if file already exists @@ -1144,17 +1334,25 @@ class Router(Node): leakfile = open(filename, "a") if not fileexists: # New file - add header - leakfile.write("# Memory Leak Detection for topotest %s\n\n" % testscript) + leakfile.write( + "# Memory Leak Detection for topotest %s\n\n" + % testscript + ) leakfile.write("## Router %s\n" % self.name) leakfile.write("### Process %s\n" % daemon) log = re.sub("core_handler: ", "", log) - log = re.sub(r"(showing active allocations in memory group [a-zA-Z0-9]+)", r"\n#### \1\n", log) + log = re.sub( + r"(showing active allocations in memory group [a-zA-Z0-9]+)", + r"\n#### \1\n", + log, + ) log = re.sub("memstats: ", " ", log) leakfile.write(log) leakfile.write("\n") if leakfound: leakfile.close() + class LinuxRouter(Router): "A Linux Router Node with IPv4/IPv6 forwarding enabled." @@ -1164,25 +1362,26 @@ class LinuxRouter(Router): def config(self, **params): Router.config(self, **params) # Enable forwarding on the router - assert_sysctl(self, 'net.ipv4.ip_forward', 1) - assert_sysctl(self, 'net.ipv6.conf.all.forwarding', 1) + assert_sysctl(self, "net.ipv4.ip_forward", 1) + assert_sysctl(self, "net.ipv6.conf.all.forwarding", 1) # Enable coredumps - assert_sysctl(self, 'kernel.core_uses_pid', 1) - assert_sysctl(self, 'fs.suid_dumpable', 1) - #this applies to the kernel not the namespace... - #original on ubuntu 17.x, but apport won't save as in namespace + assert_sysctl(self, "kernel.core_uses_pid", 1) + assert_sysctl(self, "fs.suid_dumpable", 1) + # this applies to the kernel not the namespace... + # original on ubuntu 17.x, but apport won't save as in namespace # |/usr/share/apport/apport %p %s %c %d %P - corefile = '%e_core-sig_%s-pid_%p.dmp' - assert_sysctl(self, 'kernel.core_pattern', corefile) + corefile = "%e_core-sig_%s-pid_%p.dmp" + assert_sysctl(self, "kernel.core_pattern", corefile) def terminate(self): """ Terminate generic LinuxRouter Mininet instance """ - set_sysctl(self, 'net.ipv4.ip_forward', 0) - set_sysctl(self, 'net.ipv6.conf.all.forwarding', 0) + set_sysctl(self, "net.ipv4.ip_forward", 0) + set_sysctl(self, "net.ipv6.conf.all.forwarding", 0) Router.terminate(self) + class FreeBSDRouter(Router): "A FreeBSD Router Node with IPv4/IPv6 forwarding enabled." @@ -1194,5 +1393,5 @@ class LegacySwitch(OVSSwitch): "A Legacy Switch without OpenFlow" def __init__(self, name, **params): - OVSSwitch.__init__(self, name, failMode='standalone', **params) + OVSSwitch.__init__(self, name, failMode="standalone", **params) self.switchIP = None diff --git a/tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py b/tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py index 56cd42ea57..92cebfe0b6 100755 --- a/tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py +++ b/tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py @@ -32,53 +32,56 @@ from functools import partial # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Required to instantiate the topology builder class. from mininet.topo import Topo + # Import topogen and topotest helpers from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger + # and Finally pytest import pytest class OspfSrTopo(Topo): "Test topology builder" + def build(self): "Build function" tgen = get_topogen(self) # Check for mpls if tgen.hasmpls is not True: - tgen.set_error('MPLS not available, tests will be skipped') + tgen.set_error("MPLS not available, tests will be skipped") # Create 4 routers for routern in range(1, 5): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) # Interconect router 1 and 2 - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) # Interconect router 3 and 2 - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r3']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r2"]) # Interconect router 4 and 2 - switch = tgen.add_switch('s3') - switch.add_link(tgen.gears['r4']) - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r4"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): "Sets up the pytest environment" - logger.info('\n\n---- Starting OSPF Segment Routing tests ----\n') + logger.info("\n\n---- Starting OSPF Segment Routing tests ----\n") tgen = Topogen(OspfSrTopo, mod.__name__) tgen.start_topology() @@ -87,12 +90,10 @@ def setup_module(mod): for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_OSPF, - os.path.join(CWD, '{}/ospfd.conf'.format(rname)) + TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname)) ) # Initialize all routers. @@ -101,14 +102,15 @@ def setup_module(mod): # Verify that version, MPLS and Segment Routing are OK for router in router_list.values(): # Check for Version - if router.has_version('<', '4'): - tgen.set_error('Unsupported FRR version') + if router.has_version("<", "4"): + tgen.set_error("Unsupported FRR version") break # Check that Segment Routing is available output = tgen.gears[router.name].vtysh_cmd( - "show ip ospf database segment-routing json") + "show ip ospf database segment-routing json" + ) if output.find("Unknown") != -1: - tgen.set_error('Segment Routing is not available') + tgen.set_error("Segment Routing is not available") def teardown_module(mod): @@ -117,7 +119,8 @@ def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() - logger.info('\n\n---- OSPF Segment Routing tests End ----\n') + logger.info("\n\n---- OSPF Segment Routing tests End ----\n") + # Shared test function to validate expected output. def compare_ospf_srdb(rname, expected): @@ -126,11 +129,10 @@ def compare_ospf_srdb(rname, expected): and compare the obtained result with the expected output. """ tgen = get_topogen() - current = tgen.gears[rname].vtysh_cmd( - 'show ip ospf database segment-routing json') - return topotest.difflines(current, expected, - title1="Current output", - title2="Expected output") + current = tgen.gears[rname].vtysh_cmd("show ip ospf database segment-routing json") + return topotest.difflines( + current, expected, title1="Current output", title2="Expected output" + ) def compare_mpls_table(rname, expected): @@ -139,10 +141,10 @@ def compare_mpls_table(rname, expected): result with the expected output. """ tgen = get_topogen() - current = tgen.gears[rname].vtysh_cmd('show mpls table json') - return topotest.difflines(current, expected, - title1="Current output", - title2="Expected output") + current = tgen.gears[rname].vtysh_cmd("show mpls table json") + return topotest.difflines( + current, expected, title1="Current output", title2="Expected output" + ) def test_ospf_sr(): @@ -151,24 +153,23 @@ def test_ospf_sr(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('--- test OSPF Segment Routing Data Base ---') + logger.info("--- test OSPF Segment Routing Data Base ---") for rnum in range(1, 5): - router = 'r{}'.format(rnum) + router = "r{}".format(rnum) logger.info('\tRouter "%s"', router) # Load expected results from the command - reffile = os.path.join(CWD, '{}/ospf_srdb.json'.format(router)) + reffile = os.path.join(CWD, "{}/ospf_srdb.json".format(router)) expected = open(reffile).read() # Run test function until we get an result. Wait at most 60 seconds. test_func = partial(compare_ospf_srdb, router, expected) - result, diff = topotest.run_and_expect(test_func, '', - count=25, wait=3) - assert result, ( - 'OSPF did not start Segment Routing on {}:\n{}' - ).format(router, diff) + result, diff = topotest.run_and_expect(test_func, "", count=25, wait=3) + assert result, ("OSPF did not start Segment Routing on {}:\n{}").format( + router, diff + ) def test_ospf_kernel_route(): @@ -177,34 +178,34 @@ def test_ospf_kernel_route(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info('--- test OSPF Segment Routing MPLS tables ---') + logger.info("--- test OSPF Segment Routing MPLS tables ---") for rnum in range(1, 5): - router = 'r{}'.format(rnum) + router = "r{}".format(rnum) logger.info('\tRouter "%s"', router) # Load expected results from the command - reffile = os.path.join(CWD, '{}/zebra_mpls.json'.format(router)) + reffile = os.path.join(CWD, "{}/zebra_mpls.json".format(router)) expected = open(reffile).read() # Run test function until we get an result. Wait at most 60 seconds. test_func = partial(compare_mpls_table, router, expected) - result, diff = topotest.run_and_expect(test_func, '', - count=25, wait=3) - assert result, ( - 'OSPF did not properly instal MPLS table on {}:\n{}' - ).format(router, diff) + result, diff = topotest.run_and_expect(test_func, "", count=25, wait=3) + assert result, ("OSPF did not properly instal MPLS table on {}:\n{}").format( + router, diff + ) def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/ospf-topo1-vrf/test_ospf_topo1_vrf.py b/tests/topotests/ospf-topo1-vrf/test_ospf_topo1_vrf.py index fc4854454c..130d0c85f9 100755 --- a/tests/topotests/ospf-topo1-vrf/test_ospf_topo1_vrf.py +++ b/tests/topotests/ospf-topo1-vrf/test_ospf_topo1_vrf.py @@ -34,7 +34,7 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -45,33 +45,35 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from mininet.topo import Topo + class OSPFTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) # Create 3 routers for routern in range(1, 4): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) # Create a empty network for router 1 - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) # Create a empty network for router 2 - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) # Interconect router 1, 2 and 3 - switch = tgen.add_switch('s3') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) # Create empty netowrk for router3 - switch = tgen.add_switch('s4') - switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r3"]) def setup_module(mod): @@ -83,23 +85,26 @@ def setup_module(mod): # check for zebra capability for rname, router in router_list.iteritems(): - if router.check_capability( - TopoRouter.RD_ZEBRA, - '--vrfwnetns' - ) == False: - return pytest.skip('Skipping OSPF VRF NETNS feature. VRF NETNS backend not available on FRR') + if router.check_capability(TopoRouter.RD_ZEBRA, "--vrfwnetns") == False: + return pytest.skip( + "Skipping OSPF VRF NETNS feature. VRF NETNS backend not available on FRR" + ) - if os.system('ip netns list') != 0: - return pytest.skip('Skipping OSPF VRF NETNS Test. NETNS not available on System') + if os.system("ip netns list") != 0: + return pytest.skip( + "Skipping OSPF VRF NETNS Test. NETNS not available on System" + ) - logger.info('Testing with VRF Namespace support') + logger.info("Testing with VRF Namespace support") - cmds = ['if [ -e /var/run/netns/{0}-cust1 ] ; then ip netns del {0}-cust1 ; fi', - 'ip netns add {0}-cust1', - 'ip link set dev {0}-eth0 netns {0}-cust1', - 'ip netns exec {0}-cust1 ifconfig {0}-eth0 up', - 'ip link set dev {0}-eth1 netns {0}-cust1', - 'ip netns exec {0}-cust1 ifconfig {0}-eth1 up'] + cmds = [ + "if [ -e /var/run/netns/{0}-cust1 ] ; then ip netns del {0}-cust1 ; fi", + "ip netns add {0}-cust1", + "ip link set dev {0}-eth0 netns {0}-cust1", + "ip netns exec {0}-cust1 ifconfig {0}-eth0 up", + "ip link set dev {0}-eth1 netns {0}-cust1", + "ip netns exec {0}-cust1 ifconfig {0}-eth1 up", + ] for rname, router in router_list.iteritems(): @@ -109,19 +114,18 @@ def setup_module(mod): router.load_config( TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)), - '--vrfwnetns' + os.path.join(CWD, "{}/zebra.conf".format(rname)), + "--vrfwnetns", ) router.load_config( - TopoRouter.RD_OSPF, - os.path.join(CWD, '{}/ospfd.conf'.format(rname)) + TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname)) ) # Initialize all routers. tgen.start_router() for router in router_list.values(): - if router.has_version('<', '4.0'): - tgen.set_error('unsupported version') + if router.has_version("<", "4.0"): + tgen.set_error("unsupported version") def teardown_module(mod): @@ -130,16 +134,19 @@ def teardown_module(mod): # move back rx-eth0 to default VRF # delete rx-vrf - cmds = ['ip netns exec {0}-cust1 ip link set {0}-eth0 netns 1', - 'ip netns exec {0}-cust1 ip link set {0}-eth1 netns 1', - 'ip netns delete {0}-cust1'] - + cmds = [ + "ip netns exec {0}-cust1 ip link set {0}-eth0 netns 1", + "ip netns exec {0}-cust1 ip link set {0}-eth1 netns 1", + "ip netns delete {0}-cust1", + ] + router_list = tgen.routers() for rname, router in router_list.iteritems(): for cmd in cmds: tgen.net[rname].cmd(cmd.format(rname)) tgen.stop_topology() + # Shared test function to validate expected output. def compare_show_ip_route_vrf(rname, expected): """ @@ -147,35 +154,37 @@ def compare_show_ip_route_vrf(rname, expected): result with the expected output. """ tgen = get_topogen() - vrf_name = '{0}-cust1'.format(rname) + vrf_name = "{0}-cust1".format(rname) current = topotest.ip4_route_zebra(tgen.gears[rname], vrf_name) - ret = topotest.difflines(current, expected, - title1="Current output", - title2="Expected output") + ret = topotest.difflines( + current, expected, title1="Current output", title2="Expected output" + ) return ret + def test_ospf_convergence(): "Test OSPF daemon convergence" tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") for rname, router in tgen.routers().iteritems(): logger.info('Waiting for router "%s" convergence', rname) # Load expected results from the command - reffile = os.path.join(CWD, '{}/ospfroute.txt'.format(rname)) + reffile = os.path.join(CWD, "{}/ospfroute.txt".format(rname)) expected = open(reffile).read() # Run test function until we get an result. Wait at most 60 seconds. - test_func = partial(topotest.router_output_cmp, - router, - 'show ip ospf vrf {0}-cust1 route'.format(rname), - expected) - result, diff = topotest.run_and_expect(test_func, '', - count=160, wait=0.5) - assertmsg = 'OSPF did not converge on {}:\n{}'.format(rname, diff) + test_func = partial( + topotest.router_output_cmp, + router, + "show ip ospf vrf {0}-cust1 route".format(rname), + expected, + ) + result, diff = topotest.run_and_expect(test_func, "", count=160, wait=0.5) + assertmsg = "OSPF did not converge on {}:\n{}".format(rname, diff) assert result, assertmsg @@ -184,19 +193,19 @@ def test_ospf_kernel_route(): tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") rlist = tgen.routers().values() for router in rlist: logger.info('Checking OSPF IPv4 kernel routes in "%s"', router.name) - reffile = os.path.join(CWD, '{}/zebraroute.txt'.format(router.name)) + reffile = os.path.join(CWD, "{}/zebraroute.txt".format(router.name)) expected = open(reffile).read() # Run test function until we get an result. Wait at most 60 seconds. test_func = partial(compare_show_ip_route_vrf, router.name, expected) - result, diff = topotest.run_and_expect(test_func, '', - count=140, wait=0.5) + result, diff = topotest.run_and_expect(test_func, "", count=140, wait=0.5) assertmsg = 'OSPF IPv4 route mismatch in router "{}": {}'.format( - router.name, diff) + router.name, diff + ) assert result, assertmsg @@ -205,52 +214,57 @@ def test_ospf_json(): tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") for rname, router in tgen.routers().iteritems(): - logger.info('Comparing router "%s" "show ip ospf vrf %s-cust1 json" output', router.name, router.name) + logger.info( + 'Comparing router "%s" "show ip ospf vrf %s-cust1 json" output', + router.name, + router.name, + ) expected = { - '{}-cust1'.format(router.name) : { - 'vrfName': '{}-cust1'.format(router.name), - 'routerId': '10.0.255.{}'.format(rname[1:]), - 'tosRoutesOnly': True, - 'rfc2328Conform': True, - 'spfScheduleDelayMsecs': 0, - 'holdtimeMinMsecs': 50, - 'holdtimeMaxMsecs': 5000, - 'lsaMinIntervalMsecs': 5000, - 'lsaMinArrivalMsecs': 1000, - 'writeMultiplier': 20, - 'refreshTimerMsecs': 10000, - 'asbrRouter': 'injectingExternalRoutingInformation', - 'attachedAreaCounter': 1, - 'areas': {} - } + "{}-cust1".format(router.name): { + "vrfName": "{}-cust1".format(router.name), + "routerId": "10.0.255.{}".format(rname[1:]), + "tosRoutesOnly": True, + "rfc2328Conform": True, + "spfScheduleDelayMsecs": 0, + "holdtimeMinMsecs": 50, + "holdtimeMaxMsecs": 5000, + "lsaMinIntervalMsecs": 5000, + "lsaMinArrivalMsecs": 1000, + "writeMultiplier": 20, + "refreshTimerMsecs": 10000, + "asbrRouter": "injectingExternalRoutingInformation", + "attachedAreaCounter": 1, + "areas": {}, } + } # Area specific additional checks - if router.name == 'r1' or router.name == 'r2' or router.name == 'r3': - expected['{}-cust1'.format(router.name)]['areas']['0.0.0.0'] = { - 'areaIfActiveCounter': 2, - 'areaIfTotalCounter': 2, - 'authentication': 'authenticationNone', - 'backbone': True, - 'lsaAsbrNumber': 0, - 'lsaNetworkNumber': 1, - 'lsaNssaNumber': 0, - 'lsaNumber': 4, - 'lsaOpaqueAreaNumber': 0, - 'lsaOpaqueLinkNumber': 0, - 'lsaRouterNumber': 3, - 'lsaSummaryNumber': 0, - 'nbrFullAdjacentCounter': 2, + if router.name == "r1" or router.name == "r2" or router.name == "r3": + expected["{}-cust1".format(router.name)]["areas"]["0.0.0.0"] = { + "areaIfActiveCounter": 2, + "areaIfTotalCounter": 2, + "authentication": "authenticationNone", + "backbone": True, + "lsaAsbrNumber": 0, + "lsaNetworkNumber": 1, + "lsaNssaNumber": 0, + "lsaNumber": 4, + "lsaOpaqueAreaNumber": 0, + "lsaOpaqueLinkNumber": 0, + "lsaRouterNumber": 3, + "lsaSummaryNumber": 0, + "nbrFullAdjacentCounter": 2, } - test_func = partial(topotest.router_json_cmp, - router, - 'show ip ospf vrf {0}-cust1 json'.format(rname), - expected) - _, diff = topotest.run_and_expect(test_func, None, - count=10, wait=0.5) + test_func = partial( + topotest.router_json_cmp, + router, + "show ip ospf vrf {0}-cust1 json".format(rname), + expected, + ) + _, diff = topotest.run_and_expect(test_func, None, count=10, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(rname) assert diff is None, assertmsg @@ -260,27 +274,30 @@ def test_ospf_link_down(): tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") # Simulate a network down event on router3 switch3 interface. - router3 = tgen.gears['r3'] - topotest.interface_set_status(router3, 'r3-eth0', ifaceaction=False, vrf_name='r3-cust1') + router3 = tgen.gears["r3"] + topotest.interface_set_status( + router3, "r3-eth0", ifaceaction=False, vrf_name="r3-cust1" + ) # Expect convergence on all routers for rname, router in tgen.routers().iteritems(): logger.info('Waiting for router "%s" convergence after link failure', rname) # Load expected results from the command - reffile = os.path.join(CWD, '{}/ospfroute_down.txt'.format(rname)) + reffile = os.path.join(CWD, "{}/ospfroute_down.txt".format(rname)) expected = open(reffile).read() # Run test function until we get an result. Wait at most 60 seconds. - test_func = partial(topotest.router_output_cmp, - router, - 'show ip ospf vrf {0}-cust1 route'.format(rname), - expected) - result, diff = topotest.run_and_expect(test_func, '', - count=140, wait=0.5) - assertmsg = 'OSPF did not converge on {}:\n{}'.format(rname, diff) + test_func = partial( + topotest.router_output_cmp, + router, + "show ip ospf vrf {0}-cust1 route".format(rname), + expected, + ) + result, diff = topotest.run_and_expect(test_func, "", count=140, wait=0.5) + assertmsg = "OSPF did not converge on {}:\n{}".format(rname, diff) assert result, assertmsg @@ -289,21 +306,23 @@ def test_ospf_link_down_kernel_route(): tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") rlist = tgen.routers().values() for router in rlist: - logger.info('Checking OSPF IPv4 kernel routes in "%s" after link down', router.name) + logger.info( + 'Checking OSPF IPv4 kernel routes in "%s" after link down', router.name + ) - str='{0}-cust1'.format(router.name) - reffile = os.path.join(CWD, '{}/zebraroutedown.txt'.format(router.name)) + str = "{0}-cust1".format(router.name) + reffile = os.path.join(CWD, "{}/zebraroutedown.txt".format(router.name)) expected = open(reffile).read() # Run test function until we get an result. Wait at most 60 seconds. test_func = partial(compare_show_ip_route_vrf, router.name, expected) - result, diff = topotest.run_and_expect(test_func, '', - count=140, wait=0.5) + result, diff = topotest.run_and_expect(test_func, "", count=140, wait=0.5) assertmsg = 'OSPF IPv4 route mismatch in router "{}" after link down: {}'.format( - router.name, diff) + router.name, diff + ) assert result, assertmsg @@ -311,10 +330,11 @@ def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/ospf-topo1/test_ospf_topo1.py b/tests/topotests/ospf-topo1/test_ospf_topo1.py index 638e394153..d734f378e7 100755 --- a/tests/topotests/ospf-topo1/test_ospf_topo1.py +++ b/tests/topotests/ospf-topo1/test_ospf_topo1.py @@ -34,7 +34,7 @@ import pytest # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -45,70 +45,71 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from mininet.topo import Topo + class OSPFTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) # Create 4 routers for routern in range(1, 5): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) # Create a empty network for router 1 - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) # Create a empty network for router 2 - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) # Interconect router 1, 2 and 3 - switch = tgen.add_switch('s3') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) # Create empty netowrk for router3 - switch = tgen.add_switch('s4') - switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r3"]) # Interconect router 3 and 4 - switch = tgen.add_switch('s5') - switch.add_link(tgen.gears['r3']) - switch.add_link(tgen.gears['r4']) + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) # Create a empty network for router 4 - switch = tgen.add_switch('s6') - switch.add_link(tgen.gears['r4']) + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r4"]) + def setup_module(mod): "Sets up the pytest environment" tgen = Topogen(OSPFTopo, mod.__name__) tgen.start_topology() - ospf6_config = 'ospf6d.conf' - if tgen.gears['r1'].has_version('<', '4.0'): - ospf6_config = 'ospf6d.conf-pre-v4' + ospf6_config = "ospf6d.conf" + if tgen.gears["r1"].has_version("<", "4.0"): + ospf6_config = "ospf6d.conf-pre-v4" router_list = tgen.routers() for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_OSPF, - os.path.join(CWD, '{}/ospfd.conf'.format(rname)) + TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname)) ) router.load_config( - TopoRouter.RD_OSPF6, - os.path.join(CWD, '{}/{}'.format(rname, ospf6_config)) + TopoRouter.RD_OSPF6, os.path.join(CWD, "{}/{}".format(rname, ospf6_config)) ) # Initialize all routers. tgen.start_router() + def teardown_module(mod): "Teardown the pytest environment" tgen = get_topogen() @@ -121,46 +122,50 @@ def compare_show_ipv6_ospf6(rname, expected): result with the expected output. """ tgen = get_topogen() - current = tgen.gears[rname].vtysh_cmd('show ipv6 ospf6 route') + current = tgen.gears[rname].vtysh_cmd("show ipv6 ospf6 route") # Remove the link addresses - current = re.sub(r'fe80::[^ ]+', 'fe80::xxxx:xxxx:xxxx:xxxx', current) - expected = re.sub(r'fe80::[^ ]+', 'fe80::xxxx:xxxx:xxxx:xxxx', expected) + current = re.sub(r"fe80::[^ ]+", "fe80::xxxx:xxxx:xxxx:xxxx", current) + expected = re.sub(r"fe80::[^ ]+", "fe80::xxxx:xxxx:xxxx:xxxx", expected) # Remove the time - current = re.sub(r'\d+:\d{2}:\d{2}', '', current) - expected = re.sub(r'\d+:\d{2}:\d{2}', '', expected) + current = re.sub(r"\d+:\d{2}:\d{2}", "", current) + expected = re.sub(r"\d+:\d{2}:\d{2}", "", expected) + + return topotest.difflines( + topotest.normalize_text(current), + topotest.normalize_text(expected), + title1="Current output", + title2="Expected output", + ) - return topotest.difflines(topotest.normalize_text(current), - topotest.normalize_text(expected), - title1="Current output", - title2="Expected output") def test_ospf_convergence(): "Test OSPF daemon convergence" tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") for router, rnode in tgen.routers().iteritems(): logger.info('Waiting for router "%s" convergence', router) # Load expected results from the command - reffile = os.path.join(CWD, '{}/ospfroute.txt'.format(router)) + reffile = os.path.join(CWD, "{}/ospfroute.txt".format(router)) expected = open(reffile).read() # Run test function until we get an result. Wait at most 80 seconds. test_func = partial( - topotest.router_output_cmp, rnode, 'show ip ospf route', expected) - result, diff = topotest.run_and_expect(test_func, '', - count=160, wait=0.5) - assert result, 'OSPF did not converge on {}:\n{}'.format(router, diff) + topotest.router_output_cmp, rnode, "show ip ospf route", expected + ) + result, diff = topotest.run_and_expect(test_func, "", count=160, wait=0.5) + assert result, "OSPF did not converge on {}:\n{}".format(router, diff) + def test_ospf_kernel_route(): "Test OSPF kernel route installation" tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") rlist = tgen.routers().values() for router in rlist: @@ -168,25 +173,26 @@ def test_ospf_kernel_route(): routes = topotest.ip4_route(router) expected = { - '10.0.1.0/24': {}, - '10.0.2.0/24': {}, - '10.0.3.0/24': {}, - '10.0.10.0/24': {}, - '172.16.0.0/24': {}, - '172.16.1.0/24': {}, + "10.0.1.0/24": {}, + "10.0.2.0/24": {}, + "10.0.3.0/24": {}, + "10.0.10.0/24": {}, + "172.16.0.0/24": {}, + "172.16.1.0/24": {}, } assertmsg = 'OSPF IPv4 route mismatch in router "{}"'.format(router.name) assert topotest.json_cmp(routes, expected) is None, assertmsg + def test_ospf6_convergence(): "Test OSPF6 daemon convergence" tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") - ospf6route_file = '{}/ospf6route_ecmp.txt' + ospf6route_file = "{}/ospf6route_ecmp.txt" for rnum in range(1, 5): - router = 'r{}'.format(rnum) + router = "r{}".format(rnum) logger.info('Waiting for router "%s" IPv6 OSPF convergence', router) @@ -196,39 +202,37 @@ def test_ospf6_convergence(): # Run test function until we get an result. Wait at most 60 seconds. test_func = partial(compare_show_ipv6_ospf6, router, expected) - result, diff = topotest.run_and_expect(test_func, '', - count=25, wait=3) + result, diff = topotest.run_and_expect(test_func, "", count=25, wait=3) if (not result) and (rnum == 1): # Didn't match the new ECMP version - try the old pre-ECMP format - ospf6route_file = '{}/ospf6route.txt' + ospf6route_file = "{}/ospf6route.txt" # Load expected results from the command reffile = os.path.join(CWD, ospf6route_file.format(router)) expected = open(reffile).read() test_func = partial(compare_show_ipv6_ospf6, router, expected) - result, diff = topotest.run_and_expect(test_func, '', - count=1, wait=3) + result, diff = topotest.run_and_expect(test_func, "", count=1, wait=3) if not result: # Didn't match the old version - switch back to new ECMP version # and fail - ospf6route_file = '{}/ospf6route_ecmp.txt' + ospf6route_file = "{}/ospf6route_ecmp.txt" # Load expected results from the command reffile = os.path.join(CWD, ospf6route_file.format(router)) expected = open(reffile).read() test_func = partial(compare_show_ipv6_ospf6, router, expected) - result, diff = topotest.run_and_expect(test_func, '', - count=1, wait=3) + result, diff = topotest.run_and_expect(test_func, "", count=1, wait=3) + + assert result, "OSPF6 did not converge on {}:\n{}".format(router, diff) - assert result, 'OSPF6 did not converge on {}:\n{}'.format(router, diff) def test_ospf6_kernel_route(): "Test OSPF kernel route installation" tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") rlist = tgen.routers().values() for router in rlist: @@ -236,216 +240,231 @@ def test_ospf6_kernel_route(): routes = topotest.ip6_route(router) expected = { - '2001:db8:1::/64': {}, - '2001:db8:2::/64': {}, - '2001:db8:3::/64': {}, - '2001:db8:100::/64': {}, - '2001:db8:200::/64': {}, - '2001:db8:300::/64': {}, + "2001:db8:1::/64": {}, + "2001:db8:2::/64": {}, + "2001:db8:3::/64": {}, + "2001:db8:100::/64": {}, + "2001:db8:200::/64": {}, + "2001:db8:300::/64": {}, } assertmsg = 'OSPF IPv6 route mismatch in router "{}"'.format(router.name) assert topotest.json_cmp(routes, expected) is None, assertmsg + def test_ospf_json(): "Test 'show ip ospf json' output for coherency." tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") for rnum in range(1, 5): - router = tgen.gears['r{}'.format(rnum)] + router = tgen.gears["r{}".format(rnum)] logger.info('Comparing router "%s" "show ip ospf json" output', router.name) expected = { - 'routerId': '10.0.255.{}'.format(rnum), - 'tosRoutesOnly': True, - 'rfc2328Conform': True, - 'spfScheduleDelayMsecs': 0, - 'holdtimeMinMsecs': 50, - 'holdtimeMaxMsecs': 5000, - 'lsaMinIntervalMsecs': 5000, - 'lsaMinArrivalMsecs': 1000, - 'writeMultiplier': 20, - 'refreshTimerMsecs': 10000, - 'asbrRouter': 'injectingExternalRoutingInformation', - 'attachedAreaCounter': 1, - 'areas': {} + "routerId": "10.0.255.{}".format(rnum), + "tosRoutesOnly": True, + "rfc2328Conform": True, + "spfScheduleDelayMsecs": 0, + "holdtimeMinMsecs": 50, + "holdtimeMaxMsecs": 5000, + "lsaMinIntervalMsecs": 5000, + "lsaMinArrivalMsecs": 1000, + "writeMultiplier": 20, + "refreshTimerMsecs": 10000, + "asbrRouter": "injectingExternalRoutingInformation", + "attachedAreaCounter": 1, + "areas": {}, } # Area specific additional checks - if router.name == 'r1' or router.name == 'r2' or router.name == 'r3': - expected['areas']['0.0.0.0'] = { - 'areaIfActiveCounter': 2, - 'areaIfTotalCounter': 2, - 'authentication': 'authenticationNone', - 'backbone': True, - 'lsaAsbrNumber': 1, - 'lsaNetworkNumber': 1, - 'lsaNssaNumber': 0, - 'lsaNumber': 7, - 'lsaOpaqueAreaNumber': 0, - 'lsaOpaqueLinkNumber': 0, - 'lsaRouterNumber': 3, - 'lsaSummaryNumber': 2, - 'nbrFullAdjacentCounter': 2, + if router.name == "r1" or router.name == "r2" or router.name == "r3": + expected["areas"]["0.0.0.0"] = { + "areaIfActiveCounter": 2, + "areaIfTotalCounter": 2, + "authentication": "authenticationNone", + "backbone": True, + "lsaAsbrNumber": 1, + "lsaNetworkNumber": 1, + "lsaNssaNumber": 0, + "lsaNumber": 7, + "lsaOpaqueAreaNumber": 0, + "lsaOpaqueLinkNumber": 0, + "lsaRouterNumber": 3, + "lsaSummaryNumber": 2, + "nbrFullAdjacentCounter": 2, } - if router.name == 'r3' or router.name == 'r4': - expected['areas']['0.0.0.1'] = { - 'areaIfActiveCounter': 1, - 'areaIfTotalCounter': 1, - 'authentication': 'authenticationNone', - 'lsaAsbrNumber': 2, - 'lsaNetworkNumber': 1, - 'lsaNssaNumber': 0, - 'lsaNumber': 9, - 'lsaOpaqueAreaNumber': 0, - 'lsaOpaqueLinkNumber': 0, - 'lsaRouterNumber': 2, - 'lsaSummaryNumber': 4, - 'nbrFullAdjacentCounter': 1, + if router.name == "r3" or router.name == "r4": + expected["areas"]["0.0.0.1"] = { + "areaIfActiveCounter": 1, + "areaIfTotalCounter": 1, + "authentication": "authenticationNone", + "lsaAsbrNumber": 2, + "lsaNetworkNumber": 1, + "lsaNssaNumber": 0, + "lsaNumber": 9, + "lsaOpaqueAreaNumber": 0, + "lsaOpaqueLinkNumber": 0, + "lsaRouterNumber": 2, + "lsaSummaryNumber": 4, + "nbrFullAdjacentCounter": 1, } # r4 has more interfaces for area 0.0.0.1 - if router.name == 'r4': - expected['areas']['0.0.0.1'].update({ - 'areaIfActiveCounter': 2, - 'areaIfTotalCounter': 2, - }) + if router.name == "r4": + expected["areas"]["0.0.0.1"].update( + {"areaIfActiveCounter": 2, "areaIfTotalCounter": 2,} + ) # router 3 has an additional area - if router.name == 'r3': - expected['attachedAreaCounter'] = 2 + if router.name == "r3": + expected["attachedAreaCounter"] = 2 - output = router.vtysh_cmd('show ip ospf json', isjson=True) + output = router.vtysh_cmd("show ip ospf json", isjson=True) result = topotest.json_cmp(output, expected) - assert result is None, '"{}" JSON output mismatches the expected result'.format(router.name) + assert result is None, '"{}" JSON output mismatches the expected result'.format( + router.name + ) + def test_ospf_link_down(): "Test OSPF convergence after a link goes down" tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") # Simulate a network down event on router3 switch3 interface. - router3 = tgen.gears['r3'] - router3.peer_link_enable('r3-eth0', False) + router3 = tgen.gears["r3"] + router3.peer_link_enable("r3-eth0", False) # Expect convergence on all routers for router, rnode in tgen.routers().iteritems(): logger.info('Waiting for router "%s" convergence after link failure', router) # Load expected results from the command - reffile = os.path.join(CWD, '{}/ospfroute_down.txt'.format(router)) + reffile = os.path.join(CWD, "{}/ospfroute_down.txt".format(router)) expected = open(reffile).read() # Run test function until we get an result. Wait at most 80 seconds. test_func = partial( - topotest.router_output_cmp, rnode, 'show ip ospf route', expected) - result, diff = topotest.run_and_expect(test_func, '', - count=140, wait=0.5) - assert result, 'OSPF did not converge on {}:\n{}'.format(router, diff) + topotest.router_output_cmp, rnode, "show ip ospf route", expected + ) + result, diff = topotest.run_and_expect(test_func, "", count=140, wait=0.5) + assert result, "OSPF did not converge on {}:\n{}".format(router, diff) + def test_ospf_link_down_kernel_route(): "Test OSPF kernel route installation" tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") rlist = tgen.routers().values() for router in rlist: - logger.info('Checking OSPF IPv4 kernel routes in "%s" after link down', router.name) + logger.info( + 'Checking OSPF IPv4 kernel routes in "%s" after link down', router.name + ) routes = topotest.ip4_route(router) expected = { - '10.0.1.0/24': {}, - '10.0.2.0/24': {}, - '10.0.3.0/24': {}, - '10.0.10.0/24': {}, - '172.16.0.0/24': {}, - '172.16.1.0/24': {}, + "10.0.1.0/24": {}, + "10.0.2.0/24": {}, + "10.0.3.0/24": {}, + "10.0.10.0/24": {}, + "172.16.0.0/24": {}, + "172.16.1.0/24": {}, } - if router.name == 'r1' or router.name == 'r2': - expected.update({ - '10.0.10.0/24': None, - '172.16.0.0/24': None, - '172.16.1.0/24': None, - }) - elif router.name == 'r3' or router.name == 'r4': - expected.update({ - '10.0.1.0/24': None, - '10.0.2.0/24': None, - }) + if router.name == "r1" or router.name == "r2": + expected.update( + {"10.0.10.0/24": None, "172.16.0.0/24": None, "172.16.1.0/24": None,} + ) + elif router.name == "r3" or router.name == "r4": + expected.update( + {"10.0.1.0/24": None, "10.0.2.0/24": None,} + ) # Route '10.0.3.0' is no longer available for r4 since it is down. - if router.name == 'r4': - expected.update({ - '10.0.3.0/24': None, - }) - assertmsg = 'OSPF IPv4 route mismatch in router "{}" after link down'.format(router.name) + if router.name == "r4": + expected.update( + {"10.0.3.0/24": None,} + ) + assertmsg = 'OSPF IPv4 route mismatch in router "{}" after link down'.format( + router.name + ) assert topotest.json_cmp(routes, expected) is None, assertmsg + def test_ospf6_link_down(): "Test OSPF6 daemon convergence after link goes down" tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") for rnum in range(1, 5): - router = 'r{}'.format(rnum) + router = "r{}".format(rnum) - logger.info('Waiting for router "%s" IPv6 OSPF convergence after link down', router) + logger.info( + 'Waiting for router "%s" IPv6 OSPF convergence after link down', router + ) # Load expected results from the command - reffile = os.path.join(CWD, '{}/ospf6route_down.txt'.format(router)) + reffile = os.path.join(CWD, "{}/ospf6route_down.txt".format(router)) expected = open(reffile).read() # Run test function until we get an result. Wait at most 60 seconds. test_func = partial(compare_show_ipv6_ospf6, router, expected) - result, diff = topotest.run_and_expect(test_func, '', - count=25, wait=3) - assert result, 'OSPF6 did not converge on {}:\n{}'.format(router, diff) + result, diff = topotest.run_and_expect(test_func, "", count=25, wait=3) + assert result, "OSPF6 did not converge on {}:\n{}".format(router, diff) + def test_ospf6_link_down_kernel_route(): "Test OSPF kernel route installation" tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") rlist = tgen.routers().values() for router in rlist: - logger.info('Checking OSPF IPv6 kernel routes in "%s" after link down', router.name) + logger.info( + 'Checking OSPF IPv6 kernel routes in "%s" after link down', router.name + ) routes = topotest.ip6_route(router) expected = { - '2001:db8:1::/64': {}, - '2001:db8:2::/64': {}, - '2001:db8:3::/64': {}, - '2001:db8:100::/64': {}, - '2001:db8:200::/64': {}, - '2001:db8:300::/64': {}, + "2001:db8:1::/64": {}, + "2001:db8:2::/64": {}, + "2001:db8:3::/64": {}, + "2001:db8:100::/64": {}, + "2001:db8:200::/64": {}, + "2001:db8:300::/64": {}, } - if router.name == 'r1' or router.name == 'r2': - expected.update({ - '2001:db8:100::/64': None, - '2001:db8:200::/64': None, - '2001:db8:300::/64': None, - }) - elif router.name == 'r3' or router.name == 'r4': - expected.update({ - '2001:db8:1::/64': None, - '2001:db8:2::/64': None, - }) + if router.name == "r1" or router.name == "r2": + expected.update( + { + "2001:db8:100::/64": None, + "2001:db8:200::/64": None, + "2001:db8:300::/64": None, + } + ) + elif router.name == "r3" or router.name == "r4": + expected.update( + {"2001:db8:1::/64": None, "2001:db8:2::/64": None,} + ) # Route '2001:db8:3::/64' is no longer available for r4 since it is down. - if router.name == 'r4': - expected.update({ - '2001:db8:3::/64': None, - }) - assertmsg = 'OSPF IPv6 route mismatch in router "{}" after link down'.format(router.name) + if router.name == "r4": + expected.update( + {"2001:db8:3::/64": None,} + ) + assertmsg = 'OSPF IPv6 route mismatch in router "{}" after link down'.format( + router.name + ) assert topotest.json_cmp(routes, expected) is None, assertmsg + def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/ospf6-topo1/test_ospf6_topo1.py b/tests/topotests/ospf6-topo1/test_ospf6_topo1.py index 2f7a4ce4e3..30c09ea606 100755 --- a/tests/topotests/ospf6-topo1/test_ospf6_topo1.py +++ b/tests/topotests/ospf6-topo1/test_ospf6_topo1.py @@ -82,7 +82,7 @@ from mininet.topo import Topo # Save the Current Working Directory to find configuration files later. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -97,6 +97,7 @@ import platform ## ##################################################### + class NetworkTopo(Topo): "OSPFv3 (IPv6) Test Topology 1" @@ -107,7 +108,7 @@ class NetworkTopo(Topo): # Create 4 routers for routern in range(1, 5): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) # # Wire up the switches and routers @@ -115,31 +116,31 @@ class NetworkTopo(Topo): # # Create a empty network for router 1 - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1'], nodeif='r1-stubnet') + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"], nodeif="r1-stubnet") # Create a empty network for router 2 - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r2'], nodeif='r2-stubnet') + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"], nodeif="r2-stubnet") # Create a empty network for router 3 - switch = tgen.add_switch('s3') - switch.add_link(tgen.gears['r3'], nodeif='r3-stubnet') + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r3"], nodeif="r3-stubnet") # Create a empty network for router 4 - switch = tgen.add_switch('s4') - switch.add_link(tgen.gears['r4'], nodeif='r4-stubnet') + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r4"], nodeif="r4-stubnet") # Interconnect routers 1, 2, and 3 - switch = tgen.add_switch('s5') - switch.add_link(tgen.gears['r1'], nodeif='r1-sw5') - switch.add_link(tgen.gears['r2'], nodeif='r2-sw5') - switch.add_link(tgen.gears['r3'], nodeif='r3-sw5') + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r1"], nodeif="r1-sw5") + switch.add_link(tgen.gears["r2"], nodeif="r2-sw5") + switch.add_link(tgen.gears["r3"], nodeif="r3-sw5") # Interconnect routers 3 and 4 - switch = tgen.add_switch('s6') - switch.add_link(tgen.gears['r3'], nodeif='r3-sw6') - switch.add_link(tgen.gears['r4'], nodeif='r4-sw6') + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r3"], nodeif="r3-sw6") + switch.add_link(tgen.gears["r4"], nodeif="r4-sw6") ##################################################### @@ -148,6 +149,7 @@ class NetworkTopo(Topo): ## ##################################################### + def setup_module(mod): "Sets up the pytest environment" @@ -164,12 +166,10 @@ def setup_module(mod): router_list = tgen.routers() for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_OSPF6, - os.path.join(CWD, '{}/ospf6d.conf'.format(rname)) + TopoRouter.RD_OSPF6, os.path.join(CWD, "{}/ospf6d.conf".format(rname)) ) # Initialize all routers. @@ -194,14 +194,14 @@ def test_ospf6_converged(): pytest.skip(tgen.errors) # For debugging, uncomment the next line - #tgen.mininet_cli() + # tgen.mininet_cli() # Wait for OSPF6 to converge (All Neighbors in either Full or TwoWay State) logger.info("Waiting for OSPF6 convergence") # Set up for regex - pat1 = re.compile('^[0-9]') - pat2 = re.compile('Full') + pat1 = re.compile("^[0-9]") + pat2 = re.compile("Full") timeout = 60 while timeout > 0: @@ -210,7 +210,7 @@ def test_ospf6_converged(): # Look for any node not yet converged for router, rnode in tgen.routers().iteritems(): - resStr = rnode.vtysh_cmd('show ipv6 ospf neigh') + resStr = rnode.vtysh_cmd("show ipv6 ospf neigh") isConverged = False @@ -225,12 +225,12 @@ def test_ospf6_converged(): break if isConverged == False: - logger.info('Waiting for {}'.format(router)) + logger.info("Waiting for {}".format(router)) sys.stdout.flush() break if isConverged: - logger.info('Done') + logger.info("Done") break else: sleep(5) @@ -238,7 +238,7 @@ def test_ospf6_converged(): if timeout == 0: # Bail out with error if a router fails to converge - ospfStatus = rnode.vtysh_cmd('show ipv6 ospf neigh') + ospfStatus = rnode.vtysh_cmd("show ipv6 ospf neigh") assert False, "OSPFv6 did not converge:\n{}".format(ospfStatus) logger.info("OSPFv3 converged.") @@ -250,6 +250,7 @@ def test_ospf6_converged(): if tgen.routers_have_failure(): assert tgen.errors == "", tgen.errors + def compare_show_ipv6(rname, expected): """ Calls 'show ipv6 route' for router `rname` and compare the obtained @@ -263,21 +264,24 @@ def compare_show_ipv6(rname, expected): # Use just the 'O'spf lines of the output linearr = [] for line in current.splitlines(): - if re.match('^O', line): + if re.match("^O", line): linearr.append(line) - current = '\n'.join(linearr) + current = "\n".join(linearr) + + return topotest.difflines( + topotest.normalize_text(current), + topotest.normalize_text(expected), + title1="Current output", + title2="Expected output", + ) - return topotest.difflines(topotest.normalize_text(current), - topotest.normalize_text(expected), - title1="Current output", - title2="Expected output") def test_ospfv3_routingTable(): tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") # For debugging, uncomment the next line # tgen.mininet_cli() @@ -287,15 +291,13 @@ def test_ospfv3_routingTable(): logger.info('Waiting for router "%s" convergence', router) # Load expected results from the command - reffile = os.path.join(CWD, '{}/show_ipv6_route.ref'.format(router)) + reffile = os.path.join(CWD, "{}/show_ipv6_route.ref".format(router)) expected = open(reffile).read() # Run test function until we get an result. Wait at most 60 seconds. - test_func = partial( - compare_show_ipv6, router, expected) - result, diff = topotest.run_and_expect(test_func, '', - count=120, wait=0.5) - assert result, 'OSPFv3 did not converge on {}:\n{}'.format(router, diff) + test_func = partial(compare_show_ipv6, router, expected) + result, diff = topotest.run_and_expect(test_func, "", count=120, wait=0.5) + assert result, "OSPFv3 did not converge on {}:\n{}".format(router, diff) def test_linux_ipv6_kernel_routingTable(): @@ -303,7 +305,7 @@ def test_linux_ipv6_kernel_routingTable(): tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") # Verify Linux Kernel Routing Table logger.info("Verifying Linux IPv6 Kernel Routing Table") @@ -314,22 +316,22 @@ def test_linux_ipv6_kernel_routingTable(): # each run and we need to translate them linklocals = [] for i in range(1, 5): - linklocals += tgen.net['r{}'.format(i)].get_ipv6_linklocal() + 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() + 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)) + 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)) + 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) + expected = ("\n".join(expected.splitlines())).splitlines(1) # Mask out Link-Local mac addresses for ll in linklocals: @@ -338,20 +340,21 @@ def test_linux_ipv6_kernel_routingTable(): 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) + actual = re.sub(r"ff00::/8.*", "", actual) # Strip empty lines actual = actual.lstrip() actual = actual.rstrip() - actual = re.sub(r' +', ' ', actual) + actual = re.sub(r" +", " ", actual) filtered_lines = [] for line in sorted(actual.splitlines()): - if line.startswith('fe80::/64 ') \ - or line.startswith('unreachable fe80::/64 '): + if line.startswith("fe80::/64 ") or line.startswith( + "unreachable fe80::/64 " + ): continue filtered_lines.append(line) - actual = '\n'.join(filtered_lines).splitlines(1) + actual = "\n".join(filtered_lines).splitlines(1) # Print Actual table # logger.info("Router r%s table" % i) @@ -359,18 +362,27 @@ def test_linux_ipv6_kernel_routingTable(): # logger.info(line.rstrip()) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual OSPFv3 IPv6 routing table", - title2="expected 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)) + 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) + assert failures == 0, ( + "Linux Kernel IPv6 Routing Table verification failed for router r%s:\n%s" + % (i, diff) + ) def test_shutdown_check_stderr(): @@ -378,11 +390,13 @@ def test_shutdown_check_stderr(): tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") - if os.environ.get('TOPOTESTS_CHECK_STDERR') is None: - logger.info("SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n") - pytest.skip('Skipping test for Stderr output') + if os.environ.get("TOPOTESTS_CHECK_STDERR") is None: + logger.info( + "SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n" + ) + pytest.skip("Skipping test for Stderr output") net = tgen.net @@ -390,11 +404,11 @@ def test_shutdown_check_stderr(): logger.info("******************************************") for i in range(1, 5): - net['r%s' % i].stopRouter() - log = net['r%s' % i].getStdErr('ospf6d') + net["r%s" % i].stopRouter() + log = net["r%s" % i].getStdErr("ospf6d") if log: logger.info("\nRouter r%s OSPF6d StdErr Log:\n%s" % (i, log)) - log = net['r%s' % i].getStdErr('zebra') + log = net["r%s" % i].getStdErr("zebra") if log: logger.info("\nRouter r%s Zebra StdErr Log:\n%s" % (i, log)) @@ -402,22 +416,24 @@ def test_shutdown_check_stderr(): def test_shutdown_check_memleak(): "Run the memory leak test and report results." - if os.environ.get('TOPOTESTS_CHECK_MEMLEAK') is None: - logger.info("SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)") - pytest.skip('Skipping test for memory leaks') + if os.environ.get("TOPOTESTS_CHECK_MEMLEAK") is None: + logger.info( + "SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)" + ) + pytest.skip("Skipping test for memory leaks") tgen = get_topogen() net = tgen.net for i in range(1, 5): - net['r%s' % i].stopRouter() - net['r%s' % i].report_memory_leaks( - os.environ.get('TOPOTESTS_CHECK_MEMLEAK'), - os.path.basename(__file__)) + net["r%s" % i].stopRouter() + net["r%s" % i].report_memory_leaks( + os.environ.get("TOPOTESTS_CHECK_MEMLEAK"), os.path.basename(__file__) + ) -if __name__ == '__main__': +if __name__ == "__main__": # To suppress tracebacks, either use the following pytest call or # add "--tb=no" to cli diff --git a/tests/topotests/pim-basic/mcast-rx.py b/tests/topotests/pim-basic/mcast-rx.py index 9e3484e12a..8a3a44ecb1 100755 --- a/tests/topotests/pim-basic/mcast-rx.py +++ b/tests/topotests/pim-basic/mcast-rx.py @@ -36,8 +36,8 @@ import time def ifname_to_ifindex(ifname): output = subprocess.check_output("ip link show %s" % ifname, shell=True) - first_line = output.split('\n')[0] - re_index = re.search('^(\d+):', first_line) + first_line = output.split("\n")[0] + re_index = re.search("^(\d+):", first_line) if re_index: return int(re_index.group(1)) @@ -48,24 +48,28 @@ def ifname_to_ifindex(ifname): # Thou shalt be root if os.geteuid() != 0: - sys.stderr.write('ERROR: You must have root privileges\n') + sys.stderr.write("ERROR: You must have root privileges\n") sys.exit(1) -logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)5s: %(message)s') +logging.basicConfig( + level=logging.DEBUG, format="%(asctime)s %(levelname)5s: %(message)s" +) # Color the errors and warnings in red -logging.addLevelName(logging.ERROR, "\033[91m %s\033[0m" % logging.getLevelName(logging.ERROR)) -logging.addLevelName(logging.WARNING, "\033[91m%s\033[0m" % logging.getLevelName(logging.WARNING)) +logging.addLevelName( + logging.ERROR, "\033[91m %s\033[0m" % logging.getLevelName(logging.ERROR) +) +logging.addLevelName( + logging.WARNING, "\033[91m%s\033[0m" % logging.getLevelName(logging.WARNING) +) log = logging.getLogger(__name__) -parser = argparse.ArgumentParser(description='Multicast RX utility', - version='1.0.0') -parser.add_argument('group', help='Multicast IP') -parser.add_argument('ifname', help='Interface name') -parser.add_argument('--port', help='UDP port', default=1000) -parser.add_argument('--sleep', help='Time to sleep before we stop waiting', - default = 5) +parser = argparse.ArgumentParser(description="Multicast RX utility", version="1.0.0") +parser.add_argument("group", help="Multicast IP") +parser.add_argument("ifname", help="Interface name") +parser.add_argument("--port", help="UDP port", default=1000) +parser.add_argument("--sleep", help="Time to sleep before we stop waiting", default=5) args = parser.parse_args() # Create the datagram socket @@ -77,7 +81,9 @@ newpid = os.fork() if newpid == 0: ifindex = ifname_to_ifindex(args.ifname) - mreq = struct.pack("=4sLL", socket.inet_aton(args.group), socket.INADDR_ANY, ifindex) + mreq = struct.pack( + "=4sLL", socket.inet_aton(args.group), socket.INADDR_ANY, ifindex + ) sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) time.sleep(float(args.sleep)) sock.close() diff --git a/tests/topotests/pim-basic/mcast-tx.py b/tests/topotests/pim-basic/mcast-tx.py index c469e47d4c..ad6fdc1062 100755 --- a/tests/topotests/pim-basic/mcast-tx.py +++ b/tests/topotests/pim-basic/mcast-tx.py @@ -26,20 +26,28 @@ import struct import time -logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)5s: %(message)s') +logging.basicConfig( + level=logging.DEBUG, format="%(asctime)s %(levelname)5s: %(message)s" +) # Color the errors and warnings in red -logging.addLevelName(logging.ERROR, "\033[91m %s\033[0m" % logging.getLevelName(logging.ERROR)) -logging.addLevelName(logging.WARNING, "\033[91m%s\033[0m" % logging.getLevelName(logging.WARNING)) +logging.addLevelName( + logging.ERROR, "\033[91m %s\033[0m" % logging.getLevelName(logging.ERROR) +) +logging.addLevelName( + logging.WARNING, "\033[91m%s\033[0m" % logging.getLevelName(logging.WARNING) +) log = logging.getLogger(__name__) -parser = argparse.ArgumentParser(description='Multicast packet generator', version='1.0.0') -parser.add_argument('group', help='Multicast IP') -parser.add_argument('ifname', help='Interface name') -parser.add_argument('--port', type=int, help='UDP port number', default=1000) -parser.add_argument('--ttl', type=int, help='time-to-live', default=20) -parser.add_argument('--count', type=int, help='Packets to send', default=1) -parser.add_argument('--interval', type=int, help='ms between packets', default=100) +parser = argparse.ArgumentParser( + description="Multicast packet generator", version="1.0.0" +) +parser.add_argument("group", help="Multicast IP") +parser.add_argument("ifname", help="Interface name") +parser.add_argument("--port", type=int, help="UDP port number", default=1000) +parser.add_argument("--ttl", type=int, help="time-to-live", default=20) +parser.add_argument("--count", type=int, help="Packets to send", default=1) +parser.add_argument("--interval", type=int, help="ms between packets", default=100) args = parser.parse_args() # Create the datagram socket @@ -49,22 +57,24 @@ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # https://github.com/sivel/bonding/issues/10 # # Bind our socket to ifname -sock.setsockopt(socket.SOL_SOCKET, - 25, - struct.pack("%ds" % len(args.ifname), args.ifname)) +sock.setsockopt( + socket.SOL_SOCKET, 25, struct.pack("%ds" % len(args.ifname), args.ifname) +) # We need to make sure our sendto() finishes before we close the socket sock.setblocking(1) # Set the time-to-live -sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, struct.pack('b', args.ttl)) +sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, struct.pack("b", args.ttl)) ms = args.interval / 1000.0 # Send data to the multicast group for x in xrange(args.count): - log.info('TX multicast UDP packet to %s:%d on %s' % (args.group, args.port, args.ifname)) - sent = sock.sendto('foobar %d' % x, (args.group, args.port)) + log.info( + "TX multicast UDP packet to %s:%d on %s" % (args.group, args.port, args.ifname) + ) + sent = sock.sendto("foobar %d" % x, (args.group, args.port)) if args.count > 1 and ms: time.sleep(ms) diff --git a/tests/topotests/pim-basic/test_pim.py b/tests/topotests/pim-basic/test_pim.py index 9101d7e035..2abee39176 100644 --- a/tests/topotests/pim-basic/test_pim.py +++ b/tests/topotests/pim-basic/test_pim.py @@ -32,7 +32,7 @@ import json from functools import partial CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest @@ -41,15 +41,16 @@ from lib.topolog import logger from mininet.topo import Topo + class PIMTopo(Topo): def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) for routern in range(1, 4): - tgen.add_router('r{}'.format(routern)) + tgen.add_router("r{}".format(routern)) - tgen.add_router('rp') + tgen.add_router("rp") # rp ------ r1 -------- r2 # \ @@ -63,21 +64,22 @@ class PIMTopo(Topo): # r1 <- sw1 -> r2 # r1-eth0 <-> r2-eth0 # 10.0.20.0/24 - sw = tgen.add_switch('sw1') - sw.add_link(tgen.gears['r1']) - sw.add_link(tgen.gears['r2']) + sw = tgen.add_switch("sw1") + sw.add_link(tgen.gears["r1"]) + sw.add_link(tgen.gears["r2"]) # r1 <- sw2 -> rp # r1-eth1 <-> rp-eth0 # 10.0.30.0/24 - sw = tgen.add_switch('sw2') - sw.add_link(tgen.gears['r1']) - sw.add_link(tgen.gears['rp']) + sw = tgen.add_switch("sw2") + sw.add_link(tgen.gears["r1"]) + sw.add_link(tgen.gears["rp"]) # 10.0.40.0/24 - sw = tgen.add_switch('sw3') - sw.add_link(tgen.gears['r1']) - sw.add_link(tgen.gears['r3']) + sw = tgen.add_switch("sw3") + sw.add_link(tgen.gears["r1"]) + sw.add_link(tgen.gears["r3"]) + def setup_module(mod): "Sets up the pytest environment" @@ -87,21 +89,18 @@ def setup_module(mod): # For all registered routers, load the zebra configuration file for rname, router in tgen.routers().iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_PIM, - os.path.join(CWD, '{}/pimd.conf'.format(rname)) + TopoRouter.RD_PIM, os.path.join(CWD, "{}/pimd.conf".format(rname)) ) router.load_config( - TopoRouter.RD_BGP, - os.path.join(CWD, '{}/bgpd.conf'.format(rname)) - ) + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) # After loading the configurations, this function loads configured daemons. tgen.start_router() - #tgen.mininet_cli() + # tgen.mininet_cli() def teardown_module(mod): @@ -111,22 +110,25 @@ def teardown_module(mod): # This function tears down the whole topology. tgen.stop_topology() + def test_pim_rp_setup(): "Ensure basic routing has come up and the rp has an outgoing interface" - #Ensure rp and r1 establish pim neighbor ship and bgp has come up - #Finally ensure that the rp has an outgoing interface on r1 + # Ensure rp and r1 establish pim neighbor ship and bgp has come up + # Finally ensure that the rp has an outgoing interface on r1 tgen = get_topogen() - r1 = tgen.gears['r1'] - json_file = '{}/{}/rp-info.json'.format(CWD, r1.name) + r1 = tgen.gears["r1"] + json_file = "{}/{}/rp-info.json".format(CWD, r1.name) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - r1, 'show ip pim rp-info json', expected) + test_func = partial( + topotest.router_json_cmp, r1, "show ip pim rp-info json", expected + ) _, result = topotest.run_and_expect(test_func, None, count=15, wait=5) assertmsg = '"{}" JSON output mismatches'.format(r1.name) assert result is None, assertmsg - #tgen.mininet_cli() + # tgen.mininet_cli() + def test_pim_send_mcast_stream(): "Establish a Multicast stream from r2 -> r1 and then ensure S,G is created as appropriate" @@ -137,47 +139,58 @@ def test_pim_send_mcast_stream(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - rp = tgen.gears['rp'] - r3 = tgen.gears['r3'] - r2 = tgen.gears['r2'] - r1 = tgen.gears['r1'] + rp = tgen.gears["rp"] + r3 = tgen.gears["r3"] + r2 = tgen.gears["r2"] + r1 = tgen.gears["r1"] # Let's establish a S,G stream from r2 -> r1 CWD = os.path.dirname(os.path.realpath(__file__)) - r2.run("{}/mcast-tx.py --ttl 5 --count 5 --interval 10 229.1.1.1 r2-eth0 > /tmp/bar".format(CWD)) + r2.run( + "{}/mcast-tx.py --ttl 5 --count 5 --interval 10 229.1.1.1 r2-eth0 > /tmp/bar".format( + CWD + ) + ) # And from r3 -> r1 - r3.run("{}/mcast-tx.py --ttl 5 --count 5 --interval 10 229.1.1.1 r3-eth0 > /tmp/bar".format(CWD)) + r3.run( + "{}/mcast-tx.py --ttl 5 --count 5 --interval 10 229.1.1.1 r3-eth0 > /tmp/bar".format( + CWD + ) + ) # Let's see that it shows up and we have established some basic state out = r1.vtysh_cmd("show ip pim upstream json", isjson=True) expected = { - '229.1.1.1': { - '10.0.20.2': { - 'firstHopRouter': 1, - 'joinState': 'NotJoined', - 'regState': 'RegPrune', - 'inboundInterface': 'r1-eth0', + "229.1.1.1": { + "10.0.20.2": { + "firstHopRouter": 1, + "joinState": "NotJoined", + "regState": "RegPrune", + "inboundInterface": "r1-eth0", } } } - assert topotest.json_cmp(out, expected) is None, 'failed to converge pim' - #tgen.mininet_cli() + assert topotest.json_cmp(out, expected) is None, "failed to converge pim" + # tgen.mininet_cli() + def test_pim_rp_sees_stream(): "Ensure that the RP sees the stream and has acted accordingly" tgen = get_topogen() - rp = tgen.gears['rp'] - json_file = '{}/{}/upstream.json'.format(CWD, rp.name) + rp = tgen.gears["rp"] + json_file = "{}/{}/upstream.json".format(CWD, rp.name) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - rp, 'show ip pim upstream json', expected) - _, result = topotest.run_and_expect(test_func, None, count=20, wait=.5) + test_func = partial( + topotest.router_json_cmp, rp, "show ip pim upstream json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=20, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(rp.name) assert result is None, assertmsg + def test_pim_igmp_report(): "Send a igmp report from r2->r1 and ensure that the *,G state is created on r1" logger.info("Send a igmp report from r2-r1 and ensure *,G created") @@ -187,8 +200,8 @@ def test_pim_igmp_report(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - r2 = tgen.gears['r2'] - r1 = tgen.gears['r1'] + r2 = tgen.gears["r2"] + r1 = tgen.gears["r1"] # Let's send a igmp report from r2->r1 CWD = os.path.dirname(os.path.realpath(__file__)) @@ -196,28 +209,28 @@ def test_pim_igmp_report(): out = r1.vtysh_cmd("show ip pim upstream json", isjson=True) expected = { - '229.1.1.2': { - '*': { - 'sourceIgmp': 1, - 'joinState': 'Joined', - 'regState': 'RegNoInfo', - 'sptBit': 0, + "229.1.1.2": { + "*": { + "sourceIgmp": 1, + "joinState": "Joined", + "regState": "RegNoInfo", + "sptBit": 0, } } } - assert topotest.json_cmp(out, expected) is None, 'failed to converge pim' + assert topotest.json_cmp(out, expected) is None, "failed to converge pim" def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/rip-topo1/test_rip_topo1.py b/tests/topotests/rip-topo1/test_rip_topo1.py index 8f3c25e910..132d38c2e5 100755 --- a/tests/topotests/rip-topo1/test_rip_topo1.py +++ b/tests/topotests/rip-topo1/test_rip_topo1.py @@ -54,6 +54,7 @@ fatal_error = "" ## ##################################################### + class NetworkTopo(Topo): "RIP Topology 1" @@ -63,33 +64,32 @@ class NetworkTopo(Topo): router = {} # # Setup Main Router - router[1] = topotest.addRouter(self, 'r1') + router[1] = topotest.addRouter(self, "r1") # # Setup RIP Routers for i in range(2, 4): - router[i] = topotest.addRouter(self, 'r%s' % i) + router[i] = topotest.addRouter(self, "r%s" % i) # # Setup Switches switch = {} # # On main router # First switch is for a dummy interface (for local network) - switch[1] = self.addSwitch('sw1', cls=topotest.LegacySwitch) - self.addLink(switch[1], router[1], intfName2='r1-eth0') + switch[1] = self.addSwitch("sw1", cls=topotest.LegacySwitch) + self.addLink(switch[1], router[1], intfName2="r1-eth0") # # Switches for RIP # switch 2 switch is for connection to RIP router - switch[2] = self.addSwitch('sw2', cls=topotest.LegacySwitch) - self.addLink(switch[2], router[1], intfName2='r1-eth1') - self.addLink(switch[2], router[2], intfName2='r2-eth0') + switch[2] = self.addSwitch("sw2", cls=topotest.LegacySwitch) + self.addLink(switch[2], router[1], intfName2="r1-eth1") + self.addLink(switch[2], router[2], intfName2="r2-eth0") # switch 3 is between RIP routers - switch[3] = self.addSwitch('sw3', cls=topotest.LegacySwitch) - self.addLink(switch[3], router[2], intfName2='r2-eth1') - self.addLink(switch[3], router[3], intfName2='r3-eth1') + switch[3] = self.addSwitch("sw3", cls=topotest.LegacySwitch) + self.addLink(switch[3], router[2], intfName2="r2-eth1") + self.addLink(switch[3], router[3], intfName2="r3-eth1") # switch 4 is stub on remote RIP router - switch[4] = self.addSwitch('sw4', cls=topotest.LegacySwitch) - self.addLink(switch[4], router[3], intfName2='r3-eth0') - + switch[4] = self.addSwitch("sw4", cls=topotest.LegacySwitch) + self.addLink(switch[4], router[3], intfName2="r3-eth0") ##################################################### @@ -98,6 +98,7 @@ class NetworkTopo(Topo): ## ##################################################### + def setup_module(module): global topo, net @@ -105,7 +106,7 @@ def setup_module(module): print("******************************************\n") print("Cleanup old Mininet runs") - os.system('sudo mn -c > /dev/null 2>&1') + os.system("sudo mn -c > /dev/null 2>&1") thisDir = os.path.dirname(os.path.realpath(__file__)) topo = NetworkTopo() @@ -116,9 +117,9 @@ def setup_module(module): # Starting Routers # for i in range(1, 4): - net['r%s' % i].loadConf('zebra', '%s/r%s/zebra.conf' % (thisDir, i)) - net['r%s' % i].loadConf('ripd', '%s/r%s/ripd.conf' % (thisDir, i)) - net['r%s' % i].startRouter() + net["r%s" % i].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir, i)) + net["r%s" % i].loadConf("ripd", "%s/r%s/ripd.conf" % (thisDir, i)) + net["r%s" % i].startRouter() # For debugging after starting Quagga/FRR daemons, uncomment the next line # CLI(net) @@ -139,7 +140,7 @@ def test_router_running(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) print("\n\n** Check if FRR/Quagga is running on each Router node") @@ -147,7 +148,7 @@ def test_router_running(): # Make sure that all daemons are running for i in range(1, 4): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -159,7 +160,7 @@ def test_converge_protocols(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -172,7 +173,7 @@ def test_converge_protocols(): # Make sure that all daemons are still running for i in range(1, 4): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -184,7 +185,7 @@ def test_rip_status(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -194,30 +195,37 @@ def test_rip_status(): print("******************************************\n") failures = 0 for i in range(1, 4): - refTableFile = '%s/r%s/rip_status.ref' % (thisDir, i) + 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) + 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 = ( + 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) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual IP RIP status", - title2="expected 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)) + sys.stderr.write("r%s failed IP RIP status check:\n%s\n" % (i, diff)) failures += 1 else: print("r%s ok" % i) @@ -226,7 +234,7 @@ def test_rip_status(): # Make sure that all daemons are still running for i in range(1, 4): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -238,7 +246,7 @@ def test_rip_routes(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -248,28 +256,31 @@ def test_rip_routes(): print("******************************************\n") failures = 0 for i in range(1, 4): - refTableFile = '%s/r%s/show_ip_rip.ref' % (thisDir, i) + refTableFile = "%s/r%s/show_ip_rip.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) + expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) # Actual output from router - actual = net['r%s' % i].cmd('vtysh -c "show ip rip" 2> /dev/null').rstrip() + actual = net["r%s" % i].cmd('vtysh -c "show ip rip" 2> /dev/null').rstrip() # Drop Time actual = re.sub(r"[0-9][0-9]:[0-5][0-9]", "XX:XX", actual) # Fix newlines (make them all the same) - actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual SHOW IP RIP", - title2="expected SHOW IP RIP") + title2="expected SHOW IP RIP", + ) # Empty string if it matches, otherwise diff contains unified diff if diff: - sys.stderr.write('r%s failed SHOW IP RIP check:\n%s\n' % (i, diff)) + sys.stderr.write("r%s failed SHOW IP RIP check:\n%s\n" % (i, diff)) failures += 1 else: print("r%s ok" % i) @@ -278,7 +289,7 @@ def test_rip_routes(): # Make sure that all daemons are still running for i in range(1, 4): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -290,7 +301,7 @@ def test_zebra_ipv4_routingTable(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -300,37 +311,49 @@ def test_zebra_ipv4_routingTable(): print("******************************************\n") failures = 0 for i in range(1, 4): - refTableFile = '%s/r%s/show_ip_route.ref' % (thisDir, i) + refTableFile = "%s/r%s/show_ip_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) + 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 "^R"').rstrip() + actual = ( + net["r%s" % i] + .cmd('vtysh -c "show ip route" 2> /dev/null | grep "^R"') + .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) # Fix newlines (make them all the same) - actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual Zebra IPv4 routing table", - title2="expected Zebra IPv4 routing table") + title2="expected Zebra IPv4 routing table", + ) # Empty string if it matches, otherwise diff contains unified diff if diff: - sys.stderr.write('r%s failed Zebra IPv4 Routing Table Check:\n%s\n' % (i, diff)) + sys.stderr.write( + "r%s failed Zebra IPv4 Routing Table Check:\n%s\n" % (i, diff) + ) failures += 1 else: print("r%s ok" % i) - assert failures == 0, "Zebra IPv4 Routing Table verification failed for router r%s:\n%s" % (i, diff) + assert failures == 0, ( + "Zebra IPv4 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, 4): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -342,30 +365,30 @@ def test_shutdown_check_stderr(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) - if os.environ.get('TOPOTESTS_CHECK_STDERR') is None: - pytest.skip('Skipping test for Stderr output and memory leaks') + if os.environ.get("TOPOTESTS_CHECK_STDERR") is None: + pytest.skip("Skipping test for Stderr output and memory leaks") thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifing unexpected STDERR output from daemons") print("******************************************\n") - net['r1'].stopRouter() + net["r1"].stopRouter() - log = net['r1'].getStdErr('ripd') + log = net["r1"].getStdErr("ripd") if log: print("\nRIPd StdErr Log:\n" + log) - log = net['r1'].getStdErr('zebra') + log = net["r1"].getStdErr("zebra") if log: print("\nZebra StdErr Log:\n" + log) -if __name__ == '__main__': +if __name__ == "__main__": - setLogLevel('info') + 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"]) diff --git a/tests/topotests/ripng-topo1/test_ripng_topo1.py b/tests/topotests/ripng-topo1/test_ripng_topo1.py index 32b137240c..51f7fb6fb1 100755 --- a/tests/topotests/ripng-topo1/test_ripng_topo1.py +++ b/tests/topotests/ripng-topo1/test_ripng_topo1.py @@ -55,6 +55,7 @@ fatal_error = "" ## ##################################################### + class NetworkTopo(Topo): "RIPng Topology 1" @@ -64,33 +65,32 @@ class NetworkTopo(Topo): router = {} # # Setup Main Router - router[1] = topotest.addRouter(self, 'r1') + router[1] = topotest.addRouter(self, "r1") # # Setup RIPng Routers for i in range(2, 4): - router[i] = topotest.addRouter(self, 'r%s' % i) + router[i] = topotest.addRouter(self, "r%s" % i) # Setup Switches switch = {} # # On main router # First switch is for a dummy interface (for local network) - switch[1] = self.addSwitch('sw1', cls=topotest.LegacySwitch) - self.addLink(switch[1], router[1], intfName2='r1-eth0') + switch[1] = self.addSwitch("sw1", cls=topotest.LegacySwitch) + self.addLink(switch[1], router[1], intfName2="r1-eth0") # # Switches for RIPng # switch 2 switch is for connection to RIP router - switch[2] = self.addSwitch('sw2', cls=topotest.LegacySwitch) - self.addLink(switch[2], router[1], intfName2='r1-eth1') - self.addLink(switch[2], router[2], intfName2='r2-eth0') + switch[2] = self.addSwitch("sw2", cls=topotest.LegacySwitch) + self.addLink(switch[2], router[1], intfName2="r1-eth1") + self.addLink(switch[2], router[2], intfName2="r2-eth0") # switch 3 is between RIP routers - switch[3] = self.addSwitch('sw3', cls=topotest.LegacySwitch) - self.addLink(switch[3], router[2], intfName2='r2-eth1') - self.addLink(switch[3], router[3], intfName2='r3-eth1') + switch[3] = self.addSwitch("sw3", cls=topotest.LegacySwitch) + self.addLink(switch[3], router[2], intfName2="r2-eth1") + self.addLink(switch[3], router[3], intfName2="r3-eth1") # switch 4 is stub on remote RIP router - switch[4] = self.addSwitch('sw4', cls=topotest.LegacySwitch) - self.addLink(switch[4], router[3], intfName2='r3-eth0') - + switch[4] = self.addSwitch("sw4", cls=topotest.LegacySwitch) + self.addLink(switch[4], router[3], intfName2="r3-eth0") ##################################################### @@ -99,6 +99,7 @@ class NetworkTopo(Topo): ## ##################################################### + def setup_module(module): global topo, net @@ -106,7 +107,7 @@ def setup_module(module): print("******************************************\n") print("Cleanup old Mininet runs") - os.system('sudo mn -c > /dev/null 2>&1') + os.system("sudo mn -c > /dev/null 2>&1") thisDir = os.path.dirname(os.path.realpath(__file__)) topo = NetworkTopo() @@ -117,9 +118,9 @@ def setup_module(module): # Starting Routers # for i in range(1, 4): - net['r%s' % i].loadConf('zebra', '%s/r%s/zebra.conf' % (thisDir, i)) - net['r%s' % i].loadConf('ripngd', '%s/r%s/ripngd.conf' % (thisDir, i)) - net['r%s' % i].startRouter() + net["r%s" % i].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir, i)) + net["r%s" % i].loadConf("ripngd", "%s/r%s/ripngd.conf" % (thisDir, i)) + net["r%s" % i].startRouter() # For debugging after starting Quagga/FRR daemons, uncomment the next line # CLI(net) @@ -140,7 +141,7 @@ def test_router_running(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) print("\n\n** Check if FRR/Quagga is running on each Router node") @@ -148,7 +149,7 @@ def test_router_running(): # Starting Routers for i in range(1, 4): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -160,7 +161,7 @@ def test_converge_protocols(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -173,11 +174,11 @@ def test_converge_protocols(): # Make sure that all daemons are running for i in range(1, 4): - fatal_error = net['r%s' % i].checkRouterRunning() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line - #CLI(net) + # CLI(net) def test_ripng_status(): @@ -185,7 +186,7 @@ def test_ripng_status(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -195,41 +196,53 @@ def test_ripng_status(): print("******************************************\n") failures = 0 for i in range(1, 4): - refTableFile = '%s/r%s/ripng_status.ref' % (thisDir, i) + refTableFile = "%s/r%s/ripng_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) + expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) # Actual output from router - actual = net['r%s' % i].cmd('vtysh -c "show ipv6 ripng status" 2> /dev/null').rstrip() + actual = ( + net["r%s" % i] + .cmd('vtysh -c "show ipv6 ripng status" 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) - # Drop time in next due + # 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) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual IPv6 RIPng status", - title2="expected IPv6 RIPng status") + title2="expected IPv6 RIPng status", + ) # Empty string if it matches, otherwise diff contains unified diff if diff: - sys.stderr.write('r%s failed IPv6 RIPng status check:\n%s\n' % (i, diff)) + sys.stderr.write( + "r%s failed IPv6 RIPng status check:\n%s\n" % (i, diff) + ) failures += 1 else: print("r%s ok" % i) - assert failures == 0, "IPv6 RIPng status failed for router r%s:\n%s" % (i, diff) + assert failures == 0, "IPv6 RIPng status 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() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -241,7 +254,7 @@ def test_ripng_routes(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -251,42 +264,52 @@ def test_ripng_routes(): print("******************************************\n") failures = 0 for i in range(1, 4): - refTableFile = '%s/r%s/show_ipv6_ripng.ref' % (thisDir, i) + 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) + 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() + 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) + 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()]) + 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) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual SHOW IPv6 RIPng", - title2="expected 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)) + 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) + 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() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -298,7 +321,7 @@ def test_zebra_ipv6_routingTable(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -308,39 +331,51 @@ def test_zebra_ipv6_routingTable(): print("******************************************\n") failures = 0 for i in range(1, 4): - refTableFile = '%s/r%s/show_ipv6_route.ref' % (thisDir, i) + 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) + 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() + 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) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) # Generate Diff - diff = topotest.get_textdiff(actual, expected, + diff = topotest.get_textdiff( + actual, + expected, title1="actual Zebra IPv6 routing table", - title2="expected 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)) + 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) + 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() + fatal_error = net["r%s" % i].checkRouterRunning() assert fatal_error == "", fatal_error # For debugging after starting FRR/Quagga daemons, uncomment the next line @@ -352,24 +387,26 @@ def test_shutdown_check_stderr(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) - if os.environ.get('TOPOTESTS_CHECK_STDERR') is None: - print("SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n") - pytest.skip('Skipping test for Stderr output') + if os.environ.get("TOPOTESTS_CHECK_STDERR") is None: + print( + "SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n" + ) + pytest.skip("Skipping test for Stderr output") thisDir = os.path.dirname(os.path.realpath(__file__)) print("\n\n** Verifying unexpected STDERR output from daemons") print("******************************************\n") - net['r1'].stopRouter() + net["r1"].stopRouter() - log = net['r1'].getStdErr('ripngd') + log = net["r1"].getStdErr("ripngd") if log: print("\nRIPngd StdErr Log:\n" + log) - log = net['r1'].getStdErr('zebra') + log = net["r1"].getStdErr("zebra") if log: print("\nZebra StdErr Log:\n" + log) @@ -379,22 +416,26 @@ def test_shutdown_check_memleak(): global net # Skip if previous fatal error condition is raised - if (fatal_error != ""): + if fatal_error != "": pytest.skip(fatal_error) - if os.environ.get('TOPOTESTS_CHECK_MEMLEAK') is None: - print("SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)\n") - pytest.skip('Skipping test for memory leaks') - + if os.environ.get("TOPOTESTS_CHECK_MEMLEAK") is None: + print( + "SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)\n" + ) + pytest.skip("Skipping test for memory leaks") + thisDir = os.path.dirname(os.path.realpath(__file__)) - net['r1'].stopRouter() - net['r1'].report_memory_leaks(os.environ.get('TOPOTESTS_CHECK_MEMLEAK'), os.path.basename(__file__)) + net["r1"].stopRouter() + net["r1"].report_memory_leaks( + os.environ.get("TOPOTESTS_CHECK_MEMLEAK"), os.path.basename(__file__) + ) -if __name__ == '__main__': +if __name__ == "__main__": - setLogLevel('info') + 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"]) diff --git a/tests/topotests/zebra_rib/test_zebra_rib.py b/tests/topotests/zebra_rib/test_zebra_rib.py index d73f613f95..17eb736cab 100755 --- a/tests/topotests/zebra_rib/test_zebra_rib.py +++ b/tests/topotests/zebra_rib/test_zebra_rib.py @@ -34,7 +34,7 @@ import json # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -45,24 +45,27 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from mininet.topo import Topo + class ZebraTopo(Topo): "Test topology builder" + def build(self, *_args, **_opts): "Build function" tgen = get_topogen(self) - tgen.add_router('r1') + tgen.add_router("r1") # Create a empty network for router 1 - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r1']) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r1"]) + def setup_module(mod): "Sets up the pytest environment" @@ -72,78 +75,86 @@ def setup_module(mod): router_list = tgen.routers() for rname, router in router_list.iteritems(): router.load_config( - TopoRouter.RD_ZEBRA, - os.path.join(CWD, '{}/zebra.conf'.format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) # Initialize all routers. tgen.start_router() + def teardown_module(mod): "Teardown the pytest environment" tgen = get_topogen() tgen.stop_topology() + def test_zebra_kernel_admin_distance(): "Test some basic kernel routes added that should be accepted" logger.info("Test some basic kernel routes that should be accepted") tgen = get_topogen() if tgen.routers_have_failure(): - pytest.skip('skipped because of router(s) failure') + pytest.skip("skipped because of router(s) failure") - r1 = tgen.gears['r1'] + r1 = tgen.gears["r1"] # Route with 255/8192 metric - r1.run('ip route add 4.5.1.0/24 via 192.168.210.2 dev r1-eth0 metric 4278198272') + r1.run("ip route add 4.5.1.0/24 via 192.168.210.2 dev r1-eth0 metric 4278198272") # Route with 1/1 metric - r1.run('ip route add 4.5.2.0/24 via 192.168.211.2 dev r1-eth1 metric 16777217') + r1.run("ip route add 4.5.2.0/24 via 192.168.211.2 dev r1-eth1 metric 16777217") # Route with 10/1 metric - r1.run('ip route add 4.5.3.0/24 via 192.168.212.2 dev r1-eth2 metric 167772161') + r1.run("ip route add 4.5.3.0/24 via 192.168.212.2 dev r1-eth2 metric 167772161") # Same route with a 160/1 metric - r1.run('ip route add 4.5.3.0/24 via 192.168.213.2 dev r1-eth3 metric 2684354561') + r1.run("ip route add 4.5.3.0/24 via 192.168.213.2 dev r1-eth3 metric 2684354561") - #Currently I believe we have a bug here with the same route and different - #metric. That needs to be properly resolved. Making a note for - #coming back around later and fixing this. - #tgen.mininet_cli() + # Currently I believe we have a bug here with the same route and different + # metric. That needs to be properly resolved. Making a note for + # coming back around later and fixing this. + # tgen.mininet_cli() for i in range(1, 2): - json_file = '{}/r1/v4_route_{}.json'.format(CWD, i) + json_file = "{}/r1/v4_route_{}.json".format(CWD, i) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - r1, - 'show ip route 4.5.{}.0 json'.format(i), - expected) - _, result = topotest.run_and_expect(test_func, None, count=2, wait=.5) + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip route 4.5.{}.0 json".format(i), + expected, + ) + _, result = topotest.run_and_expect(test_func, None, count=2, wait=0.5) assertmsg = '"r1" JSON output mismatches' assert result is None, assertmsg - #tgen.mininet_cli() + # tgen.mininet_cli() + def test_zebra_kernel_override(): "Test that a FRR route with a lower admin distance takes over" logger.info("Test kernel override with a better admin distance") tgen = get_topogen() - if (tgen.routers_have_failure()): + if tgen.routers_have_failure(): ptyest.skip("skipped because of preview test failure") - r1 = tgen.gears['r1'] + r1 = tgen.gears["r1"] r1.vtysh_cmd("conf\nip route 4.5.1.0/24 192.168.216.3") - json_file = '{}/r1/v4_route_1_static_override.json'.format(CWD) + json_file = "{}/r1/v4_route_1_static_override.json".format(CWD) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - r1, 'show ip route 4.5.1.0 json', expected) - _, result = topotest.run_and_expect(test_func, None, count=2, wait=.5) + test_func = partial( + topotest.router_json_cmp, r1, "show ip route 4.5.1.0 json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=2, wait=0.5) assert result is None, '"r1" JSON output mismatches' - logger.info("Test that the removal of the static route allows the kernel to take back over") + logger.info( + "Test that the removal of the static route allows the kernel to take back over" + ) r1.vtysh_cmd("conf\nno ip route 4.5.1.0/24 192.168.216.3") - json_file = '{}/r1/v4_route_1.json'.format(CWD) + json_file = "{}/r1/v4_route_1.json".format(CWD) expected = json.loads(open(json_file).read()) - test_func = partial(topotest.router_json_cmp, - r1, 'show ip route 4.5.1.0 json', expected) - _, result = topotest.run_and_expect(test_func, None, count=2, wait=.5) + test_func = partial( + topotest.router_json_cmp, r1, "show ip route 4.5.1.0 json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=2, wait=0.5) assert result is None, '"r1" JSON output mismatches' @@ -151,10 +162,11 @@ def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() if not tgen.is_memleak_enabled(): - pytest.skip('Memory leak test/report is disabled') + pytest.skip("Memory leak test/report is disabled") tgen.report_memory_leaks() -if __name__ == '__main__': + +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args))