Merge pull request #18658 from y-bharath14/srib-tests-v12

tests: Resource leak in common_config.py
This commit is contained in:
Donatas Abraitis 2025-04-17 18:18:26 +03:00 committed by GitHub
commit 0850ae7db7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -330,13 +330,12 @@ def create_common_configurations(
for router in routers: for router in routers:
fname = "{}/{}/{}".format(tgen.logdir, router, FRRCFG_FILE) fname = "{}/{}/{}".format(tgen.logdir, router, FRRCFG_FILE)
try: try:
frr_cfg_fd = open(fname, mode) with open(fname, mode) as frr_cfg_fd:
if config_type: if config_type:
frr_cfg_fd.write(config_map[config_type]) frr_cfg_fd.write(config_map[config_type])
for line in config_dict[router]: for line in config_dict[router]:
frr_cfg_fd.write("{} \n".format(str(line))) frr_cfg_fd.write("{} \n".format(str(line)))
frr_cfg_fd.write("\n") frr_cfg_fd.write("\n")
except IOError as err: except IOError as err:
logger.error("Unable to open FRR Config '%s': %s" % (fname, str(err))) logger.error("Unable to open FRR Config '%s': %s" % (fname, str(err)))
return False return False
@ -487,10 +486,11 @@ def save_initial_config_on_routers(tgen):
procs = {} procs = {}
for rname in router_list: for rname in router_list:
logger.debug("Fetching running config for router %s", rname) logger.debug("Fetching running config for router %s", rname)
with open(target_cfg_fmt.format(rname), "w") as target_cfg_fd:
procs[rname] = router_list[rname].popen( procs[rname] = router_list[rname].popen(
["/usr/bin/env", "vtysh", "-c", "show running-config no-header"], ["/usr/bin/env", "vtysh", "-c", "show running-config no-header"],
stdin=None, stdin=None,
stdout=open(target_cfg_fmt.format(rname), "w"), stdout=target_cfg_fd,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
) )
for rname, p in procs.items(): for rname, p in procs.items():
@ -543,10 +543,11 @@ def reset_config_on_routers(tgen, routerName=None):
procs = {} procs = {}
for rname in router_list: for rname in router_list:
logger.debug("Fetching running config for router %s", rname) logger.debug("Fetching running config for router %s", rname)
with open(run_cfg_fmt.format(rname, gen), "w") as run_cfg_fd:
procs[rname] = router_list[rname].popen( procs[rname] = router_list[rname].popen(
["/usr/bin/env", "vtysh", "-c", "show running-config no-header"], ["/usr/bin/env", "vtysh", "-c", "show running-config no-header"],
stdin=None, stdin=None,
stdout=open(run_cfg_fmt.format(rname, gen), "w"), stdout=run_cfg_fd,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
) )
for rname, p in procs.items(): for rname, p in procs.items():
@ -567,6 +568,7 @@ def reset_config_on_routers(tgen, routerName=None):
logger.debug( logger.debug(
"Generating delta for router %s to new configuration (gen %d)", rname, gen "Generating delta for router %s to new configuration (gen %d)", rname, gen
) )
with open(delta_fmt.format(rname, gen), "w") as delta_fd:
procs[rname] = tgen.net.popen( procs[rname] = tgen.net.popen(
[ [
"/usr/lib/frr/frr-reload.py", "/usr/lib/frr/frr-reload.py",
@ -577,7 +579,7 @@ def reset_config_on_routers(tgen, routerName=None):
target_cfg_fmt.format(rname), target_cfg_fmt.format(rname),
], ],
stdin=None, stdin=None,
stdout=open(delta_fmt.format(rname, gen), "w"), stdout=delta_fd,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
) )
for rname, p in procs.items(): for rname, p in procs.items():