Skip to content

Commit

Permalink
topogen: configure daemon logging files
Browse files Browse the repository at this point in the history
Auto configure daemon logging files to the appropriated place. This
removes the responsibility from the test developer to set this in the
daemon configuration.
  • Loading branch information
rzalamena committed Jul 10, 2017
1 parent d5409d7 commit 3e64410
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/topogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import json
import ConfigParser
import glob
import grp

from mininet.net import Mininet
from mininet.log import setLogLevel
Expand Down Expand Up @@ -431,6 +432,7 @@ def __init__(self, tgen, cls, name, **params):
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

Expand Down Expand Up @@ -461,6 +463,16 @@ def _prepare_tmpfiles(self):
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
Expand Down Expand Up @@ -492,9 +504,20 @@ def start(self):
* 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):
"""
Expand Down

0 comments on commit 3e64410

Please sign in to comment.