Skip to content

Commit

Permalink
Merge pull request #13594 from LabNConsulting/chopps/uniconfig
Browse files Browse the repository at this point in the history
tests: cleanup unified config and config arg
  • Loading branch information
ton31337 authored May 26, 2023
2 parents b570e9c + 27c6bfc commit 91ac217
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
14 changes: 7 additions & 7 deletions tests/topotests/lib/topogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,23 +798,23 @@ def load_frr_config(self, source, daemons=None):
Start the daemons in the list
If daemons is None, try to infer daemons from the config file
"""
self.load_config(self.RD_FRR, source)
source_path = self.load_config(self.RD_FRR, source)
if not daemons:
# Always add zebra
self.load_config(self.RD_ZEBRA)
self.load_config(self.RD_ZEBRA, "")
for daemon in self.RD:
# This will not work for all daemons
daemonstr = self.RD.get(daemon).rstrip("d")
if daemonstr == "pim":
grep_cmd = "grep 'ip {}' {}".format(daemonstr, source)
grep_cmd = "grep 'ip {}' {}".format(daemonstr, source_path)
else:
grep_cmd = "grep 'router {}' {}".format(daemonstr, source)
grep_cmd = "grep 'router {}' {}".format(daemonstr, source_path)
result = self.run(grep_cmd, warn=False).strip()
if result:
self.load_config(daemon)
self.load_config(daemon, "")
else:
for daemon in daemons:
self.load_config(daemon)
self.load_config(daemon, "")

def load_config(self, daemon, source=None, param=None):
"""Loads daemon configuration from the specified source
Expand All @@ -833,7 +833,7 @@ def load_config(self, daemon, source=None, param=None):
"""
daemonstr = self.RD.get(daemon)
self.logger.debug('loading "{}" configuration: {}'.format(daemonstr, source))
self.net.loadConf(daemonstr, source, param)
return self.net.loadConf(daemonstr, source, param)

def check_router_running(self):
"""
Expand Down
39 changes: 32 additions & 7 deletions tests/topotests/lib/topotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,9 +1527,11 @@ def loadConf(self, daemon, source=None, param=None):
"""

# Unfortunately this API allowsfor source to not exist for any and all routers.
if source is None:
source_was_none = source is None
if source_was_none:
source = f"{daemon}.conf"

# "" to avoid loading a default config which is present in router dir
if source:
head, tail = os.path.split(source)
if not head and not self.path_exists(tail):
Expand All @@ -1550,18 +1552,40 @@ def loadConf(self, daemon, source=None, param=None):
if param is not None:
self.daemons_options[daemon] = param
conf_file = "/etc/{}/{}.conf".format(self.routertype, daemon)
if source is None or not os.path.exists(source):
if source and not os.path.exists(source):
logger.warn(
"missing config '%s' for '%s' creating empty file '%s'",
self.name,
source,
conf_file,
)
if daemon == "frr" or not self.unified_config:
self.cmd_raises("rm -f " + conf_file)
self.cmd_raises("touch " + conf_file)
else:
self.cmd_raises(
"chown {0}:{0} {1}".format(self.routertype, conf_file)
)
self.cmd_raises("chmod 664 {}".format(conf_file))
elif source:
# copy zebra.conf to mgmtd folder, which can be used during startup
if daemon == "zebra":
if daemon == "zebra" and not self.unified_config:
conf_file_mgmt = "/etc/{}/{}.conf".format(self.routertype, "mgmtd")
logger.debug(
"copying '%s' as '%s' on '%s'",
source,
conf_file_mgmt,
self.name,
)
self.cmd_raises("cp {} {}".format(source, conf_file_mgmt))
self.cmd_raises("cp {} {}".format(source, conf_file))
self.cmd_raises(
"chown {0}:{0} {1}".format(self.routertype, conf_file_mgmt)
)
self.cmd_raises("chmod 664 {}".format(conf_file_mgmt))

if not (self.unified_config or daemon == "frr"):
logger.debug(
"copying '%s' as '%s' on '%s'", source, conf_file, self.name
)
self.cmd_raises("cp {} {}".format(source, conf_file))
self.cmd_raises("chown {0}:{0} {1}".format(self.routertype, conf_file))
self.cmd_raises("chmod 664 {}".format(conf_file))

Expand All @@ -1588,7 +1612,8 @@ def loadConf(self, daemon, source=None, param=None):

else:
logger.warning("No daemon {} known".format(daemon))
# print "Daemons after:", self.daemons

return source if os.path.exists(source) else ""

def runInWindow(self, cmd, title=None):
return self.run_in_window(cmd, title)
Expand Down

0 comments on commit 91ac217

Please sign in to comment.