diff options
Diffstat (limited to 'tests/topotests')
| -rw-r--r-- | tests/topotests/bgp_rpki_topo1/test_bgp_rpki_topo1.py | 115 | ||||
| -rw-r--r-- | tests/topotests/lib/common_config.py | 66 | ||||
| -rw-r--r-- | tests/topotests/static_simple/test_static_simple.py | 20 |
3 files changed, 165 insertions, 36 deletions
diff --git a/tests/topotests/bgp_rpki_topo1/test_bgp_rpki_topo1.py b/tests/topotests/bgp_rpki_topo1/test_bgp_rpki_topo1.py index 5b775aa6cb..bdf905feba 100644 --- a/tests/topotests/bgp_rpki_topo1/test_bgp_rpki_topo1.py +++ b/tests/topotests/bgp_rpki_topo1/test_bgp_rpki_topo1.py @@ -477,6 +477,121 @@ def test_bgp_ecommunity_rpki(): assert result is None, "Received RPKI extended community" +def test_show_bgp_rpki_as_number(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["r1", "r3"]: + logger.info("{}: checking if rtrd is running".format(rname)) + if rtrd_process[rname].poll() is not None: + pytest.skip(tgen.errors) + + step("Check RPKI prefixes for ASN 65531") + + rname = "r2" + output = json.loads(tgen.gears[rname].vtysh_cmd("show rpki as-number 65531 json")) + + # Expected output should show no prefixes for this ASN + expected = {"ipv4PrefixCount": 0, "ipv6PrefixCount": 0, "prefixes": []} + + assert output == expected, "Found unexpected RPKI prefixes for ASN 65531" + + +def test_show_bgp_rpki_as_number_65530(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["r1", "r3"]: + logger.info("{}: checking if rtrd is running".format(rname)) + if rtrd_process[rname].poll() is not None: + pytest.skip(tgen.errors) + + step("Check RPKI prefixes for ASN 65530") + + rname = "r2" + output = json.loads(tgen.gears[rname].vtysh_cmd("show rpki as-number 65530 json")) + + expected = { + "prefixes": [ + { + "prefix": "198.51.100.0", + "prefixLenMin": 24, + "prefixLenMax": 24, + "asn": 65530, + }, + { + "prefix": "203.0.113.0", + "prefixLenMin": 24, + "prefixLenMax": 24, + "asn": 65530, + }, + ], + "ipv4PrefixCount": 2, + "ipv6PrefixCount": 0, + } + + assert ( + output == expected + ), "RPKI prefixes for ASN 65530 do not match expected output" + + +def test_rpki_stop_and_check_connection(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["r1", "r3"]: + logger.info("{}: checking if rtrd is running".format(rname)) + if rtrd_process[rname].poll() is not None: + pytest.skip(tgen.errors) + + step("Stop RPKI on r2") + rname = "r2" + tgen.gears[rname].vtysh_cmd("rpki stop") + + step("Check RPKI cache connection status") + output = json.loads(tgen.gears[rname].vtysh_cmd("show rpki cache-connection json")) + + expected = {"error": "No connection to RPKI cache server."} + assert ( + output == expected + ), "RPKI cache connection status does not show as disconnected" + + +def test_rpki_start_and_check_connection(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["r1", "r3"]: + logger.info("{}: checking if rtrd is running".format(rname)) + if rtrd_process[rname].poll() is not None: + pytest.skip(tgen.errors) + + step("Start RPKI on r2") + rname = "r2" + tgen.gears[rname].vtysh_cmd("rpki start") + + def _check_rpki_connection(): + output = json.loads( + tgen.gears[rname].vtysh_cmd("show rpki cache-connection json") + ) + # We expect to see a connected group and at least one connection + return "connectedGroup" in output and "connections" in output + + step("Check RPKI cache connection status") + _, result = topotest.run_and_expect( + _check_rpki_connection, True, count=60, wait=0.5 + ) + assert result, "RPKI cache connection did not establish after start" + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index 54142e8526..a19c61b19d 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -330,13 +330,12 @@ def create_common_configurations( for router in routers: fname = "{}/{}/{}".format(tgen.logdir, router, FRRCFG_FILE) try: - frr_cfg_fd = open(fname, mode) - if config_type: - frr_cfg_fd.write(config_map[config_type]) - for line in config_dict[router]: - frr_cfg_fd.write("{} \n".format(str(line))) - frr_cfg_fd.write("\n") - + with open(fname, mode) as frr_cfg_fd: + if config_type: + frr_cfg_fd.write(config_map[config_type]) + for line in config_dict[router]: + frr_cfg_fd.write("{} \n".format(str(line))) + frr_cfg_fd.write("\n") except IOError as err: logger.error("Unable to open FRR Config '%s': %s" % (fname, str(err))) return False @@ -487,12 +486,13 @@ def save_initial_config_on_routers(tgen): procs = {} for rname in router_list: logger.debug("Fetching running config for router %s", rname) - procs[rname] = router_list[rname].popen( - ["/usr/bin/env", "vtysh", "-c", "show running-config no-header"], - stdin=None, - stdout=open(target_cfg_fmt.format(rname), "w"), - stderr=subprocess.PIPE, - ) + with open(target_cfg_fmt.format(rname), "w") as target_cfg_fd: + procs[rname] = router_list[rname].popen( + ["/usr/bin/env", "vtysh", "-c", "show running-config no-header"], + stdin=None, + stdout=target_cfg_fd, + stderr=subprocess.PIPE, + ) for rname, p in procs.items(): _, error = p.communicate() if p.returncode: @@ -543,12 +543,13 @@ def reset_config_on_routers(tgen, routerName=None): procs = {} for rname in router_list: logger.debug("Fetching running config for router %s", rname) - procs[rname] = router_list[rname].popen( - ["/usr/bin/env", "vtysh", "-c", "show running-config no-header"], - stdin=None, - stdout=open(run_cfg_fmt.format(rname, gen), "w"), - stderr=subprocess.PIPE, - ) + with open(run_cfg_fmt.format(rname, gen), "w") as run_cfg_fd: + procs[rname] = router_list[rname].popen( + ["/usr/bin/env", "vtysh", "-c", "show running-config no-header"], + stdin=None, + stdout=run_cfg_fd, + stderr=subprocess.PIPE, + ) for rname, p in procs.items(): _, error = p.communicate() if p.returncode: @@ -567,19 +568,20 @@ def reset_config_on_routers(tgen, routerName=None): logger.debug( "Generating delta for router %s to new configuration (gen %d)", rname, gen ) - procs[rname] = tgen.net.popen( - [ - "/usr/lib/frr/frr-reload.py", - "--test-reset", - "--input", - run_cfg_fmt.format(rname, gen), - "--test", - target_cfg_fmt.format(rname), - ], - stdin=None, - stdout=open(delta_fmt.format(rname, gen), "w"), - stderr=subprocess.PIPE, - ) + with open(delta_fmt.format(rname, gen), "w") as delta_fd: + procs[rname] = tgen.net.popen( + [ + "/usr/lib/frr/frr-reload.py", + "--test-reset", + "--input", + run_cfg_fmt.format(rname, gen), + "--test", + target_cfg_fmt.format(rname), + ], + stdin=None, + stdout=delta_fd, + stderr=subprocess.PIPE, + ) for rname, p in procs.items(): _, error = p.communicate() if p.returncode: diff --git a/tests/topotests/static_simple/test_static_simple.py b/tests/topotests/static_simple/test_static_simple.py index afde58fbf7..615d1621f3 100644 --- a/tests/topotests/static_simple/test_static_simple.py +++ b/tests/topotests/static_simple/test_static_simple.py @@ -111,6 +111,7 @@ def do_config_inner( count, add=True, do_ipv6=False, + do_ipv6_nexthop=False, do_sadr=False, via=None, vrf=None, @@ -129,6 +130,8 @@ def do_config_inner( src_prefs = ["2001:db8:1111::/48", "2001:db8:2222::/48"] elif do_ipv6: super_prefs = ["2001::/48", "2002::/48"] + elif do_ipv6_nexthop: + super_prefs = ["11.0.0.0/8", "21.0.0.0/8"] else: super_prefs = ["10.0.0.0/8", "20.0.0.0/8"] @@ -142,11 +145,19 @@ def do_config_inner( matchvia = f"dev {via}" else: if vrf: - via = "2102::2" if do_ipv6 else "102.0.0.2" - matchvia = f"via {via} dev r1-eth1" + via = "2102::2" if do_ipv6 or do_ipv6_nexthop else "102.0.0.2" + matchvia = ( + f"via inet6 {via} dev r1-eth1" + if not do_ipv6 and do_ipv6_nexthop + else f"via {via} dev r1-eth1" + ) else: - via = "2101::2" if do_ipv6 else "101.0.0.2" - matchvia = f"via {via} dev r1-eth0" + via = "2101::2" if do_ipv6 or do_ipv6_nexthop else "101.0.0.2" + matchvia = ( + f"via inet6 {via} dev r1-eth0" + if not do_ipv6 and do_ipv6_nexthop + else f"via {via} dev r1-eth0" + ) vrfdbg = " in vrf {}".format(vrf) if vrf else "" logger.debug("{} {} static {} routes{}".format(optype, count, iptype, vrfdbg)) @@ -201,6 +212,7 @@ def do_config_inner( def do_config(*args, **kwargs): do_config_inner(*args, do_ipv6=False, do_sadr=False, **kwargs) + do_config_inner(*args, do_ipv6=False, do_ipv6_nexthop=True, **kwargs) do_config_inner(*args, do_ipv6=True, do_sadr=False, **kwargs) do_config_inner(*args, do_ipv6=True, do_sadr=True, **kwargs) |
