]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/eigrp_topo1/test_eigrp_topo1.py
6 # Copyright (c) 2017 by
7 # Cumulus Networks, Inc.
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
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
26 test_eigrp_topo1.py: Testing EIGRP
36 pytestmark
= [pytest
.mark
.eigrpd
]
38 # Save the Current Working Directory to find configuration files.
39 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
40 sys
.path
.append(os
.path
.join(CWD
, "../"))
42 # pylint: disable=C0413
43 # Import topogen and topotest helpers
44 from lib
import topotest
45 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
46 from lib
.topolog
import logger
48 # Required to instantiate the topology builder class.
50 #####################################################
52 ## Network Topology Definition
54 #####################################################
58 for routern
in range(1, 4):
59 tgen
.add_router("r{}".format(routern
))
62 # First switch is for a dummy interface (for local network)
63 switch
= tgen
.add_switch("sw1")
64 switch
.add_link(tgen
.gears
["r1"])
67 # switch 2 switch is for connection to EIGRP router
68 switch
= tgen
.add_switch("sw2")
69 switch
.add_link(tgen
.gears
["r1"])
70 switch
.add_link(tgen
.gears
["r2"])
72 # switch 4 is stub on remote EIGRP router
73 switch
= tgen
.add_switch("sw4")
74 switch
.add_link(tgen
.gears
["r3"])
76 # switch 3 is between EIGRP routers
77 switch
= tgen
.add_switch("sw3")
78 switch
.add_link(tgen
.gears
["r2"])
79 switch
.add_link(tgen
.gears
["r3"])
82 #####################################################
86 #####################################################
89 def setup_module(module
):
91 tgen
= Topogen(build_topo
, module
.__name
__)
94 # This is a sample of configuration loading.
95 router_list
= tgen
.routers()
96 for rname
, router
in router_list
.items():
98 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
101 TopoRouter
.RD_EIGRP
, os
.path
.join(CWD
, "{}/eigrpd.conf".format(rname
))
107 def teardown_module(_mod
):
108 "Teardown the pytest environment"
111 # This function tears down the whole topology.
115 def test_converge_protocols():
116 "Wait for protocol convergence"
119 # Don't run this test if we have any failure.
120 if tgen
.routers_have_failure():
121 pytest
.skip(tgen
.errors
)
123 topotest
.sleep(5, "Waiting for EIGRP convergence")
126 def test_eigrp_routes():
127 "Test EIGRP 'show ip eigrp'"
130 # Don't run this test if we have any failure.
131 if tgen
.routers_have_failure():
132 pytest
.skip(tgen
.errors
)
134 # Verify EIGRP Status
135 logger
.info("Verifying EIGRP routes")
137 router_list
= tgen
.routers().values()
138 for router
in router_list
:
139 refTableFile
= "{}/{}/show_ip_eigrp.json".format(CWD
, router
.name
)
141 # Read expected result from file
142 expected
= json
.loads(open(refTableFile
).read())
144 # Actual output from router
145 actual
= ip_eigrp_topo(router
)
147 assertmsg
= '"show ip eigrp topo" mismatches on {}'.format(router
.name
)
148 assert topotest
.json_cmp(actual
, expected
) is None, assertmsg
151 def test_zebra_ipv4_routingTable():
152 "Test 'show ip route'"
155 # Don't run this test if we have any failure.
156 if tgen
.routers_have_failure():
157 pytest
.skip(tgen
.errors
)
160 router_list
= tgen
.routers().values()
161 for router
in router_list
:
162 output
= router
.vtysh_cmd("show ip route json", isjson
=True)
163 refTableFile
= "{}/{}/show_ip_route.json_ref".format(CWD
, router
.name
)
164 expected
= json
.loads(open(refTableFile
).read())
166 assertmsg
= "Zebra IPv4 Routing Table verification failed for router {}".format(
169 assert topotest
.json_cmp(output
, expected
) is None, assertmsg
172 def test_shut_interface_and_recover():
173 "Test shutdown of an interface and recovery of the interface"
176 router
= tgen
.gears
["r1"]
177 router
.run("ip link set r1-eth1 down")
178 topotest
.sleep(5, "Waiting for EIGRP convergence")
179 router
.run("ip link set r1-eth1 up")
182 def test_shutdown_check_stderr():
183 if os
.environ
.get("TOPOTESTS_CHECK_STDERR") is None:
184 pytest
.skip("Skipping test for Stderr output and memory leaks")
187 # Don't run this test if we have any failure.
188 if tgen
.routers_have_failure():
189 pytest
.skip(tgen
.errors
)
191 logger
.info("Verifying unexpected STDERR output from daemons")
193 router_list
= tgen
.routers().values()
194 for router
in router_list
:
197 log
= tgen
.net
[router
.name
].getStdErr("eigrpd")
199 logger
.error("EIGRPd StdErr Log:" + log
)
200 log
= tgen
.net
[router
.name
].getStdErr("zebra")
202 logger
.error("Zebra StdErr Log:" + log
)
205 if __name__
== "__main__":
206 args
= ["-s"] + sys
.argv
[1:]
207 sys
.exit(pytest
.main(args
))
210 # Auxiliary Functions
212 def ip_eigrp_topo(node
):
214 Parse 'show ip eigrp topo' from `node` and returns a dict with the
237 output
= topotest
.normalize_text(node
.vtysh_cmd("show ip eigrp topo")).splitlines()
239 for idx
, line
in enumerate(output
):
240 columns
= line
.split(" ", 1)
242 # Parse the following format into python dicts
243 # code A.B.C.D/E, X successors, FD is Y, serno: Z
244 # via FOO, interface-name
246 if code
not in ["P", "A", "U", "Q", "R", "r", "s"]:
249 if code
not in result
:
252 # Split network from the rest
253 columns
= columns
[1].split(",")
255 # Parse first line data
257 result
[code
][network
] = {}
258 for column
in columns
:
259 # Skip the network column
260 if column
== columns
[0]:
263 match
= re
.search(r
"(\d+) successors", column
)
264 if match
is not None:
265 result
[code
][network
]["successors"] = match
.group(1)
268 match
= re
.search(r
"FD is (\d+)", column
)
269 if match
is not None:
270 result
[code
][network
]["fd"] = match
.group(1)
273 match
= re
.search(r
"serno: (\d+)", column
)
274 if match
is not None:
275 result
[code
][network
]["serno"] = match
.group(1)
278 # Parse second line data
279 nextline
= output
[idx
+ 1]
280 columns
= topotest
.normalize_text(nextline
).split(",")
281 for column
in columns
:
282 match
= re
.search(r
"via (.+)", column
)
283 if match
is not None:
284 result
[code
][network
]["via"] = match
.group(1)
287 match
= re
.search(r
"(.+)", column
)
288 if match
is not None:
289 result
[code
][network
]["interface"] = match
.group(1)