]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py
tests: fix pylint test errors
[mirror_frr.git] / tests / topotests / bgp_default_route_route_map_match_set / test_bgp_default-originate_route-map_match_set.py
CommitLineData
462b3067
DA
1#!/usr/bin/env python
2
55b15c38 3# Copyright (c) 2020 by
462b3067
DA
4# Donatas Abraitis <donatas.abraitis@gmail.com>
5#
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
9# in all copies.
10#
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
18# OF THIS SOFTWARE.
19#
20
21"""
55b15c38
DA
22Test if default-originate works with match operations.
23And verify if set operations work as well.
462b3067
DA
24"""
25
26import os
27import sys
28import json
29import time
30import pytest
31import functools
32
33CWD = os.path.dirname(os.path.realpath(__file__))
787e7624 34sys.path.append(os.path.join(CWD, "../"))
462b3067
DA
35
36# pylint: disable=C0413
37from lib import topotest
38from lib.topogen import Topogen, TopoRouter, get_topogen
39from lib.topolog import logger
8db751b8 40from lib.micronet_compat import Topo
462b3067 41
787e7624 42
bf3a0a9a
DS
43pytestmark = [pytest.mark.bgpd]
44
45
462b3067
DA
46class TemplateTopo(Topo):
47 def build(self, *_args, **_opts):
48 tgen = get_topogen(self)
49
50 for routern in range(1, 3):
787e7624 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"])
462b3067 56
462b3067
DA
57
58def setup_module(mod):
59 tgen = Topogen(TemplateTopo, mod.__name__)
60 tgen.start_topology()
61
62 router_list = tgen.routers()
63
e5f0ed14 64 for i, (rname, router) in enumerate(router_list.items(), 1):
462b3067 65 router.load_config(
787e7624 66 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
462b3067
DA
67 )
68 router.load_config(
787e7624 69 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
462b3067
DA
70 )
71
72 tgen.start_router()
73
787e7624 74
462b3067
DA
75def teardown_module(mod):
76 tgen = get_topogen()
77 tgen.stop_topology()
78
787e7624 79
462b3067
DA
80def test_bgp_default_originate_route_map():
81 tgen = get_topogen()
82
83 if tgen.routers_have_failure():
84 pytest.skip(tgen.errors)
85
787e7624 86 router = tgen.gears["r2"]
462b3067
DA
87
88 def _bgp_converge(router):
89 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
90 expected = {
787e7624 91 "192.168.255.1": {
92 "bgpState": "Established",
93 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 1}},
462b3067
DA
94 }
95 }
96 return topotest.json_cmp(output, expected)
97
98 def _bgp_default_route_has_metric(router):
99 output = json.loads(router.vtysh_cmd("show ip bgp 0.0.0.0/0 json"))
cc54c072
DA
100 expected = {
101 "paths": [{"aspath": {"string": "65000 65000 65000 65000"}, "metric": 123}]
102 }
462b3067
DA
103 return topotest.json_cmp(output, expected)
104
105 test_func = functools.partial(_bgp_converge, router)
55b15c38 106 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
462b3067
DA
107
108 assert result is None, 'Failed to see bgp convergence in "{}"'.format(router)
109
110 test_func = functools.partial(_bgp_default_route_has_metric, router)
55b15c38 111 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
462b3067 112
787e7624 113 assert (
114 result is None
115 ), 'Failed to see applied metric for default route in "{}"'.format(router)
116
462b3067 117
787e7624 118if __name__ == "__main__":
462b3067
DA
119 args = ["-s"] + sys.argv[1:]
120 sys.exit(pytest.main(args))