]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/eigrp_topo1/test_eigrp_topo1.py
2 # SPDX-License-Identifier: ISC
7 # Copyright (c) 2017 by
8 # Cumulus Networks, Inc.
13 test_eigrp_topo1.py: Testing EIGRP
23 pytestmark
= [pytest
.mark
.eigrpd
]
25 # Save the Current Working Directory to find configuration files.
26 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
27 sys
.path
.append(os
.path
.join(CWD
, "../"))
29 # pylint: disable=C0413
30 # Import topogen and topotest helpers
31 from lib
import topotest
32 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
33 from lib
.topolog
import logger
35 # Required to instantiate the topology builder class.
37 #####################################################
39 ## Network Topology Definition
41 #####################################################
45 for routern
in range(1, 4):
46 tgen
.add_router("r{}".format(routern
))
49 # First switch is for a dummy interface (for local network)
50 switch
= tgen
.add_switch("sw1")
51 switch
.add_link(tgen
.gears
["r1"])
54 # switch 2 switch is for connection to EIGRP router
55 switch
= tgen
.add_switch("sw2")
56 switch
.add_link(tgen
.gears
["r1"])
57 switch
.add_link(tgen
.gears
["r2"])
59 # switch 4 is stub on remote EIGRP router
60 switch
= tgen
.add_switch("sw4")
61 switch
.add_link(tgen
.gears
["r3"])
63 # switch 3 is between EIGRP routers
64 switch
= tgen
.add_switch("sw3")
65 switch
.add_link(tgen
.gears
["r2"])
66 switch
.add_link(tgen
.gears
["r3"])
69 #####################################################
73 #####################################################
76 def setup_module(module
):
78 tgen
= Topogen(build_topo
, module
.__name
__)
81 # This is a sample of configuration loading.
82 router_list
= tgen
.routers()
83 for rname
, router
in router_list
.items():
85 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
88 TopoRouter
.RD_EIGRP
, os
.path
.join(CWD
, "{}/eigrpd.conf".format(rname
))
94 def teardown_module(_mod
):
95 "Teardown the pytest environment"
98 # This function tears down the whole topology.
102 def test_converge_protocols():
103 "Wait for protocol convergence"
106 # Don't run this test if we have any failure.
107 if tgen
.routers_have_failure():
108 pytest
.skip(tgen
.errors
)
110 topotest
.sleep(5, "Waiting for EIGRP convergence")
113 def test_eigrp_routes():
114 "Test EIGRP 'show ip eigrp'"
117 # Don't run this test if we have any failure.
118 if tgen
.routers_have_failure():
119 pytest
.skip(tgen
.errors
)
121 # Verify EIGRP Status
122 logger
.info("Verifying EIGRP routes")
124 router_list
= tgen
.routers().values()
125 for router
in router_list
:
126 refTableFile
= "{}/{}/show_ip_eigrp.json".format(CWD
, router
.name
)
128 # Read expected result from file
129 expected
= json
.loads(open(refTableFile
).read())
131 # Actual output from router
132 actual
= ip_eigrp_topo(router
)
134 assertmsg
= '"show ip eigrp topo" mismatches on {}'.format(router
.name
)
135 assert topotest
.json_cmp(actual
, expected
) is None, assertmsg
138 def test_zebra_ipv4_routingTable():
139 "Test 'show ip route'"
142 # Don't run this test if we have any failure.
143 if tgen
.routers_have_failure():
144 pytest
.skip(tgen
.errors
)
147 router_list
= tgen
.routers().values()
148 for router
in router_list
:
149 output
= router
.vtysh_cmd("show ip route json", isjson
=True)
150 refTableFile
= "{}/{}/show_ip_route.json_ref".format(CWD
, router
.name
)
151 expected
= json
.loads(open(refTableFile
).read())
153 assertmsg
= "Zebra IPv4 Routing Table verification failed for router {}".format(
156 assert topotest
.json_cmp(output
, expected
) is None, assertmsg
159 def test_shut_interface_and_recover():
160 "Test shutdown of an interface and recovery of the interface"
163 router
= tgen
.gears
["r1"]
164 router
.run("ip link set r1-eth1 down")
165 topotest
.sleep(5, "Waiting for EIGRP convergence")
166 router
.run("ip link set r1-eth1 up")
169 def test_shutdown_check_stderr():
170 if os
.environ
.get("TOPOTESTS_CHECK_STDERR") is None:
171 pytest
.skip("Skipping test for Stderr output and memory leaks")
174 # Don't run this test if we have any failure.
175 if tgen
.routers_have_failure():
176 pytest
.skip(tgen
.errors
)
178 logger
.info("Verifying unexpected STDERR output from daemons")
180 router_list
= tgen
.routers().values()
181 for router
in router_list
:
184 log
= tgen
.net
[router
.name
].getStdErr("eigrpd")
186 logger
.error("EIGRPd StdErr Log:" + log
)
187 log
= tgen
.net
[router
.name
].getStdErr("zebra")
189 logger
.error("Zebra StdErr Log:" + log
)
192 if __name__
== "__main__":
193 args
= ["-s"] + sys
.argv
[1:]
194 sys
.exit(pytest
.main(args
))
197 # Auxiliary Functions
199 def ip_eigrp_topo(node
):
201 Parse 'show ip eigrp topo' from `node` and returns a dict with the
224 output
= topotest
.normalize_text(node
.vtysh_cmd("show ip eigrp topo")).splitlines()
226 for idx
, line
in enumerate(output
):
227 columns
= line
.split(" ", 1)
229 # Parse the following format into python dicts
230 # code A.B.C.D/E, X successors, FD is Y, serno: Z
231 # via FOO, interface-name
233 if code
not in ["P", "A", "U", "Q", "R", "r", "s"]:
236 if code
not in result
:
239 # Split network from the rest
240 columns
= columns
[1].split(",")
242 # Parse first line data
244 result
[code
][network
] = {}
245 for column
in columns
:
246 # Skip the network column
247 if column
== columns
[0]:
250 match
= re
.search(r
"(\d+) successors", column
)
251 if match
is not None:
252 result
[code
][network
]["successors"] = match
.group(1)
255 match
= re
.search(r
"FD is (\d+)", column
)
256 if match
is not None:
257 result
[code
][network
]["fd"] = match
.group(1)
260 match
= re
.search(r
"serno: (\d+)", column
)
261 if match
is not None:
262 result
[code
][network
]["serno"] = match
.group(1)
265 # Parse second line data
266 nextline
= output
[idx
+ 1]
267 columns
= topotest
.normalize_text(nextline
).split(",")
268 for column
in columns
:
269 match
= re
.search(r
"via (.+)", column
)
270 if match
is not None:
271 result
[code
][network
]["via"] = match
.group(1)
274 match
= re
.search(r
"(.+)", column
)
275 if match
is not None:
276 result
[code
][network
]["interface"] = match
.group(1)