]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_dont_capability_negotiate/test_bgp_dont_capability_negotiate.py
Merge pull request #9697 from SaiGomathiN/igmp-sources
[mirror_frr.git] / tests / topotests / bgp_dont_capability_negotiate / test_bgp_dont_capability_negotiate.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2021 by
4 # Donatas Abraitis <donatas.abraitis@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 BGP connection is established if at least one peer
23 sets `dont-capability-negotiate`.
24 """
25
26 import os
27 import sys
28 import json
29 import pytest
30 import functools
31
32 pytestmark = pytest.mark.bgpd
33
34 CWD = os.path.dirname(os.path.realpath(__file__))
35 sys.path.append(os.path.join(CWD, "../"))
36
37 # pylint: disable=C0413
38 from lib import topotest
39 from lib.topogen import Topogen, TopoRouter, get_topogen
40
41 pytestmark = [pytest.mark.bgpd]
42
43
44 def setup_module(mod):
45 topodef = {"s1": ("r1", "r2")}
46 tgen = Topogen(topodef, mod.__name__)
47 tgen.start_topology()
48
49 router_list = tgen.routers()
50
51 for i, (rname, router) in enumerate(router_list.items(), 1):
52 router.load_config(
53 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
54 )
55 router.load_config(
56 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
57 )
58
59 tgen.start_router()
60
61
62 def teardown_module(mod):
63 tgen = get_topogen()
64 tgen.stop_topology()
65
66
67 def test_bgp_dont_capability_negotiate():
68 tgen = get_topogen()
69
70 if tgen.routers_have_failure():
71 pytest.skip(tgen.errors)
72
73 router = tgen.gears["r1"]
74
75 def _bgp_converge(router):
76 output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast summary json"))
77 expected = {
78 "peers": {
79 "192.168.1.2": {
80 "pfxRcd": 2,
81 "pfxSnt": 2,
82 "state": "Established",
83 "peerState": "OK",
84 }
85 }
86 }
87 return topotest.json_cmp(output, expected)
88
89 test_func = functools.partial(_bgp_converge, router)
90 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
91 assert result is None, "Can't converge with dont-capability-negotiate"
92
93
94 if __name__ == "__main__":
95 args = ["-s"] + sys.argv[1:]
96 sys.exit(pytest.main(args))