2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2022 by
5 # Donatas Abraitis <donatas@opensourcerouting.org>
9 Check if routes from R1 has local-preference set to 0 and graceful-shutdown
19 pytestmark
= pytest
.mark
.bgpd
21 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
22 sys
.path
.append(os
.path
.join(CWD
, "../"))
24 # pylint: disable=C0413
25 from lib
import topotest
26 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
27 from lib
.common_config
import step
29 pytestmark
= [pytest
.mark
.bgpd
]
32 def setup_module(mod
):
33 topodef
= {"s1": ("r1", "r2"), "s2": ("r2", "r3")}
34 tgen
= Topogen(topodef
, mod
.__name
__)
37 router_list
= tgen
.routers()
39 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
41 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
44 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
50 def teardown_module(mod
):
58 if tgen
.routers_have_failure():
59 pytest
.skip(tgen
.errors
)
67 "show bgp ipv4 unicast neighbor 192.168.2.2 advertised-routes json"
70 expected
= {"advertisedRoutes": {"10.10.10.1/32": {"locPrf": 100}}}
71 return topotest
.json_cmp(output
, expected
)
73 test_func
= functools
.partial(_bgp_converge
)
74 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
75 assert result
is None, "Can't converge at R2"
77 step("Mark routes from R1 as graceful-shutdown")
82 neighbor 192.168.1.1 graceful-shutdown
86 def _bgp_check_peer_graceful_shutdown():
87 output
= json
.loads(r3
.vtysh_cmd("show bgp ipv4 unicast 10.10.10.1/32 json"))
92 "community": {"string": "graceful-shutdown"},
96 return topotest
.json_cmp(output
, expected
)
98 test_func
= functools
.partial(_bgp_check_peer_graceful_shutdown
)
99 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
102 ), "local-preference is not 0 and/or graceful-shutdown community missing"
105 if __name__
== "__main__":
106 args
= ["-s"] + sys
.argv
[1:]
107 sys
.exit(pytest
.main(args
))