]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bfd_profiles_topo1/test_bfd_profiles_topo1.py
4 # test_bfd_profiles_topo1.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2020 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
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_bfd_profiles_topo1.py: Test the FRR BFD profile protocol integration.
32 from functools
import partial
35 # Save the Current Working Directory to find configuration files.
36 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
37 sys
.path
.append(os
.path
.join(CWD
, "../"))
39 # pylint: disable=C0413
40 # Import topogen and topotest helpers
41 from lib
import topotest
42 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
43 from lib
.topolog
import logger
45 pytestmark
= [pytest
.mark
.bfdd
, pytest
.mark
.bgpd
, pytest
.mark
.isisd
, pytest
.mark
.ospfd
]
48 def setup_module(mod
):
49 "Sets up the pytest environment"
58 tgen
= Topogen(topodef
, mod
.__name
__)
61 router_list
= tgen
.routers()
62 for rname
, router
in router_list
.items():
63 daemon_file
= "{}/{}/bfdd.conf".format(CWD
, rname
)
64 if os
.path
.isfile(daemon_file
):
65 router
.load_config(TopoRouter
.RD_BFD
, daemon_file
)
67 daemon_file
= "{}/{}/bgpd.conf".format(CWD
, rname
)
68 if os
.path
.isfile(daemon_file
):
69 router
.load_config(TopoRouter
.RD_BGP
, daemon_file
)
71 daemon_file
= "{}/{}/isisd.conf".format(CWD
, rname
)
72 if os
.path
.isfile(daemon_file
):
73 router
.load_config(TopoRouter
.RD_ISIS
, daemon_file
)
75 daemon_file
= "{}/{}/ospfd.conf".format(CWD
, rname
)
76 if os
.path
.isfile(daemon_file
):
77 router
.load_config(TopoRouter
.RD_OSPF
, daemon_file
)
79 daemon_file
= "{}/{}/ospf6d.conf".format(CWD
, rname
)
80 if os
.path
.isfile(daemon_file
):
81 router
.load_config(TopoRouter
.RD_OSPF6
, daemon_file
)
83 daemon_file
= "{}/{}/zebra.conf".format(CWD
, rname
)
84 if os
.path
.isfile(daemon_file
):
85 router
.load_config(TopoRouter
.RD_ZEBRA
, daemon_file
)
87 # Initialize all routers.
91 def teardown_module(_mod
):
92 "Teardown the pytest environment"
97 def test_wait_protocols_convergence():
98 "Wait for all protocols to converge"
100 if tgen
.routers_have_failure():
101 pytest
.skip(tgen
.errors
)
103 logger
.info("waiting for protocols to converge")
105 def expect_loopback_route(router
, iptype
, route
, proto
):
106 "Wait until route is present on RIB for protocol."
107 logger
.info("waiting route {} in {}".format(route
, router
))
109 topotest
.router_json_cmp
,
111 "show {} route json".format(iptype
),
112 {route
: [{"protocol": proto
}]},
114 _
, result
= topotest
.run_and_expect(test_func
, None, count
=130, wait
=1)
115 assertmsg
= '"{}" OSPF convergence failure'.format(router
)
116 assert result
is None, assertmsg
118 # Wait for R1 <-> R6 convergence.
119 expect_loopback_route("r1", "ip", "10.254.254.6/32", "ospf")
121 # Wait for R6 <-> R1 convergence.
122 expect_loopback_route("r6", "ip", "10.254.254.1/32", "ospf")
124 # Wait for R2 <-> R3 convergence.
125 expect_loopback_route("r2", "ip", "10.254.254.3/32", "bgp")
127 # Wait for R3 <-> R2 convergence.
128 expect_loopback_route("r3", "ip", "10.254.254.2/32", "bgp")
130 # Wait for R3 <-> R4 convergence.
131 expect_loopback_route("r3", "ipv6", "2001:db8:3::/64", "isis")
133 # Wait for R4 <-> R3 convergence.
134 expect_loopback_route("r4", "ipv6", "2001:db8:1::/64", "isis")
136 # Wait for R4 <-> R5 convergence.
137 expect_loopback_route("r4", "ipv6", "2001:db8:3::/64", "ospf6")
139 # Wait for R5 <-> R4 convergence.
140 expect_loopback_route("r5", "ipv6", "2001:db8:2::/64", "ospf6")
143 def test_bfd_profile_values():
144 "Assert that the BFD peers can find themselves."
146 if tgen
.routers_have_failure():
147 pytest
.skip(tgen
.errors
)
149 logger
.info("waiting for bfd peers to go up and checking profile values")
151 for router
in tgen
.routers().values():
152 json_file
= "{}/{}/bfd-peers-initial.json".format(CWD
, router
.name
)
153 expected
= json
.loads(open(json_file
).read())
155 topotest
.router_json_cmp
, router
, "show bfd peers json", expected
157 _
, result
= topotest
.run_and_expect(test_func
, None, count
=12, wait
=0.5)
158 assertmsg
= '"{}" JSON output mismatches'.format(router
.name
)
159 assert result
is None, assertmsg
162 def test_memory_leak():
163 "Run the memory leak test and report results."
165 if not tgen
.is_memleak_enabled():
166 pytest
.skip("Memory leak test/report is disabled")
168 tgen
.report_memory_leaks()
171 if __name__
== "__main__":
172 args
= ["-s"] + sys
.argv
[1:]
173 sys
.exit(pytest
.main(args
))