mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-09 20:15:08 +00:00
topotests: remove duplicated code
Handle the duplicated code with a simple conditional: if called from specialized API use provided daemons configuration, otherwise fallback to old `Router` own daemon settings. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
This commit is contained in:
parent
7799deeed6
commit
aa5261bf7d
@ -1144,62 +1144,8 @@ class Router(Node):
|
|||||||
logger.info("BFD Test, but no bfdd compiled or installed")
|
logger.info("BFD Test, but no bfdd compiled or installed")
|
||||||
return "BFD Test, but no bfdd compiled or installed"
|
return "BFD Test, but no bfdd compiled or installed"
|
||||||
|
|
||||||
self.restartRouter()
|
return self.startRouterDaemons()
|
||||||
return ""
|
|
||||||
|
|
||||||
def restartRouter(self):
|
|
||||||
# Starts actual daemons without init (ie restart)
|
|
||||||
# cd to per node directory
|
|
||||||
self.cmd("cd {}/{}".format(self.logdir, self.name))
|
|
||||||
self.cmd("umask 000")
|
|
||||||
# Re-enable to allow for report per run
|
|
||||||
self.reportCores = True
|
|
||||||
if self.version == None:
|
|
||||||
self.version = self.cmd(
|
|
||||||
os.path.join(self.daemondir, "bgpd") + " -v"
|
|
||||||
).split()[2]
|
|
||||||
logger.info("{}: running version: {}".format(self.name, self.version))
|
|
||||||
# Start Zebra first
|
|
||||||
if self.daemons["zebra"] == 1:
|
|
||||||
zebra_path = os.path.join(self.daemondir, "zebra")
|
|
||||||
zebra_option = self.daemons_options["zebra"]
|
|
||||||
self.cmd(
|
|
||||||
"{0} {1} > zebra.out 2> zebra.err &".format(
|
|
||||||
zebra_path, zebra_option, self.logdir, self.name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.waitOutput()
|
|
||||||
logger.debug("{}: {} zebra started".format(self, self.routertype))
|
|
||||||
sleep(1, "{}: waiting for zebra to start".format(self.name))
|
|
||||||
# Start staticd next if required
|
|
||||||
if self.daemons["staticd"] == 1:
|
|
||||||
staticd_path = os.path.join(self.daemondir, "staticd")
|
|
||||||
staticd_option = self.daemons_options["staticd"]
|
|
||||||
self.cmd(
|
|
||||||
"{0} {1} > staticd.out 2> staticd.err &".format(
|
|
||||||
staticd_path, staticd_option, self.logdir, self.name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.waitOutput()
|
|
||||||
logger.debug("{}: {} staticd started".format(self, self.routertype))
|
|
||||||
# Fix Link-Local Addresses
|
|
||||||
# Somehow (on Mininet only), Zebra removes the IPv6 Link-Local addresses on start. Fix this
|
|
||||||
self.cmd(
|
|
||||||
"for i in `ls /sys/class/net/` ; do mac=`cat /sys/class/net/$i/address`; IFS=':'; set $mac; unset IFS; ip address add dev $i scope link fe80::$(printf %02x $((0x$1 ^ 2)))$2:${3}ff:fe$4:$5$6/64; done"
|
|
||||||
)
|
|
||||||
# Now start all the other daemons
|
|
||||||
for daemon in self.daemons:
|
|
||||||
# Skip disabled daemons and zebra
|
|
||||||
if self.daemons[daemon] == 0 or daemon == "zebra" or daemon == "staticd":
|
|
||||||
continue
|
|
||||||
daemon_path = os.path.join(self.daemondir, daemon)
|
|
||||||
self.cmd(
|
|
||||||
"{0} {1} > {2}.out 2> {2}.err &".format(
|
|
||||||
daemon_path, self.daemons_options.get(daemon, ""), daemon
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.waitOutput()
|
|
||||||
logger.debug("{}: {} {} started".format(self, self.routertype, daemon))
|
|
||||||
|
|
||||||
def getStdErr(self, daemon):
|
def getStdErr(self, daemon):
|
||||||
return self.getLog("err", daemon)
|
return self.getLog("err", daemon)
|
||||||
@ -1210,64 +1156,93 @@ class Router(Node):
|
|||||||
def getLog(self, log, daemon):
|
def getLog(self, log, daemon):
|
||||||
return self.cmd("cat {}/{}/{}.{}".format(self.logdir, self.name, daemon, log))
|
return self.cmd("cat {}/{}/{}.{}".format(self.logdir, self.name, daemon, log))
|
||||||
|
|
||||||
def startRouterDaemons(self, daemons):
|
def startRouterDaemons(self, daemons=None):
|
||||||
|
"Starts all FRR daemons for this router."
|
||||||
|
|
||||||
# Starts actual daemons without init (ie restart)
|
# Starts actual daemons without init (ie restart)
|
||||||
# cd to per node directory
|
# cd to per node directory
|
||||||
self.cmd('cd {}/{}'.format(self.logdir, self.name))
|
self.cmd("cd {}/{}".format(self.logdir, self.name))
|
||||||
self.cmd('umask 000')
|
self.cmd("umask 000")
|
||||||
#Re-enable to allow for report per run
|
|
||||||
|
# Re-enable to allow for report per run
|
||||||
self.reportCores = True
|
self.reportCores = True
|
||||||
rundaemons = self.cmd('ls -1 /var/run/%s/*.pid' % self.routertype)
|
|
||||||
|
|
||||||
for daemon in daemons:
|
# XXX: glue code forward ported from removed function.
|
||||||
if daemon == 'zebra':
|
if self.version == None:
|
||||||
# Start Zebra first
|
self.version = self.cmd(
|
||||||
if self.daemons['zebra'] == 1:
|
os.path.join(self.daemondir, 'bgpd') + ' -v'
|
||||||
zebra_path = os.path.join(self.daemondir, 'zebra')
|
).split()[2]
|
||||||
zebra_option = self.daemons_options['zebra']
|
logger.info("{}: running version: {}".format(self.name, self.version))
|
||||||
self.cmd('{0} {1} > zebra.out 2> zebra.err &'.format(
|
|
||||||
zebra_path, zebra_option, self.logdir, self.name
|
|
||||||
))
|
|
||||||
self.waitOutput()
|
|
||||||
logger.debug('{}: {} zebra started'.format(self, self.routertype))
|
|
||||||
sleep(1, '{}: waiting for zebra to start'.format(self.name))
|
|
||||||
|
|
||||||
# Fix Link-Local Addresses
|
# If `daemons` was specified then some upper API called us with
|
||||||
# Somehow (on Mininet only), Zebra removes the IPv6 Link-Local
|
# specific daemons, otherwise just use our own configuration.
|
||||||
# addresses on start. Fix this
|
daemons_list = []
|
||||||
self.cmd('for i in `ls /sys/class/net/` ; do mac=`cat /sys/class/net/$i/address`; IFS=\':\'; set $mac; unset IFS; ip address add dev $i scope link fe80::$(printf %02x $((0x$1 ^ 2)))$2:${3}ff:fe$4:$5$6/64; done')
|
if daemons is None:
|
||||||
|
# Append all daemons configured.
|
||||||
|
for daemon in self.daemons:
|
||||||
|
if self.daemons[daemon] == 1:
|
||||||
|
daemons_list.append(daemon)
|
||||||
|
|
||||||
if daemon == 'staticd':
|
# Start Zebra first
|
||||||
# Start staticd next if required
|
if 'zebra' in daemons_list:
|
||||||
if self.daemons['staticd'] == 1:
|
zebra_path = os.path.join(self.daemondir, "zebra")
|
||||||
staticd_path = os.path.join(self.daemondir, 'staticd')
|
zebra_option = self.daemons_options["zebra"]
|
||||||
staticd_option = self.daemons_options['staticd']
|
self.cmd(
|
||||||
self.cmd('{0} {1} > staticd.out 2> staticd.err &'.format(
|
"{0} {1} > zebra.out 2> zebra.err &".format(
|
||||||
staticd_path, staticd_option, self.logdir, self.name
|
zebra_path, zebra_option, self.logdir, self.name
|
||||||
))
|
)
|
||||||
self.waitOutput()
|
)
|
||||||
logger.debug('{}: {} staticd started'.format(self, self.routertype))
|
|
||||||
sleep(1, '{}: waiting for staticd to start'.format(self.name))
|
|
||||||
|
|
||||||
# Now start all the daemons
|
|
||||||
# Skip disabled daemons and zebra
|
|
||||||
if self.daemons[daemon] == 0 or daemon == 'zebra' or daemon == 'staticd':
|
|
||||||
continue
|
|
||||||
daemon_path = os.path.join(self.daemondir, daemon)
|
|
||||||
self.cmd('{0} > {1}.out 2> {1}.err &'.format(
|
|
||||||
daemon_path, daemon
|
|
||||||
))
|
|
||||||
self.waitOutput()
|
self.waitOutput()
|
||||||
logger.debug('{}: {} {} started'.format(self, self.routertype, daemon))
|
logger.debug("{}: {} zebra started".format(self, self.routertype))
|
||||||
sleep(1, '{}: waiting for {} to start'.format(self.name, daemon))
|
sleep(1, "{}: waiting for zebra to start".format(self.name))
|
||||||
|
|
||||||
|
# Remove `zebra` so we don't attempt to start it again.
|
||||||
|
daemons_list.remove('zebra')
|
||||||
|
|
||||||
|
# Start staticd next if required
|
||||||
|
if 'staticd' in daemons_list:
|
||||||
|
staticd_path = os.path.join(self.daemondir, "staticd")
|
||||||
|
staticd_option = self.daemons_options["staticd"]
|
||||||
|
self.cmd(
|
||||||
|
"{0} {1} > staticd.out 2> staticd.err &".format(
|
||||||
|
staticd_path, staticd_option, self.logdir, self.name
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.waitOutput()
|
||||||
|
logger.debug("{}: {} staticd started".format(self, self.routertype))
|
||||||
|
|
||||||
|
# Remove `staticd` so we don't attempt to start it again.
|
||||||
|
daemons_list.remove('staticd')
|
||||||
|
|
||||||
|
# Fix Link-Local Addresses
|
||||||
|
# Somehow (on Mininet only), Zebra removes the IPv6 Link-Local addresses on start. Fix this
|
||||||
|
self.cmd(
|
||||||
|
"for i in `ls /sys/class/net/` ; do mac=`cat /sys/class/net/$i/address`; IFS=':'; set $mac; unset IFS; ip address add dev $i scope link fe80::$(printf %02x $((0x$1 ^ 2)))$2:${3}ff:fe$4:$5$6/64; done"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Now start all the other daemons
|
||||||
|
for daemon in self.daemons:
|
||||||
|
# Skip disabled daemons and zebra
|
||||||
|
if self.daemons[daemon] == 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
daemon_path = os.path.join(self.daemondir, daemon)
|
||||||
|
self.cmd(
|
||||||
|
"{0} {1} > {2}.out 2> {2}.err &".format(
|
||||||
|
daemon_path, self.daemons_options.get(daemon, ""), daemon
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.waitOutput()
|
||||||
|
logger.debug("{}: {} {} started".format(self, self.routertype, daemon))
|
||||||
|
|
||||||
|
# Check if daemons are running.
|
||||||
rundaemons = self.cmd('ls -1 /var/run/%s/*.pid' % self.routertype)
|
rundaemons = self.cmd('ls -1 /var/run/%s/*.pid' % self.routertype)
|
||||||
|
|
||||||
if re.search(r"No such file or directory", rundaemons):
|
if re.search(r"No such file or directory", rundaemons):
|
||||||
return "Daemons are not running"
|
return "Daemons are not running"
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def killRouterDaemons(self, daemons, wait=True, assertOnError=True,
|
def killRouterDaemons(self, daemons, wait=True, assertOnError=True,
|
||||||
minErrorVersion='5.1'):
|
minErrorVersion='5.1'):
|
||||||
# Kill Running Quagga or FRR specific
|
# Kill Running Quagga or FRR specific
|
||||||
|
Loading…
Reference in New Issue
Block a user