]>
Commit | Line | Data |
---|---|---|
b7822d20 DS |
1 | #!/usr/bin/env python |
2 | ||
3 | # | |
8df8e156 | 4 | # test_bgp-vrf-route-leak-basic.py |
b7822d20 DS |
5 | # |
6 | # Copyright (c) 2018 Cumulus Networks, Inc. | |
7 | # Donald Sharp | |
8 | # | |
9 | # Permission to use, copy, modify, and/or distribute this software | |
10 | # for any purpose with or without fee is hereby granted, provided | |
11 | # that the above copyright notice and this permission notice appear | |
12 | # in all copies. | |
13 | # | |
14 | # THE SOFTWARE IS PROVIDED "AS IS" AND Cumulus Networks DISCLAIMS ALL WARRANTIES | |
15 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
16 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR | |
17 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY | |
18 | # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
19 | # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | |
20 | # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | |
21 | # OF THIS SOFTWARE. | |
22 | # | |
23 | ||
24 | """ | |
8df8e156 | 25 | test_bgp-vrf-route-leak-basic.py.py: Test basic vrf route leaking |
b7822d20 DS |
26 | """ |
27 | ||
b7822d20 DS |
28 | import os |
29 | import sys | |
8df8e156 | 30 | from functools import partial |
b7822d20 DS |
31 | import pytest |
32 | ||
33 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
787e7624 | 34 | sys.path.append(os.path.join(CWD, "../")) |
b7822d20 DS |
35 | |
36 | # pylint: disable=C0413 | |
37 | from lib import topotest | |
38 | from lib.topogen import Topogen, TopoRouter, get_topogen | |
39 | from lib.topolog import logger | |
40 | ||
b7822d20 | 41 | |
bf3a0a9a DS |
42 | pytestmark = [pytest.mark.bgpd] |
43 | ||
b7822d20 | 44 | |
e82b531d CH |
45 | def build_topo(tgen): |
46 | "Build function" | |
b7822d20 | 47 | |
e82b531d CH |
48 | for routern in range(1, 2): |
49 | tgen.add_router("r{}".format(routern)) | |
787e7624 | 50 | |
b7822d20 DS |
51 | |
52 | def setup_module(mod): | |
53 | "Sets up the pytest environment" | |
e82b531d | 54 | tgen = Topogen(build_topo, mod.__name__) |
b7822d20 DS |
55 | tgen.start_topology() |
56 | ||
57 | # For all registered routers, load the zebra configuration file | |
e5f0ed14 | 58 | for rname, router in tgen.routers().items(): |
b7822d20 DS |
59 | router.run("/bin/bash {}/setup_vrfs".format(CWD)) |
60 | router.load_config( | |
787e7624 | 61 | TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) |
b7822d20 DS |
62 | ) |
63 | router.load_config( | |
787e7624 | 64 | TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) |
b7822d20 DS |
65 | ) |
66 | ||
67 | # After loading the configurations, this function loads configured daemons. | |
68 | tgen.start_router() | |
787e7624 | 69 | # tgen.mininet_cli() |
70 | ||
b7822d20 DS |
71 | |
72 | def teardown_module(mod): | |
73 | "Teardown the pytest environment" | |
74 | tgen = get_topogen() | |
75 | ||
76 | # This function tears down the whole topology. | |
77 | tgen.stop_topology() | |
78 | ||
787e7624 | 79 | |
2bb8b49c | 80 | def test_vrf_route_leak(): |
b7822d20 DS |
81 | logger.info("Ensure that routes are leaked back and forth") |
82 | tgen = get_topogen() | |
83 | # Don't run this test if we have any failure. | |
84 | if tgen.routers_have_failure(): | |
85 | pytest.skip(tgen.errors) | |
86 | ||
787e7624 | 87 | r1 = tgen.gears["r1"] |
b7822d20 | 88 | |
2bb8b49c DS |
89 | # Test DONNA VRF. |
90 | expect = { | |
91 | "10.0.0.0/24": [ | |
92 | { | |
93 | "protocol": "connected", | |
94 | } | |
95 | ], | |
96 | "10.0.1.0/24": [ | |
97 | {"protocol": "bgp", "selected": True, "nexthops": [{"fib": True}]} | |
98 | ], | |
99 | "10.0.2.0/24": [{"protocol": "connected"}], | |
100 | "10.0.3.0/24": [ | |
101 | {"protocol": "bgp", "selected": True, "nexthops": [{"fib": True}]} | |
102 | ], | |
103 | } | |
8df8e156 | 104 | |
2bb8b49c DS |
105 | test_func = partial( |
106 | topotest.router_json_cmp, r1, "show ip route vrf DONNA json", expect | |
8df8e156 | 107 | ) |
2bb8b49c DS |
108 | result, diff = topotest.run_and_expect(test_func, None, count=10, wait=0.5) |
109 | assert result, "BGP VRF DONNA check failed:\n{}".format(diff) | |
110 | ||
111 | # Test EVA VRF. | |
112 | expect = { | |
113 | "10.0.0.0/24": [ | |
114 | {"protocol": "bgp", "selected": True, "nexthops": [{"fib": True}]} | |
115 | ], | |
116 | "10.0.1.0/24": [ | |
117 | { | |
118 | "protocol": "connected", | |
119 | } | |
120 | ], | |
121 | "10.0.2.0/24": [ | |
122 | {"protocol": "bgp", "selected": True, "nexthops": [{"fib": True}]} | |
123 | ], | |
124 | "10.0.3.0/24": [ | |
125 | { | |
126 | "protocol": "connected", | |
127 | } | |
128 | ], | |
129 | } | |
56748da5 | 130 | |
2bb8b49c DS |
131 | test_func = partial( |
132 | topotest.router_json_cmp, r1, "show ip route vrf EVA json", expect | |
133 | ) | |
134 | result, diff = topotest.run_and_expect(test_func, None, count=10, wait=0.5) | |
135 | assert result, "BGP VRF EVA check failed:\n{}".format(diff) | |
787e7624 | 136 | |
b7822d20 DS |
137 | |
138 | def test_memory_leak(): | |
139 | "Run the memory leak test and report results." | |
140 | tgen = get_topogen() | |
141 | if not tgen.is_memleak_enabled(): | |
787e7624 | 142 | pytest.skip("Memory leak test/report is disabled") |
b7822d20 DS |
143 | |
144 | tgen.report_memory_leaks() | |
145 | ||
146 | ||
787e7624 | 147 | if __name__ == "__main__": |
b7822d20 DS |
148 | args = ["-s"] + sys.argv[1:] |
149 | sys.exit(pytest.main(args)) |