]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_vrf_leaking_rt_change_route_maps/test_bgp_vrf_leaking_rt_change_route_maps.py
tests: Check if old paths are flushed when import/export RT list was changed
[mirror_frr.git] / tests / topotests / bgp_vrf_leaking_rt_change_route_maps / test_bgp_vrf_leaking_rt_change_route_maps.py
CommitLineData
c170a608
DA
1#!/usr/bin/env python
2
3#
4# Copyright (c) 2022 by
5# Donatas Abraitis <donatas@opensourcerouting.org>
6#
7# Permission to use, copy, modify, and/or distribute this software
8# for any purpose with or without fee is hereby granted, provided
9# that the above copyright notice and this permission notice appear
10# in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
19# OF THIS SOFTWARE.
20#
21
22"""
23If we overwrite import/export RT list via route-maps or even flush by using
24`set extcommunity none`, then we must withdraw old paths from VRFs to avoid
25stale paths.
26"""
27
28import os
29import sys
30import json
31import pytest
32import functools
33
34CWD = os.path.dirname(os.path.realpath(__file__))
35sys.path.append(os.path.join(CWD, "../"))
36
37# pylint: disable=C0413
38from lib import topotest
39from lib.topogen import Topogen, TopoRouter, get_topogen
40from lib.common_config import step
41
42pytestmark = [pytest.mark.bgpd]
43
44
45def build_topo(tgen):
46 tgen.add_router("r1")
47
48
49def setup_module(mod):
50 tgen = Topogen(build_topo, mod.__name__)
51 tgen.start_topology()
52
53 router = tgen.gears["r1"]
54 router.cmd_raises("ip link add vrf1 type vrf table 10")
55 router.cmd_raises("ip link set up dev vrf1")
56 router.cmd_raises("ip link add vrf2 type vrf table 20")
57 router.cmd_raises("ip link set up dev vrf2")
58 router.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, "r1/zebra.conf"))
59 router.load_config(TopoRouter.RD_BGP, os.path.join(CWD, "r1/bgpd.conf"))
60 router.start()
61
62
63def teardown_module(mod):
64 tgen = get_topogen()
65 tgen.stop_topology()
66
67
68def test_bgp_vrf_leaking_rt_change_route_maps():
69 tgen = get_topogen()
70
71 router = tgen.gears["r1"]
72
73 if tgen.routers_have_failure():
74 pytest.skip(tgen.errors)
75
76 def _bgp_check_path():
77 output = json.loads(router.vtysh_cmd("show bgp vrf vrf2 ipv4 unicast json"))
78 expected = {"routes": {"192.168.100.100/32": [{"nhVrfName": "vrf1"}]}}
79 return topotest.json_cmp(output, expected)
80
81 step("Initial converge")
82 test_func = functools.partial(_bgp_check_path)
83 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
84 assert result is None, "Can't see 192.168.100.100/32 leaked from vrf1 into vrf2."
85
86 step("Overwrite RT list (remove rt 65500:11990 from route-map)")
87 router.vtysh_cmd(
88 """
89 config terminal
90 route-map rm permit 10
91 set extcommunity rt 65500:10100
92 exit
93 """
94 )
95
96 step("Check if 192.168.100.100/32 was removed from vrf2")
97 test_func = functools.partial(_bgp_check_path)
98 _, result = topotest.run_and_expect(test_func, not None, count=20, wait=0.5)
99 assert result is not None, "192.168.100.100/32 still exists in vrf2 as stale."
100
101
102if __name__ == "__main__":
103 args = ["-s"] + sys.argv[1:]
104 sys.exit(pytest.main(args))