]>
Commit | Line | Data |
---|---|---|
1cc55938 S |
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 time | |
30 | import pytest | |
31 | from functools import partial | |
32 | from time import sleep | |
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 | from lib.topolog import logger | |
8db751b8 | 41 | from lib.micronet_compat import Topo |
1cc55938 | 42 | |
bf3a0a9a DS |
43 | pytestmark = [pytest.mark.bgpd] |
44 | ||
1cc55938 S |
45 | |
46 | class TemplateTopo(Topo): | |
47 | def build(self, *_args, **_opts): | |
48 | tgen = get_topogen(self) | |
49 | ||
50 | for routern in range(1, 4): | |
51 | tgen.add_router("r{}".format(routern)) | |
52 | ||
53 | switch = tgen.add_switch("s1") | |
54 | switch.add_link(tgen.gears["r1"]) | |
55 | switch.add_link(tgen.gears["r2"]) | |
56 | ||
57 | switch = tgen.add_switch("s2") | |
58 | switch.add_link(tgen.gears["r2"]) | |
59 | switch.add_link(tgen.gears["r3"]) | |
60 | ||
9fa6ec14 | 61 | |
1cc55938 S |
62 | def setup_module(mod): |
63 | tgen = Topogen(TemplateTopo, mod.__name__) | |
64 | tgen.start_topology() | |
65 | ||
66 | router_list = tgen.routers() | |
67 | ||
68 | for i, (rname, router) in enumerate(router_list.items(), 1): | |
69 | router.load_config( | |
70 | TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) | |
71 | ) | |
72 | router.load_config( | |
73 | TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) | |
74 | ) | |
75 | ||
76 | tgen.start_router() | |
77 | ||
78 | ||
79 | def teardown_module(mod): | |
80 | tgen = get_topogen() | |
81 | tgen.stop_topology() | |
82 | ||
83 | ||
84 | def test_bgp_route(): | |
85 | tgen = get_topogen() | |
86 | ||
87 | if tgen.routers_have_failure(): | |
88 | pytest.skip(tgen.errors) | |
89 | ||
90 | r3 = tgen.gears["r3"] | |
91 | ||
92 | sleep(5) | |
93 | ||
94 | json_file = "{}/r3/v4_route.json".format(CWD) | |
95 | expected = json.loads(open(json_file).read()) | |
96 | ||
97 | test_func = partial( | |
98 | topotest.router_json_cmp, | |
99 | r3, | |
100 | "show ip route 40.0.0.0 json", | |
101 | expected, | |
102 | ) | |
103 | _, result = topotest.run_and_expect(test_func, None, count=2, wait=0.5) | |
104 | assertmsg = '"r3" JSON output mismatches' | |
105 | assert result is None, assertmsg | |
106 | ||
107 | json_file = "{}/r3/v4_route2.json".format(CWD) | |
108 | expected = json.loads(open(json_file).read()) | |
109 | ||
110 | test_func = partial( | |
111 | topotest.router_json_cmp, | |
112 | r3, | |
113 | "show ip route 50.0.0.0 json", | |
114 | expected, | |
115 | ) | |
116 | _, result = topotest.run_and_expect(test_func, None, count=3, wait=0.5) | |
117 | assertmsg = '"r3" JSON output mismatches' | |
118 | assert result is None, assertmsg | |
119 | ||
9fa6ec14 | 120 | |
1cc55938 S |
121 | if __name__ == "__main__": |
122 | args = ["-s"] + sys.argv[1:] | |
123 | sys.exit(pytest.main(args)) |