]>
Commit | Line | Data |
---|---|---|
689bb566 | 1 | #!/usr/bin/env python |
acddc0ed | 2 | # SPDX-License-Identifier: ISC |
689bb566 PG |
3 | |
4 | # | |
5 | # test_bgp_ipv6_rtadv.py | |
6 | # Part of NetDEF Topology Tests | |
7 | # | |
8 | # Copyright (c) 2019 by 6WIND | |
9 | # | |
689bb566 PG |
10 | |
11 | """ | |
622c4996 | 12 | test_bgp_ipv6_rtadv.py: Test the FRR BGP daemon with BGP IPv6 interface |
689bb566 PG |
13 | with route advertisements on a separate netns. |
14 | """ | |
15 | ||
16 | import os | |
17 | import sys | |
18 | import json | |
19 | from functools import partial | |
20 | import pytest | |
21 | ||
22 | # Save the Current Working Directory to find configuration files. | |
23 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
787e7624 | 24 | sys.path.append(os.path.join(CWD, "../")) |
689bb566 PG |
25 | |
26 | # pylint: disable=C0413 | |
27 | # Import topogen and topotest helpers | |
28 | from lib import topotest | |
29 | from lib.topogen import Topogen, TopoRouter, get_topogen | |
30 | from lib.topolog import logger | |
31 | ||
32 | # Required to instantiate the topology builder class. | |
689bb566 PG |
33 | |
34 | ||
98ca91e1 DS |
35 | pytestmark = [pytest.mark.bgpd] |
36 | ||
37 | ||
e82b531d CH |
38 | def build_topo(tgen): |
39 | "Build function" | |
787e7624 | 40 | |
e82b531d CH |
41 | # Create 2 routers. |
42 | tgen.add_router("r1") | |
43 | tgen.add_router("r2") | |
689bb566 | 44 | |
e82b531d CH |
45 | switch = tgen.add_switch("s1") |
46 | switch.add_link(tgen.gears["r1"]) | |
47 | switch.add_link(tgen.gears["r2"]) | |
689bb566 | 48 | |
689bb566 PG |
49 | |
50 | def setup_module(mod): | |
51 | "Sets up the pytest environment" | |
e82b531d | 52 | tgen = Topogen(build_topo, mod.__name__) |
689bb566 PG |
53 | tgen.start_topology() |
54 | ||
55 | router_list = tgen.routers() | |
56 | ||
e5f0ed14 | 57 | for rname, router in router_list.items(): |
689bb566 | 58 | router.load_config( |
787e7624 | 59 | TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) |
689bb566 PG |
60 | ) |
61 | router.load_config( | |
787e7624 | 62 | TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) |
689bb566 PG |
63 | ) |
64 | ||
65 | # Initialize all routers. | |
66 | tgen.start_router() | |
67 | ||
787e7624 | 68 | |
689bb566 PG |
69 | def teardown_module(_mod): |
70 | "Teardown the pytest environment" | |
71 | tgen = get_topogen() | |
72 | ||
73 | tgen.stop_topology() | |
74 | ||
75 | ||
76 | def test_protocols_convergence(): | |
77 | """ | |
78 | Assert that all protocols have converged | |
79 | statuses as they depend on it. | |
80 | """ | |
81 | tgen = get_topogen() | |
82 | if tgen.routers_have_failure(): | |
83 | pytest.skip(tgen.errors) | |
84 | ||
85 | # Check IPv4 routing tables. | |
86 | logger.info("Checking IPv4 routes for convergence") | |
87 | for router in tgen.routers().values(): | |
787e7624 | 88 | json_file = "{}/{}/ipv4_routes.json".format(CWD, router.name) |
689bb566 | 89 | if not os.path.isfile(json_file): |
787e7624 | 90 | logger.info("skipping file {}".format(json_file)) |
689bb566 PG |
91 | continue |
92 | ||
93 | expected = json.loads(open(json_file).read()) | |
787e7624 | 94 | test_func = partial( |
95 | topotest.router_json_cmp, | |
96 | router, | |
f4baa8fe | 97 | "show ip route json", |
787e7624 | 98 | expected, |
99 | ) | |
100 | _, result = topotest.run_and_expect(test_func, None, count=160, wait=0.5) | |
689bb566 PG |
101 | assertmsg = '"{}" JSON output mismatches'.format(router.name) |
102 | assert result is None, assertmsg | |
103 | ||
104 | # Check IPv6 routing tables. | |
105 | logger.info("Checking IPv6 routes for convergence") | |
106 | for router in tgen.routers().values(): | |
787e7624 | 107 | json_file = "{}/{}/ipv6_routes.json".format(CWD, router.name) |
689bb566 | 108 | if not os.path.isfile(json_file): |
787e7624 | 109 | logger.info("skipping file {}".format(json_file)) |
689bb566 PG |
110 | continue |
111 | ||
112 | expected = json.loads(open(json_file).read()) | |
787e7624 | 113 | test_func = partial( |
114 | topotest.router_json_cmp, | |
115 | router, | |
f4baa8fe | 116 | "show ipv6 route json", |
787e7624 | 117 | expected, |
118 | ) | |
119 | _, result = topotest.run_and_expect(test_func, None, count=160, wait=0.5) | |
689bb566 PG |
120 | assertmsg = '"{}" JSON output mismatches'.format(router.name) |
121 | assert result is None, assertmsg | |
122 | ||
787e7624 | 123 | |
689bb566 PG |
124 | def test_memory_leak(): |
125 | "Run the memory leak test and report results." | |
126 | tgen = get_topogen() | |
127 | if not tgen.is_memleak_enabled(): | |
787e7624 | 128 | pytest.skip("Memory leak test/report is disabled") |
689bb566 PG |
129 | |
130 | tgen.report_memory_leaks() | |
131 | ||
132 | ||
787e7624 | 133 | if __name__ == "__main__": |
689bb566 PG |
134 | args = ["-s"] + sys.argv[1:] |
135 | sys.exit(pytest.main(args)) |