]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py
Merge pull request #9533 from mobash-rasool/ospfv3-bug-fixes
[mirror_frr.git] / tests / topotests / bgp_suppress_fib / test_bgp_suppress_fib.py
1 #!/usr/bin/env python
2
3 #
4 # test_bgp_suppress_fib.py
5 #
6 # Copyright (c) 2019 by
7 #
8 # Permission to use, copy, modify, and/or distribute this software
9 # for any purpose with or without fee is hereby granted, provided
10 # that the above copyright notice and this permission notice appear
11 # in all copies.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
14 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
16 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
17 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 # OF THIS SOFTWARE.
21 #
22
23 """
24 """
25
26 import os
27 import sys
28 import json
29 import pytest
30 from functools import partial
31 from time import sleep
32
33 CWD = os.path.dirname(os.path.realpath(__file__))
34 sys.path.append(os.path.join(CWD, "../"))
35
36 # pylint: disable=C0413
37 from lib import topotest
38 from lib.topogen import Topogen, TopoRouter, get_topogen
39
40 pytestmark = [pytest.mark.bgpd]
41
42
43 def build_topo(tgen):
44 for routern in range(1, 4):
45 tgen.add_router("r{}".format(routern))
46
47 switch = tgen.add_switch("s1")
48 switch.add_link(tgen.gears["r1"])
49 switch.add_link(tgen.gears["r2"])
50
51 switch = tgen.add_switch("s2")
52 switch.add_link(tgen.gears["r2"])
53 switch.add_link(tgen.gears["r3"])
54
55
56 def setup_module(mod):
57 tgen = Topogen(build_topo, mod.__name__)
58 tgen.start_topology()
59
60 router_list = tgen.routers()
61
62 for i, (rname, router) in enumerate(router_list.items(), 1):
63 router.load_config(
64 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
65 )
66 router.load_config(
67 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
68 )
69
70 tgen.start_router()
71
72
73 def teardown_module(mod):
74 tgen = get_topogen()
75 tgen.stop_topology()
76
77
78 def test_bgp_route():
79 tgen = get_topogen()
80
81 if tgen.routers_have_failure():
82 pytest.skip(tgen.errors)
83
84 r3 = tgen.gears["r3"]
85
86 sleep(5)
87
88 json_file = "{}/r3/v4_route.json".format(CWD)
89 expected = json.loads(open(json_file).read())
90
91 test_func = partial(
92 topotest.router_json_cmp,
93 r3,
94 "show ip route 40.0.0.0 json",
95 expected,
96 )
97 _, result = topotest.run_and_expect(test_func, None, count=2, wait=0.5)
98 assertmsg = '"r3" JSON output mismatches'
99 assert result is None, assertmsg
100
101 json_file = "{}/r3/v4_route2.json".format(CWD)
102 expected = json.loads(open(json_file).read())
103
104 test_func = partial(
105 topotest.router_json_cmp,
106 r3,
107 "show ip route 50.0.0.0 json",
108 expected,
109 )
110 _, result = topotest.run_and_expect(test_func, None, count=3, wait=0.5)
111 assertmsg = '"r3" JSON output mismatches'
112 assert result is None, assertmsg
113
114
115 if __name__ == "__main__":
116 args = ["-s"] + sys.argv[1:]
117 sys.exit(pytest.main(args))