]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_peer_group/test_bgp_peer-group.py
tests: remove legacy Topo class (fixes many pylint errors)
[mirror_frr.git] / tests / topotests / bgp_peer_group / test_bgp_peer-group.py
CommitLineData
2f8e3650
DA
1#!/usr/bin/env python
2
3#
4# Copyright (c) 2021 by
5# Donatas Abraitis <donatas.abraitis@gmail.com>
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"""
23Test if peer-group works for numbered and unnumbered configurations.
24"""
25
26import os
27import sys
28import json
29import pytest
30import functools
31
32CWD = os.path.dirname(os.path.realpath(__file__))
33sys.path.append(os.path.join(CWD, "../"))
34
35# pylint: disable=C0413
36from lib import topotest
37from lib.topogen import Topogen, TopoRouter, get_topogen
38from lib.topolog import logger
8db751b8 39from lib.micronet_compat import Topo
2f8e3650
DA
40
41
98ca91e1
DS
42pytestmark = [pytest.mark.bgpd]
43
44
e82b531d
CH
45def build_topo(tgen):
46 for routern in range(1, 4):
47 tgen.add_router("r{}".format(routern))
2f8e3650 48
e82b531d
CH
49 switch = tgen.add_switch("s1")
50 switch.add_link(tgen.gears["r1"])
51 switch.add_link(tgen.gears["r2"])
52 switch.add_link(tgen.gears["r3"])
2f8e3650
DA
53
54
55def setup_module(mod):
e82b531d 56 tgen = Topogen(build_topo, mod.__name__)
2f8e3650
DA
57 tgen.start_topology()
58
59 router_list = tgen.routers()
60
61 for i, (rname, router) in enumerate(router_list.items(), 1):
62 router.load_config(
63 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
64 )
65 router.load_config(
66 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
67 )
68
69 tgen.start_router()
70
71
72def teardown_module(mod):
73 tgen = get_topogen()
74 tgen.stop_topology()
75
76
77def test_bgp_peer_group():
78 tgen = get_topogen()
79
80 if tgen.routers_have_failure():
81 pytest.skip(tgen.errors)
82
83 def _bgp_peer_group_configured():
84 output = json.loads(tgen.gears["r1"].vtysh_cmd("show ip bgp neighbor json"))
85 expected = {
86 "r1-eth0": {"peerGroup": "PG", "bgpState": "Established"},
87 "192.168.255.3": {"peerGroup": "PG", "bgpState": "Established"},
88 }
89 return topotest.json_cmp(output, expected)
90
91 test_func = functools.partial(_bgp_peer_group_configured)
92 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
93
94 assert result is None, 'Failed bgp convergence in "{}"'.format(tgen.gears["r1"])
95
96
97if __name__ == "__main__":
98 args = ["-s"] + sys.argv[1:]
99 sys.exit(pytest.main(args))