]>
Commit | Line | Data |
---|---|---|
c170a608 | 1 | #!/usr/bin/env python |
acddc0ed | 2 | # SPDX-License-Identifier: ISC |
c170a608 DA |
3 | |
4 | # | |
5 | # Copyright (c) 2022 by | |
6 | # Donatas Abraitis <donatas@opensourcerouting.org> | |
7 | # | |
c170a608 DA |
8 | |
9 | """ | |
10 | If we overwrite import/export RT list via route-maps or even flush by using | |
11 | `set extcommunity none`, then we must withdraw old paths from VRFs to avoid | |
12 | stale paths. | |
13 | """ | |
14 | ||
15 | import os | |
16 | import sys | |
17 | import json | |
18 | import pytest | |
19 | import functools | |
20 | ||
21 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
22 | sys.path.append(os.path.join(CWD, "../")) | |
23 | ||
24 | # pylint: disable=C0413 | |
25 | from lib import topotest | |
26 | from lib.topogen import Topogen, TopoRouter, get_topogen | |
27 | from lib.common_config import step | |
28 | ||
29 | pytestmark = [pytest.mark.bgpd] | |
30 | ||
31 | ||
32 | def build_topo(tgen): | |
33 | tgen.add_router("r1") | |
34 | ||
35 | ||
36 | def setup_module(mod): | |
37 | tgen = Topogen(build_topo, mod.__name__) | |
38 | tgen.start_topology() | |
39 | ||
40 | router = tgen.gears["r1"] | |
41 | router.cmd_raises("ip link add vrf1 type vrf table 10") | |
42 | router.cmd_raises("ip link set up dev vrf1") | |
43 | router.cmd_raises("ip link add vrf2 type vrf table 20") | |
44 | router.cmd_raises("ip link set up dev vrf2") | |
45 | router.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, "r1/zebra.conf")) | |
46 | router.load_config(TopoRouter.RD_BGP, os.path.join(CWD, "r1/bgpd.conf")) | |
47 | router.start() | |
48 | ||
49 | ||
50 | def teardown_module(mod): | |
51 | tgen = get_topogen() | |
52 | tgen.stop_topology() | |
53 | ||
54 | ||
55 | def test_bgp_vrf_leaking_rt_change_route_maps(): | |
56 | tgen = get_topogen() | |
57 | ||
58 | router = tgen.gears["r1"] | |
59 | ||
60 | if tgen.routers_have_failure(): | |
61 | pytest.skip(tgen.errors) | |
62 | ||
63 | def _bgp_check_path(): | |
64 | output = json.loads(router.vtysh_cmd("show bgp vrf vrf2 ipv4 unicast json")) | |
65 | expected = {"routes": {"192.168.100.100/32": [{"nhVrfName": "vrf1"}]}} | |
66 | return topotest.json_cmp(output, expected) | |
67 | ||
68 | step("Initial converge") | |
69 | test_func = functools.partial(_bgp_check_path) | |
70 | _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) | |
71 | assert result is None, "Can't see 192.168.100.100/32 leaked from vrf1 into vrf2." | |
72 | ||
73 | step("Overwrite RT list (remove rt 65500:11990 from route-map)") | |
74 | router.vtysh_cmd( | |
75 | """ | |
76 | config terminal | |
77 | route-map rm permit 10 | |
78 | set extcommunity rt 65500:10100 | |
79 | exit | |
80 | """ | |
81 | ) | |
82 | ||
83 | step("Check if 192.168.100.100/32 was removed from vrf2") | |
84 | test_func = functools.partial(_bgp_check_path) | |
85 | _, result = topotest.run_and_expect(test_func, not None, count=20, wait=0.5) | |
86 | assert result is not None, "192.168.100.100/32 still exists in vrf2 as stale." | |
87 | ||
88 | ||
89 | if __name__ == "__main__": | |
90 | args = ["-s"] + sys.argv[1:] | |
91 | sys.exit(pytest.main(args)) |