]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_minimum_holdtime/test_bgp_minimum_holdtime.py
Merge pull request #9497 from opensourcerouting/cli-better-no
[mirror_frr.git] / tests / topotests / bgp_minimum_holdtime / test_bgp_minimum_holdtime.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2021 by
4 # Takemasa Imada <takemasa.imada@gmail.com>
5 #
6 # Permission to use, copy, modify, and/or distribute this software
7 # for any purpose with or without fee is hereby granted, provided
8 # that the above copyright notice and this permission notice appear
9 # in all copies.
10 #
11 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
15 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
16 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
17 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
18 # OF THIS SOFTWARE.
19 #
20
21 """
22 Test if minimum-holdtime works.
23 """
24
25 import os
26 import sys
27 import json
28 import pytest
29 import functools
30
31 CWD = os.path.dirname(os.path.realpath(__file__))
32 sys.path.append(os.path.join(CWD, "../"))
33
34 # pylint: disable=C0413
35 from lib import topotest
36 from lib.topogen import Topogen, TopoRouter, get_topogen
37
38 pytestmark = [pytest.mark.bgpd]
39
40
41 def build_topo(tgen):
42 for routern in range(1, 3):
43 tgen.add_router("r{}".format(routern))
44
45 switch = tgen.add_switch("s1")
46 switch.add_link(tgen.gears["r1"])
47 switch.add_link(tgen.gears["r2"])
48
49
50 def setup_module(mod):
51 tgen = Topogen(build_topo, mod.__name__)
52 tgen.start_topology()
53
54 router_list = tgen.routers()
55
56 for i, (rname, router) in enumerate(router_list.items(), 1):
57 router.load_config(
58 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
59 )
60 router.load_config(
61 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
62 )
63
64 tgen.start_router()
65
66
67 def teardown_module(mod):
68 tgen = get_topogen()
69 tgen.stop_topology()
70
71
72 def test_bgp_minimum_holdtime():
73 tgen = get_topogen()
74
75 if tgen.routers_have_failure():
76 pytest.skip(tgen.errors)
77
78 def _bgp_neighbor_check_if_notification_sent():
79 output = json.loads(
80 tgen.gears["r1"].vtysh_cmd("show ip bgp neighbor 192.168.255.2 json")
81 )
82 expected = {
83 "192.168.255.2": {
84 "connectionsEstablished": 0,
85 "lastNotificationReason": "OPEN Message Error/Unacceptable Hold Time",
86 "lastResetDueTo": "BGP Notification send",
87 }
88 }
89 return topotest.json_cmp(output, expected)
90
91 test_func = functools.partial(_bgp_neighbor_check_if_notification_sent)
92 success, result = topotest.run_and_expect(test_func, None, count=40, wait=0.5)
93 assert result is None, "Failed to send notification message\n"
94
95
96 if __name__ == "__main__":
97 args = ["-s"] + sys.argv[1:]
98 sys.exit(pytest.main(args))