3 # Copyright (c) 2022 by
4 # Donatas Abraitis <donatas@opensourcerouting.org>
6 # Permission to use, copy, modify, and/or distribute this software
7 # for any purpose with or without fee is hereby granted, provided
8 # that the above copyright notice and this permission notice appear
11 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
15 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
16 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
17 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 Check if routes from R1 has local-preference set to 0 and graceful-shutdown
32 pytestmark
= pytest
.mark
.bgpd
34 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
35 sys
.path
.append(os
.path
.join(CWD
, "../"))
37 # pylint: disable=C0413
38 from lib
import topotest
39 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
40 from lib
.common_config
import step
42 pytestmark
= [pytest
.mark
.bgpd
]
45 def setup_module(mod
):
46 topodef
= {"s1": ("r1", "r2"), "s2": ("r2", "r3")}
47 tgen
= Topogen(topodef
, mod
.__name
__)
50 router_list
= tgen
.routers()
52 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
54 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
57 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
63 def teardown_module(mod
):
71 if tgen
.routers_have_failure():
72 pytest
.skip(tgen
.errors
)
80 "show bgp ipv4 unicast neighbor 192.168.2.2 advertised-routes json"
83 expected
= {"advertisedRoutes": {"10.10.10.1/32": {"locPrf": 100}}}
84 return topotest
.json_cmp(output
, expected
)
86 test_func
= functools
.partial(_bgp_converge
)
87 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
88 assert result
is None, "Can't converge at R2"
90 step("Mark routes from R1 as graceful-shutdown")
95 neighbor 192.168.1.1 graceful-shutdown
99 def _bgp_check_peer_graceful_shutdown():
100 output
= json
.loads(r3
.vtysh_cmd("show bgp ipv4 unicast 10.10.10.1/32 json"))
105 "community": {"string": "graceful-shutdown"},
109 return topotest
.json_cmp(output
, expected
)
111 test_func
= functools
.partial(_bgp_check_peer_graceful_shutdown
)
112 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
115 ), "local-preference is not 0 and/or graceful-shutdown community missing"
118 if __name__
== "__main__":
119 args
= ["-s"] + sys
.argv
[1:]
120 sys
.exit(pytest
.main(args
))