]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / tests / topotests / bgp_local_as_private_remove / test_bgp_local_as_private_remove.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 #
5 # bgp_local_as_private_remove.py
6 # Part of NetDEF Topology Tests
7 #
8 # Copyright (c) 2019 by
9 # Network Device Education Foundation, Inc. ("NetDEF")
10 #
11
12 """
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`.
16 """
17
18 import os
19 import sys
20 import json
21 import pytest
22 import functools
23
24 CWD = os.path.dirname(os.path.realpath(__file__))
25 sys.path.append(os.path.join(CWD, "../"))
26
27 # pylint: disable=C0413
28 from lib import topotest
29 from lib.topogen import Topogen, TopoRouter, get_topogen
30
31 pytestmark = [pytest.mark.bgpd]
32
33
34 def build_topo(tgen):
35 for routern in range(1, 5):
36 tgen.add_router("r{}".format(routern))
37
38 switch = tgen.add_switch("s1")
39 switch.add_link(tgen.gears["r1"])
40 switch.add_link(tgen.gears["r2"])
41
42 switch = tgen.add_switch("s2")
43 switch.add_link(tgen.gears["r3"])
44 switch.add_link(tgen.gears["r4"])
45
46
47 def setup_module(mod):
48 tgen = Topogen(build_topo, mod.__name__)
49 tgen.start_topology()
50
51 router_list = tgen.routers()
52
53 for i, (rname, router) in enumerate(router_list.items(), 1):
54 router.load_config(
55 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
56 )
57 router.load_config(
58 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
59 )
60
61 tgen.start_router()
62
63
64 def teardown_module(mod):
65 tgen = get_topogen()
66 tgen.stop_topology()
67
68
69 def test_bgp_remove_private_as():
70 tgen = get_topogen()
71
72 if tgen.routers_have_failure():
73 pytest.skip(tgen.errors)
74
75 r2 = tgen.gears["r2"]
76 r4 = tgen.gears["r4"]
77
78 def _bgp_converge():
79 output = json.loads(r2.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
80 expected = {
81 "192.168.255.1": {
82 "bgpState": "Established",
83 }
84 }
85 return topotest.json_cmp(output, expected)
86
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"
90
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"))
93 expected = {
94 "paths": [
95 {
96 "aspath": {
97 "string": asn_path,
98 "length": asn_length,
99 }
100 }
101 ]
102 }
103 return topotest.json_cmp(output, expected)
104
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"
108
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"
112
113
114 if __name__ == "__main__":
115 args = ["-s"] + sys.argv[1:]
116 sys.exit(pytest.main(args))