]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bfd_profiles_topo1/test_bfd_profiles_topo1.py
2 # SPDX-License-Identifier: ISC
5 # test_bfd_profiles_topo1.py
6 # Part of NetDEF Topology Tests
8 # Copyright (c) 2020 by
9 # Network Device Education Foundation, Inc. ("NetDEF")
13 test_bfd_profiles_topo1.py: Test the FRR BFD profile protocol integration.
19 from functools
import partial
22 # Save the Current Working Directory to find configuration files.
23 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
24 sys
.path
.append(os
.path
.join(CWD
, "../"))
26 # pylint: disable=C0413
27 # Import topogen and topotest helpers
28 from lib
import topotest
29 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
30 from lib
.topolog
import logger
32 pytestmark
= [pytest
.mark
.bfdd
, pytest
.mark
.bgpd
, pytest
.mark
.isisd
, pytest
.mark
.ospfd
]
35 def setup_module(mod
):
36 "Sets up the pytest environment"
45 tgen
= Topogen(topodef
, mod
.__name
__)
48 router_list
= tgen
.routers()
49 for rname
, router
in router_list
.items():
50 daemon_file
= "{}/{}/bfdd.conf".format(CWD
, rname
)
51 if os
.path
.isfile(daemon_file
):
52 router
.load_config(TopoRouter
.RD_BFD
, daemon_file
)
54 daemon_file
= "{}/{}/bgpd.conf".format(CWD
, rname
)
55 if os
.path
.isfile(daemon_file
):
56 router
.load_config(TopoRouter
.RD_BGP
, daemon_file
)
58 daemon_file
= "{}/{}/isisd.conf".format(CWD
, rname
)
59 if os
.path
.isfile(daemon_file
):
60 router
.load_config(TopoRouter
.RD_ISIS
, daemon_file
)
62 daemon_file
= "{}/{}/ospfd.conf".format(CWD
, rname
)
63 if os
.path
.isfile(daemon_file
):
64 router
.load_config(TopoRouter
.RD_OSPF
, daemon_file
)
66 daemon_file
= "{}/{}/ospf6d.conf".format(CWD
, rname
)
67 if os
.path
.isfile(daemon_file
):
68 router
.load_config(TopoRouter
.RD_OSPF6
, daemon_file
)
70 daemon_file
= "{}/{}/zebra.conf".format(CWD
, rname
)
71 if os
.path
.isfile(daemon_file
):
72 router
.load_config(TopoRouter
.RD_ZEBRA
, daemon_file
)
74 # Initialize all routers.
78 def teardown_module(_mod
):
79 "Teardown the pytest environment"
84 def test_wait_protocols_convergence():
85 "Wait for all protocols to converge"
87 if tgen
.routers_have_failure():
88 pytest
.skip(tgen
.errors
)
90 logger
.info("waiting for protocols to converge")
92 def expect_loopback_route(router
, iptype
, route
, proto
):
93 "Wait until route is present on RIB for protocol."
94 logger
.info("waiting route {} in {}".format(route
, router
))
96 topotest
.router_json_cmp
,
98 "show {} route json".format(iptype
),
99 {route
: [{"protocol": proto
}]},
101 _
, result
= topotest
.run_and_expect(test_func
, None, count
=130, wait
=1)
102 assertmsg
= '"{}" OSPF convergence failure'.format(router
)
103 assert result
is None, assertmsg
105 # Wait for R1 <-> R6 convergence.
106 expect_loopback_route("r1", "ip", "10.254.254.6/32", "ospf")
108 # Wait for R6 <-> R1 convergence.
109 expect_loopback_route("r6", "ip", "10.254.254.1/32", "ospf")
111 # Wait for R2 <-> R3 convergence.
112 expect_loopback_route("r2", "ip", "10.254.254.3/32", "bgp")
114 # Wait for R3 <-> R2 convergence.
115 expect_loopback_route("r3", "ip", "10.254.254.2/32", "bgp")
117 # Wait for R3 <-> R4 convergence.
118 expect_loopback_route("r3", "ipv6", "2001:db8:3::/64", "isis")
120 # Wait for R4 <-> R3 convergence.
121 expect_loopback_route("r4", "ipv6", "2001:db8:1::/64", "isis")
123 # Wait for R4 <-> R5 convergence.
124 expect_loopback_route("r4", "ipv6", "2001:db8:3::/64", "ospf6")
126 # Wait for R5 <-> R4 convergence.
127 expect_loopback_route("r5", "ipv6", "2001:db8:2::/64", "ospf6")
130 def test_bfd_profile_values():
131 "Assert that the BFD peers can find themselves."
133 if tgen
.routers_have_failure():
134 pytest
.skip(tgen
.errors
)
136 logger
.info("waiting for bfd peers to go up and checking profile values")
138 for router
in tgen
.routers().values():
139 json_file
= "{}/{}/bfd-peers-initial.json".format(CWD
, router
.name
)
140 expected
= json
.loads(open(json_file
).read())
142 topotest
.router_json_cmp
, router
, "show bfd peers json", expected
144 _
, result
= topotest
.run_and_expect(test_func
, None, count
=12, wait
=0.5)
145 assertmsg
= '"{}" JSON output mismatches'.format(router
.name
)
146 assert result
is None, assertmsg
149 def test_memory_leak():
150 "Run the memory leak test and report results."
152 if not tgen
.is_memleak_enabled():
153 pytest
.skip("Memory leak test/report is disabled")
155 tgen
.report_memory_leaks()
158 if __name__
== "__main__":
159 args
= ["-s"] + sys
.argv
[1:]
160 sys
.exit(pytest
.main(args
))