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