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