3 # Copyright (c) 2021 by
4 # Donatas Abraitis <donatas.abraitis@gmail.com>
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 Test if BGP community alias is visible in CLI outputs
31 pytestmark
= pytest
.mark
.bgpd
33 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
34 sys
.path
.append(os
.path
.join(CWD
, "../"))
36 # pylint: disable=C0413
37 from lib
import topotest
38 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
40 pytestmark
= [pytest
.mark
.bgpd
]
44 for routern
in range(1, 3):
45 tgen
.add_router("r{}".format(routern
))
47 switch
= tgen
.add_switch("s1")
48 switch
.add_link(tgen
.gears
["r1"])
49 switch
.add_link(tgen
.gears
["r2"])
52 def setup_module(mod
):
53 tgen
= Topogen(build_topo
, mod
.__name
__)
56 router_list
= tgen
.routers()
58 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
60 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
63 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
69 def teardown_module(mod
):
74 def test_bgp_community_alias():
77 if tgen
.routers_have_failure():
78 pytest
.skip(tgen
.errors
)
80 router
= tgen
.gears
["r1"]
82 def _bgp_converge(router
):
83 output
= json
.loads(router
.vtysh_cmd("show ip route json"))
88 "communities": "community-r2-1 65001:2",
89 "largeCommunities": "large-community-r2-1 65001:1:2",
95 "communities": "65002:1 community-r2-2",
96 "largeCommunities": "",
103 "largeCommunities": "",
107 return topotest
.json_cmp(output
, expected
)
109 test_func
= functools
.partial(_bgp_converge
, router
)
110 success
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
111 assert result
is None, "Cannot see BGP community aliases at r1"
113 def _bgp_show_prefixes_by_alias(router
):
116 "show bgp ipv4 unicast alias large-community-r2-1 json detail"
124 "community": {"string": "community-r2-1 65001:2"},
126 "string": "large-community-r2-1 65001:1:2"
133 return topotest
.json_cmp(output
, expected
)
135 test_func
= functools
.partial(_bgp_show_prefixes_by_alias
, router
)
136 success
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
137 assert result
is None, "Cannot see BGP prefixes by community alias at r1"
139 def _bgp_show_prefixes_by_large_community_list(router
):
141 router
.vtysh_cmd("show bgp ipv4 unicast large-community-list r2 json")
143 expected
= {"routes": {"172.16.16.1/32": [{"valid": True}]}}
144 return topotest
.json_cmp(output
, expected
)
146 test_func
= functools
.partial(_bgp_show_prefixes_by_large_community_list
, router
)
147 success
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
148 assert result
is None, "Cannot see BGP prefixes by large community list at r1"
151 if __name__
== "__main__":
152 args
= ["-s"] + sys
.argv
[1:]
153 sys
.exit(pytest
.main(args
))