From 98c9d21b52b6ff9627b683e28b434a6a6f697e56 Mon Sep 17 00:00:00 2001 From: Alexander Skorichenko Date: Thu, 23 Jan 2025 11:20:24 +0100 Subject: [PATCH] tests: bgp routers with vrf cross import Signed-off-by: Alexander Skorichenko --- .../bgp_router_vrf_cross_import/r1/frr.conf | 23 ++++++ .../test_cross_import.py | 79 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 tests/topotests/bgp_router_vrf_cross_import/r1/frr.conf create mode 100644 tests/topotests/bgp_router_vrf_cross_import/test_cross_import.py diff --git a/tests/topotests/bgp_router_vrf_cross_import/r1/frr.conf b/tests/topotests/bgp_router_vrf_cross_import/r1/frr.conf new file mode 100644 index 000000000000..d03468d28896 --- /dev/null +++ b/tests/topotests/bgp_router_vrf_cross_import/r1/frr.conf @@ -0,0 +1,23 @@ +! +int r1-eth0 + ip address 10.255.0.1/24 +! +vrf D +exit-vrf +! +router bgp 65001 vrf D + ! + bgp router-id 10.255.0.1 + address-family ipv4 unicast + import vrf default + exit-address-family +exit +! +router bgp 65001 + ! + bgp router-id 10.255.0.1 + address-family ipv4 unicast + import vrf D + exit-address-family +exit +! diff --git a/tests/topotests/bgp_router_vrf_cross_import/test_cross_import.py b/tests/topotests/bgp_router_vrf_cross_import/test_cross_import.py new file mode 100644 index 000000000000..a64c5ed8c38a --- /dev/null +++ b/tests/topotests/bgp_router_vrf_cross_import/test_cross_import.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +import functools, json, os, pytest, re, sys + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +from lib import topotest +from lib.topogen import Topogen, get_topogen + +pytestmark = [pytest.mark.bgpd] + + +def setup_module(mod): + topodef = {"s1": ("r1")} + tgen = Topogen(topodef, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for _, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config( + os.path.join(CWD, "{}/frr.conf".format(rname)) + ) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_remote_as_auto(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + + def _bgp_router_vrf_custom(): + output = json.loads( + r1.vtysh_cmd("show bgp vrf D detail json") + ) + expected = { + "vrfName": "D", + "localAS": 65001 + } + + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_router_vrf_custom, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "bgp router 65001 vrf D failed" + + def _bgp_router_vrf_default(): + output = json.loads( + r1.vtysh_cmd("show bgp detail json") + ) + expected = { + "vrfName": "default", + "localAS": 65001 + } + + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_router_vrf_default, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "bgp router 65001 failed in default vrf" + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args))