]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_peer_group/test_bgp_peer-group.py
tests: micronet: adapt tests
[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
2f8e3650
DA
45class TemplateTopo(Topo):
46 def build(self, *_args, **_opts):
47 tgen = get_topogen(self)
48
49 for routern in range(1, 4):
50 tgen.add_router("r{}".format(routern))
51
52 switch = tgen.add_switch("s1")
53 switch.add_link(tgen.gears["r1"])
54 switch.add_link(tgen.gears["r2"])
55 switch.add_link(tgen.gears["r3"])
56
57
58def setup_module(mod):
59 tgen = Topogen(TemplateTopo, mod.__name__)
60 tgen.start_topology()
61
62 router_list = tgen.routers()
63
64 for i, (rname, router) in enumerate(router_list.items(), 1):
65 router.load_config(
66 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
67 )
68 router.load_config(
69 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
70 )
71
72 tgen.start_router()
73
74
75def teardown_module(mod):
76 tgen = get_topogen()
77 tgen.stop_topology()
78
79
80def test_bgp_peer_group():
81 tgen = get_topogen()
82
83 if tgen.routers_have_failure():
84 pytest.skip(tgen.errors)
85
86 def _bgp_peer_group_configured():
87 output = json.loads(tgen.gears["r1"].vtysh_cmd("show ip bgp neighbor json"))
88 expected = {
89 "r1-eth0": {"peerGroup": "PG", "bgpState": "Established"},
90 "192.168.255.3": {"peerGroup": "PG", "bgpState": "Established"},
91 }
92 return topotest.json_cmp(output, expected)
93
94 test_func = functools.partial(_bgp_peer_group_configured)
95 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
96
97 assert result is None, 'Failed bgp convergence in "{}"'.format(tgen.gears["r1"])
98
99
100if __name__ == "__main__":
101 args = ["-s"] + sys.argv[1:]
102 sys.exit(pytest.main(args))