]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_unnumbered/test_bgp_unnumbered.py
2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2022 by
9 Test some bgp interface based issues that show up
18 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
19 sys
.path
.append(os
.path
.join(CWD
, "../"))
21 # pylint: disable=C0413
22 from lib
import topotest
23 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
24 from lib
.common_config
import step
26 pytestmark
= [pytest
.mark
.bgpd
]
34 switch
= tgen
.add_switch("s1")
35 switch
.add_link(tgen
.gears
["r1"])
36 switch
.add_link(tgen
.gears
["r2"])
39 def setup_module(mod
):
40 tgen
= Topogen(build_topo
, mod
.__name
__)
43 router_list
= tgen
.routers()
45 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
47 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
50 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
56 def teardown_module(mod
):
63 # a) create an unnumbered neighbor
64 # b) shutdown the interface
65 # c) remove the unnumbered peer in bgp and bgp does not crash
66 def test_bgp_unnumbered_removal():
69 if tgen
.routers_have_failure():
70 pytest
.skip(tgen
.errors
)
72 def _bgp_nexthop_cache():
73 output
= tgen
.gears
["r1"].vtysh_cmd("show bgp nexthop")
74 expected
= "Current BGP nexthop cache:\n"
75 return output
== expected
79 tgen
.gears
["r1"].vtysh_cmd("show ip bgp 172.16.255.254/32 json")
81 expected
= {"prefix": "172.16.255.254/32"}
83 return topotest
.json_cmp(output
, expected
)
85 step("Ensure Convergence of BGP")
86 test_func
= functools
.partial(_bgp_converge
)
87 success
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=1)
89 assert result
is None, 'Failed bgp convergence in "{}"'.format(tgen
.gears
["r2"])
91 step("Shutdown interface r1-eth0")
93 tgen
.gears
["r1"].vtysh_cmd(
101 step("Remove the neighbor from r1")
102 tgen
.gears
["r1"].vtysh_cmd(
106 no neighbor r1-eth0 interface remote-as external
110 step("Ensure that BGP does not crash")
111 test_func
= functools
.partial(_bgp_nexthop_cache
)
112 success
, result
= topotest
.run_and_expect(test_func
, True, count
=10, wait
=1)
114 assert result
is True, "BGP did not crash on r1"
117 if __name__
== "__main__":
118 args
= ["-s"] + sys
.argv
[1:]
119 sys
.exit(pytest
.main(args
))