]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/babel_topo1/test_babel_topo1.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / babel_topo1 / test_babel_topo1.py
CommitLineData
d844d516
DS
1#!/usr/bin/env python
2
3#
4# test_babel_topo1.py
5#
6# Copyright (c) 2017 by
7# Cumulus Networks, Inc.
8# Donald Sharp
9#
10# Permission to use, copy, modify, and/or distribute this software
11# for any purpose with or without fee is hereby granted, provided
12# that the above copyright notice and this permission notice appear
13# in all copies.
14#
15# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22# OF THIS SOFTWARE.
23#
24
25"""
26test_babel_topo1.py: Testing BABEL
27
28"""
29
30import os
31import re
32import sys
33import pytest
34import json
35
36pytestmark = [pytest.mark.babeld]
37
38# Save the Current Working Directory to find configuration files.
39CWD = os.path.dirname(os.path.realpath(__file__))
40sys.path.append(os.path.join(CWD, "../"))
41
42# pylint: disable=C0413
43# Import topogen and topotest helpers
44from lib import topotest
45from lib.topogen import Topogen, TopoRouter, get_topogen
46from lib.topolog import logger
47
48# Required to instantiate the topology builder class.
49
50#####################################################
51##
52## Network Topology Definition
53##
54#####################################################
55
56
57def build_topo(tgen):
58 for routern in range(1, 4):
59 tgen.add_router("r{}".format(routern))
60
61 # On main router
62 # First switch is for a dummy interface (for local network)
63 switch = tgen.add_switch("sw1")
64 switch.add_link(tgen.gears["r1"])
65
66 # Switches for BABEL
67 # switch 2 switch is for connection to BABEL router
68 switch = tgen.add_switch("sw2")
69 switch.add_link(tgen.gears["r1"])
70 switch.add_link(tgen.gears["r2"])
71
72 # switch 4 is stub on remote BABEL router
73 switch = tgen.add_switch("sw4")
74 switch.add_link(tgen.gears["r3"])
75
76 # switch 3 is between BABEL routers
77 switch = tgen.add_switch("sw3")
78 switch.add_link(tgen.gears["r2"])
79 switch.add_link(tgen.gears["r3"])
80
81
82#####################################################
83##
84## Tests starting
85##
86#####################################################
87
88
89def setup_module(module):
90 "Setup topology"
91 tgen = Topogen(build_topo, module.__name__)
92 tgen.start_topology()
93
94 # This is a sample of configuration loading.
95 router_list = tgen.routers()
96 for rname, router in router_list.items():
97 router.load_config(
98 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
99 )
100 router.load_config(
101 TopoRouter.RD_BABEL, os.path.join(CWD, "{}/babeld.conf".format(rname))
102 )
103
104 tgen.start_router()
105
106
107def teardown_module(_mod):
108 "Teardown the pytest environment"
109 tgen = get_topogen()
110
111 # This function tears down the whole topology.
112 tgen.stop_topology()
113
114
115def test_converge_protocols():
116 "Wait for protocol convergence"
117
118 tgen = get_topogen()
119 # Don't run this test if we have any failure.
120 if tgen.routers_have_failure():
121 pytest.skip(tgen.errors)
122
123 topotest.sleep(10, "Waiting for BABEL convergence")
124
125
126def test_zebra_ipv4_routingTable():
127 "Test 'show ip route'"
128
129 tgen = get_topogen()
130 # Don't run this test if we have any failure.
131 if tgen.routers_have_failure():
132 pytest.skip(tgen.errors)
133
134 failures = 0
135 router_list = tgen.routers().values()
136 for router in router_list:
137 output = router.vtysh_cmd("show ip route json", isjson=True)
138 refTableFile = "{}/{}/show_ip_route.json_ref".format(CWD, router.name)
139 expected = json.loads(open(refTableFile).read())
140
141 assertmsg = "Zebra IPv4 Routing Table verification failed for router {}".format(
142 router.name
143 )
144 assert topotest.json_cmp(output, expected) is None, assertmsg
145
146def test_shutdown_check_stderr():
147 if os.environ.get("TOPOTESTS_CHECK_STDERR") is None:
148 pytest.skip("Skipping test for Stderr output and memory leaks")
149
150 tgen = get_topogen()
151 # Don't run this test if we have any failure.
152 if tgen.routers_have_failure():
153 pytest.skip(tgen.errors)
154
155 logger.info("Verifying unexpected STDERR output from daemons")
156
157 router_list = tgen.routers().values()
158 for router in router_list:
159 router.stop()
160
161 log = tgen.net[router.name].getStdErr("babeld")
162 if log:
163 logger.error("BABELd StdErr Log:" + log)
164 log = tgen.net[router.name].getStdErr("zebra")
165 if log:
166 logger.error("Zebra StdErr Log:" + log)
167
168
169if __name__ == "__main__":
170 args = ["-s"] + sys.argv[1:]
171 sys.exit(pytest.main(args))