]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py
2 # SPDX-License-Identifier: ISC
5 # bgp_local_as_private_remove.py
6 # Part of NetDEF Topology Tests
8 # Copyright (c) 2019 by
9 # Network Device Education Foundation, Inc. ("NetDEF")
13 bgp_local_as_private_remove.py:
14 Test if primary AS number is not removed in cases when `local-as`
15 used together with `remove-private-AS`.
24 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
25 sys
.path
.append(os
.path
.join(CWD
, "../"))
27 # pylint: disable=C0413
28 from lib
import topotest
29 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
31 pytestmark
= [pytest
.mark
.bgpd
]
35 for routern
in range(1, 5):
36 tgen
.add_router("r{}".format(routern
))
38 switch
= tgen
.add_switch("s1")
39 switch
.add_link(tgen
.gears
["r1"])
40 switch
.add_link(tgen
.gears
["r2"])
42 switch
= tgen
.add_switch("s2")
43 switch
.add_link(tgen
.gears
["r3"])
44 switch
.add_link(tgen
.gears
["r4"])
47 def setup_module(mod
):
48 tgen
= Topogen(build_topo
, mod
.__name
__)
51 router_list
= tgen
.routers()
53 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
55 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
58 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
64 def teardown_module(mod
):
69 def test_bgp_remove_private_as():
72 if tgen
.routers_have_failure():
73 pytest
.skip(tgen
.errors
)
79 output
= json
.loads(r2
.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
82 "bgpState": "Established",
85 return topotest
.json_cmp(output
, expected
)
87 test_func
= functools
.partial(_bgp_converge
)
88 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
89 assert result
is None, "Can't converge initially"
91 def _bgp_as_path(router
, asn_path
, asn_length
):
92 output
= json
.loads(router
.vtysh_cmd("show ip bgp 172.16.255.254/32 json"))
103 return topotest
.json_cmp(output
, expected
)
105 test_func
= functools
.partial(_bgp_as_path
, r2
, "500", 1)
106 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
107 assert result
is None, "Private ASNs not stripped"
109 test_func
= functools
.partial(_bgp_as_path
, r4
, "500 3000", 2)
110 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
111 assert result
is None, "Private ASNs not stripped"
114 if __name__
== "__main__":
115 args
= ["-s"] + sys
.argv
[1:]
116 sys
.exit(pytest
.main(args
))