]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/route_scale/scale_test_common.py
2 # SPDX-License-Identifier: ISC
7 # Copyright (c) 2020 by
8 # Cumulus Networks, Inc.
13 scale_test_common.py: Common routines for testing route scale
22 from functools
import partial
24 # Save the Current Working Directory to find configuration files.
25 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
26 sys
.path
.append(os
.path
.join(CWD
, "../"))
28 # pylint: disable=C0413
29 # Import topogen and topotest helpers
30 from lib
import topotest
31 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
32 from lib
.topolog
import logger
35 #####################################################
37 ## Network Topology Definition
39 #####################################################
42 def scale_build_common(tgen
):
46 for routern
in range(1, 2):
47 tgen
.add_router("r{}".format(routern
))
50 for switchn
in range(1, 33):
51 switch
= tgen
.add_switch("sw{}".format(switchn
))
52 switch
.add_link(tgen
.gears
["r1"])
55 def scale_setup_module(module
):
57 tgen
= Topogen(scale_build_common
, module
.__name
__)
60 router_list
= tgen
.routers()
61 for rname
, router
in router_list
.items():
63 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
66 TopoRouter
.RD_SHARP
, os
.path
.join(CWD
, "{}/sharpd.conf".format(rname
))
73 def scale_teardown_module(_mod
):
74 "Teardown the pytest environment"
77 # This function tears down the whole topology.
81 def scale_converge_protocols():
82 "Wait for protocol convergence"
85 # Don't run this test if we have any failure.
86 if tgen
.routers_have_failure():
87 pytest
.skip(tgen
.errors
)
90 def run_one_setup(r1
, s
):
94 expected_installed
= s
["expect_in"]
95 expected_removed
= s
["expect_rem"]
97 retries
= s
["retries"]
100 for d
in expected_installed
["routes"]:
101 if d
["type"] == "sharp":
105 logger
.info("Testing {} routes X {} ecmp".format(count
, s
["ecmp"]))
108 "sharp install route 1.0.0.0 \
109 nexthop-group {} {}".format(
116 topotest
.router_json_cmp
, r1
, "show ip route summary json", expected_installed
118 success
, result
= topotest
.run_and_expect(test_func
, None, retries
, wait
)
119 assert success
, "Route scale test install failed:\n{}".format(result
)
121 output
= r1
.vtysh_cmd("sharp data route", isjson
=False)
122 logger
.info("{} routes X {} ecmp installed".format(count
, s
["ecmp"]))
124 r1
.vtysh_cmd("sharp remove route 1.0.0.0 {}".format(count
), isjson
=False)
126 topotest
.router_json_cmp
, r1
, "show ip route summary json", expected_removed
128 success
, result
= topotest
.run_and_expect(test_func
, None, retries
, wait
)
129 assert success
, "Route scale test remove failed:\n{}".format(result
)
131 output
= r1
.vtysh_cmd("sharp data route", isjson
=False)
132 logger
.info("{} routes x {} ecmp removed".format(count
, s
["ecmp"]))
136 def route_install_helper(iter):
137 "Test route install for a variety of ecmp"
140 # Don't run this test if we have any failure.
141 if tgen
.routers_have_failure():
142 pytest
.skip(tgen
.errors
)
144 r1
= tgen
.gears
["r1"]
146 # Avoid top ecmp case for runs with < 4G memory
147 output
= tgen
.net
.cmd_raises("free")
148 m
= re
.search(r
"Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)", output
)
149 total_mem
= int(m
.group(2))
150 if total_mem
< 4000000 and iter == 5:
152 "Limited memory available: {}, skipping x32 testcase".format(total_mem
)
156 installed_file
= "{}/r1/installed.routes.json".format(CWD
)
157 expected_installed
= json
.loads(open(installed_file
).read())
159 removed_file
= "{}/r1/no.routes.json".format(CWD
)
160 expected_removed
= json
.loads(open(removed_file
).read())
162 # dict keys of params: ecmp number, corresponding nhg name, timeout,
163 # number of times to wait
164 scale_keys
= ["ecmp", "nhg", "wait", "retries", "expect_in", "expect_rem"]
166 # Table of defaults, used for timeout values and 'expected' objects
167 scale_defaults
= dict(
168 zip(scale_keys
, [None, None, 10, 50, expected_installed
, expected_removed
])
171 # List of params for each step in the test; note extra time given
172 # for the highest ecmp steps. Executing 'show' at scale can be costly
173 # so we widen the interval there too.
179 [16, "sixteen", 10, 40],
180 [32, "thirtytwo", 10, 40],
183 # Build up a list of dicts with params for each step of the test;
184 # use defaults where the step doesn't supply a value
186 s
= scale_steps
[iter]
188 d
= dict(zip(scale_keys
, s
))
191 d
[k
] = scale_defaults
[k
]
197 def scale_test_memory_leak():
198 "Run the memory leak test and report results."
200 if not tgen
.is_memleak_enabled():
201 pytest
.skip("Memory leak test/report is disabled")
202 tgen
.report_memory_leaks()