topogen: configure daemon logging files

Auto configure daemon logging files to the appropriated place. This
removes the responsibility from the test developer to set this in the
daemon configuration.
This commit is contained in:
Rafael Zalamena 2017-07-07 16:01:30 -03:00 committed by Donald Sharp
parent 36040f453e
commit f6899d4dd4

View File

@ -43,6 +43,7 @@ import sys
import json
import ConfigParser
import glob
import grp
from mininet.net import Mininet
from mininet.log import setLogLevel
@ -431,6 +432,7 @@ class TopoRouter(TopoGear):
self.name = name
self.cls = cls
self.options = {}
self.routertype = params.get('routertype', 'frr')
if not params.has_key('privateDirs'):
params['privateDirs'] = self.PRIVATE_DIRS
@ -461,6 +463,16 @@ class TopoRouter(TopoGear):
except OSError:
pass
# Allow unprivileged daemon user (frr/quagga) to create log files
try:
# Only allow group, if it exist.
gid = grp.getgrnam(self.routertype)[2]
os.chown(self.logdir, 0, gid)
os.chmod(self.logdir, 0775)
except KeyError:
# Allow anyone, but set the sticky bit to avoid file deletions
os.chmod(self.logdir, 01777)
# Try to find relevant old logfiles in /tmp and delete them
map(os.remove, glob.glob('{}/*{}*.log'.format(self.logdir, self.name)))
# Remove old core files
@ -492,9 +504,20 @@ class TopoRouter(TopoGear):
* Clean up files
* Configure interfaces
* Start daemons (e.g. FRR/Quagga)
* Configure daemon logging files
"""
self.logger.debug('starting')
return self.tgen.net[self.name].startRouter()
nrouter = self.tgen.net[self.name]
result = nrouter.startRouter()
# Enable all daemon logging files and set them to the logdir.
for daemon, enabled in nrouter.daemons.iteritems():
if enabled == 0:
continue
self.vtysh_cmd('configure terminal\nlog file {}/{}-{}.log'.format(
self.logdir, self.name, daemon))
return result
def stop(self):
"""