]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_comm_list_delete / test_bgp_comm-list_delete.py
1 #!/usr/bin/env python
2
3 #
4 # bgp_comm-list_delete.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2019 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
9 #
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
13 # in all copies.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 # OF THIS SOFTWARE.
23 #
24
25 """
26 bgp_comm-list_delete.py:
27
28 Test if works the following commands:
29 route-map test permit 10
30 set comm-list <arg> delete
31 """
32
33 import os
34 import sys
35 import json
36 import pytest
37 import functools
38
39 CWD = os.path.dirname(os.path.realpath(__file__))
40 sys.path.append(os.path.join(CWD, "../"))
41
42 # pylint: disable=C0413
43 from lib import topotest
44 from lib.topogen import Topogen, TopoRouter, get_topogen
45
46 pytestmark = [pytest.mark.bgpd]
47
48
49 def build_topo(tgen):
50 for routern in range(1, 3):
51 tgen.add_router("r{}".format(routern))
52
53 switch = tgen.add_switch("s1")
54 switch.add_link(tgen.gears["r1"])
55 switch.add_link(tgen.gears["r2"])
56
57
58 def setup_module(mod):
59 tgen = Topogen(build_topo, mod.__name__)
60 tgen.start_topology()
61
62 router_list = tgen.routers()
63
64 for i, (rname, router) in enumerate(router_list.items(), 1):
65 router.load_config(
66 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
67 )
68 router.load_config(
69 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
70 )
71
72 tgen.start_router()
73
74
75 def teardown_module(mod):
76 tgen = get_topogen()
77 tgen.stop_topology()
78
79
80 def test_bgp_maximum_prefix_invalid():
81 tgen = get_topogen()
82
83 if tgen.routers_have_failure():
84 pytest.skip(tgen.errors)
85
86 r2 = tgen.gears["r2"]
87
88 def _bgp_converge():
89 output = json.loads(r2.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
90 expected = {
91 "192.168.255.1": {
92 "bgpState": "Established",
93 "addressFamilyInfo": {
94 "ipv4Unicast": {
95 "acceptedPrefixCounter": 2,
96 }
97 },
98 }
99 }
100 return topotest.json_cmp(output, expected)
101
102 test_func = functools.partial(_bgp_converge)
103 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
104 assert result is None, "Can't converge initially"
105
106 def _bgp_comm_list_delete():
107 output = json.loads(r2.vtysh_cmd("show ip bgp 172.16.255.254/32 json"))
108 expected = {"paths": [{"community": {"list": ["333:333"]}}]}
109 return topotest.json_cmp(output, expected)
110
111 test_func = functools.partial(_bgp_comm_list_delete)
112 _, result = topotest.run_and_expect(test_func, not None, count=60, wait=0.5)
113 assert result is not None, "333:333 community SHOULD be stripped from r1"
114
115
116 if __name__ == "__main__":
117 args = ["-s"] + sys.argv[1:]
118 sys.exit(pytest.main(args))