]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_peer_graceful_shutdown/test_bgp_peer_graceful_shutdown.py
Merge pull request #12805 from karlquan/kquan_self_orig
[mirror_frr.git] / tests / topotests / bgp_peer_graceful_shutdown / test_bgp_peer_graceful_shutdown.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 # Copyright (c) 2022 by
5 # Donatas Abraitis <donatas@opensourcerouting.org>
6 #
7
8 """
9 Check if routes from R1 has local-preference set to 0 and graceful-shutdown
10 community.
11 """
12
13 import os
14 import sys
15 import json
16 import pytest
17 import functools
18
19 pytestmark = pytest.mark.bgpd
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 setup_module(mod):
33 topodef = {"s1": ("r1", "r2"), "s2": ("r2", "r3")}
34 tgen = Topogen(topodef, mod.__name__)
35 tgen.start_topology()
36
37 router_list = tgen.routers()
38
39 for i, (rname, router) in enumerate(router_list.items(), 1):
40 router.load_config(
41 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
42 )
43 router.load_config(
44 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
45 )
46
47 tgen.start_router()
48
49
50 def teardown_module(mod):
51 tgen = get_topogen()
52 tgen.stop_topology()
53
54
55 def test_bgp_orf():
56 tgen = get_topogen()
57
58 if tgen.routers_have_failure():
59 pytest.skip(tgen.errors)
60
61 r2 = tgen.gears["r2"]
62 r3 = tgen.gears["r3"]
63
64 def _bgp_converge():
65 output = json.loads(
66 r2.vtysh_cmd(
67 "show bgp ipv4 unicast neighbor 192.168.2.2 advertised-routes json"
68 )
69 )
70 expected = {"advertisedRoutes": {"10.10.10.1/32": {"locPrf": 100}}}
71 return topotest.json_cmp(output, expected)
72
73 test_func = functools.partial(_bgp_converge)
74 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
75 assert result is None, "Can't converge at R2"
76
77 step("Mark routes from R1 as graceful-shutdown")
78 r2.vtysh_cmd(
79 """
80 configure terminal
81 router bgp
82 neighbor 192.168.1.1 graceful-shutdown
83 """
84 )
85
86 def _bgp_check_peer_graceful_shutdown():
87 output = json.loads(r3.vtysh_cmd("show bgp ipv4 unicast 10.10.10.1/32 json"))
88 expected = {
89 "paths": [
90 {
91 "locPrf": 0,
92 "community": {"string": "graceful-shutdown"},
93 }
94 ]
95 }
96 return topotest.json_cmp(output, expected)
97
98 test_func = functools.partial(_bgp_check_peer_graceful_shutdown)
99 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
100 assert (
101 result is None
102 ), "local-preference is not 0 and/or graceful-shutdown community missing"
103
104
105 if __name__ == "__main__":
106 args = ["-s"] + sys.argv[1:]
107 sys.exit(pytest.main(args))