]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py
*: manual SPDX License ID conversions
[mirror_frr.git] / tests / topotests / bgp_comm_list_delete / test_bgp_comm-list_delete.py
CommitLineData
5bb05cce
DA
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"""
26bgp_comm-list_delete.py:
27
28Test if works the following commands:
29route-map test permit 10
30 set comm-list <arg> delete
31"""
32
33import os
34import sys
35import json
5bb05cce 36import pytest
52ffb4e6 37import functools
5bb05cce
DA
38
39CWD = os.path.dirname(os.path.realpath(__file__))
787e7624 40sys.path.append(os.path.join(CWD, "../"))
5bb05cce
DA
41
42# pylint: disable=C0413
52ffb4e6 43from lib import topotest
5bb05cce 44from lib.topogen import Topogen, TopoRouter, get_topogen
5bb05cce 45
5ad1fd54
DS
46pytestmark = [pytest.mark.bgpd]
47
787e7624 48
e82b531d
CH
49def build_topo(tgen):
50 for routern in range(1, 3):
51 tgen.add_router("r{}".format(routern))
5bb05cce 52
e82b531d
CH
53 switch = tgen.add_switch("s1")
54 switch.add_link(tgen.gears["r1"])
55 switch.add_link(tgen.gears["r2"])
5bb05cce 56
5bb05cce
DA
57
58def setup_module(mod):
e82b531d 59 tgen = Topogen(build_topo, mod.__name__)
5bb05cce
DA
60 tgen.start_topology()
61
62 router_list = tgen.routers()
63
e5f0ed14 64 for i, (rname, router) in enumerate(router_list.items(), 1):
5bb05cce 65 router.load_config(
787e7624 66 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
5bb05cce
DA
67 )
68 router.load_config(
787e7624 69 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
5bb05cce
DA
70 )
71
72 tgen.start_router()
73
787e7624 74
5bb05cce
DA
75def teardown_module(mod):
76 tgen = get_topogen()
77 tgen.stop_topology()
78
787e7624 79
5bb05cce
DA
80def test_bgp_maximum_prefix_invalid():
81 tgen = get_topogen()
82
83 if tgen.routers_have_failure():
84 pytest.skip(tgen.errors)
85
52ffb4e6
DA
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"
787e7624 114
5bb05cce 115
787e7624 116if __name__ == "__main__":
5bb05cce
DA
117 args = ["-s"] + sys.argv[1:]
118 sys.exit(pytest.main(args))