]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py
*: manual SPDX License ID conversions
[mirror_frr.git] / tests / topotests / bgp_vrf_lite_ipv6_rtadv / test_bgp_vrf_lite_ipv6_rtadv.py
CommitLineData
37ce18dc
PG
1#!/usr/bin/env python
2
3#
4# test_bgp_ipv6_rtadv.py
5# Part of NetDEF Topology Tests
6#
7# Copyright (c) 2019 by 6WIND
8#
9# Permission to use, copy, modify, and/or distribute this software
10# for any purpose with or without fee is hereby granted, provided
11# that the above copyright notice and this permission notice appear
12# in all copies.
13#
14# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
15# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
17# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
18# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21# OF THIS SOFTWARE.
22#
23
24"""
622c4996 25 test_bgp_ipv6_rtadv.py: Test the FRR BGP daemon with BGP IPv6 interface
37ce18dc
PG
26 with route advertisements on a separate netns.
27"""
28
29import os
30import sys
31import json
32from functools import partial
33import pytest
34
35# Save the Current Working Directory to find configuration files.
36CWD = os.path.dirname(os.path.realpath(__file__))
787e7624 37sys.path.append(os.path.join(CWD, "../"))
37ce18dc
PG
38
39# pylint: disable=C0413
40# Import topogen and topotest helpers
41from lib import topotest
42from lib.topogen import Topogen, TopoRouter, get_topogen
43from lib.topolog import logger
36eef858 44from lib.common_config import required_linux_kernel_version
37ce18dc
PG
45
46# Required to instantiate the topology builder class.
37ce18dc 47
bf3a0a9a
DS
48pytestmark = [pytest.mark.bgpd]
49
37ce18dc 50
e82b531d
CH
51def build_topo(tgen):
52 "Build function"
787e7624 53
e82b531d
CH
54 # Create 2 routers.
55 tgen.add_router("r1")
56 tgen.add_router("r2")
37ce18dc 57
e82b531d
CH
58 switch = tgen.add_switch("s1")
59 switch.add_link(tgen.gears["r1"])
60 switch.add_link(tgen.gears["r2"])
37ce18dc 61
37ce18dc
PG
62
63def setup_module(mod):
64 "Sets up the pytest environment"
36eef858
IR
65
66 # Required linux kernel version for this suite to run.
67 result = required_linux_kernel_version("5.0")
68 if result is not True:
69 pytest.skip("Kernel requirements are not met")
70
e82b531d 71 tgen = Topogen(build_topo, mod.__name__)
37ce18dc
PG
72 tgen.start_topology()
73
74 router_list = tgen.routers()
75
787e7624 76 logger.info("Testing with VRF Lite support")
37ce18dc 77
787e7624 78 cmds = [
79 "ip link add {0}-cust1 type vrf table 1001",
80 "ip link add loop1 type dummy",
81 "ip link set loop1 master {0}-cust1",
82 "ip link set {0}-eth0 master {0}-cust1",
83 ]
37ce18dc 84
e5f0ed14 85 for rname, router in router_list.items():
37ce18dc
PG
86 for cmd in cmds:
87 output = tgen.net[rname].cmd(cmd.format(rname))
88
e5f0ed14 89 for rname, router in router_list.items():
37ce18dc 90 router.load_config(
787e7624 91 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
37ce18dc
PG
92 )
93 router.load_config(
787e7624 94 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
37ce18dc
PG
95 )
96
97 # Initialize all routers.
98 tgen.start_router()
99
787e7624 100
37ce18dc
PG
101def teardown_module(_mod):
102 "Teardown the pytest environment"
103 tgen = get_topogen()
104
105 tgen.stop_topology()
106
107
108def test_protocols_convergence():
109 """
110 Assert that all protocols have converged
111 statuses as they depend on it.
112 """
113 tgen = get_topogen()
114 if tgen.routers_have_failure():
115 pytest.skip(tgen.errors)
116
117 # Check IPv4 routing tables.
118 logger.info("Checking IPv4 routes for convergence")
119
120 for router in tgen.routers().values():
787e7624 121 json_file = "{}/{}/ipv4_routes.json".format(CWD, router.name)
37ce18dc 122 if not os.path.isfile(json_file):
787e7624 123 logger.info("skipping file {}".format(json_file))
37ce18dc
PG
124 continue
125
126 expected = json.loads(open(json_file).read())
787e7624 127 test_func = partial(
128 topotest.router_json_cmp,
129 router,
130 "show ip route vrf {}-cust1 json".format(router.name),
131 expected,
132 )
133 _, result = topotest.run_and_expect(test_func, None, count=160, wait=0.5)
37ce18dc
PG
134 assertmsg = '"{}" JSON output mismatches'.format(router.name)
135 assert result is None, assertmsg
136
137 # Check IPv6 routing tables.
138 logger.info("Checking IPv6 routes for convergence")
139 for router in tgen.routers().values():
787e7624 140 json_file = "{}/{}/ipv6_routes.json".format(CWD, router.name)
37ce18dc 141 if not os.path.isfile(json_file):
787e7624 142 logger.info("skipping file {}".format(json_file))
37ce18dc
PG
143 continue
144
145 expected = json.loads(open(json_file).read())
787e7624 146 test_func = partial(
147 topotest.router_json_cmp,
148 router,
149 "show ipv6 route vrf {}-cust1 json".format(router.name),
150 expected,
151 )
152 _, result = topotest.run_and_expect(test_func, None, count=160, wait=0.5)
37ce18dc
PG
153 assertmsg = '"{}" JSON output mismatches'.format(router.name)
154 assert result is None, assertmsg
155
787e7624 156
37ce18dc
PG
157def test_memory_leak():
158 "Run the memory leak test and report results."
159 tgen = get_topogen()
160 if not tgen.is_memleak_enabled():
787e7624 161 pytest.skip("Memory leak test/report is disabled")
37ce18dc
PG
162
163 tgen.report_memory_leaks()
164
165
787e7624 166if __name__ == "__main__":
37ce18dc
PG
167 args = ["-s"] + sys.argv[1:]
168 sys.exit(pytest.main(args))