From 8dd5077d81db1c86d185bfdc2f64c8b15d190836 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 31 Jan 2018 11:48:11 +0100 Subject: [PATCH] lib: zebra support for vrfwnetns parameter topotest library is being added a new parameter when preparing the configurationof each daemon. This parameter will be used to call the daemon with some extra parameters. The -n parameter for zebra is taken into account. Also, when a extra parameter is given for calling zebra, a check is done to see if it is possible to run zebra daemon with that option. This is the case for vrfwnetns option. If not available, an error message is sent back. Signed-off-by: Philippe Guibert --- tests/topotests/lib/topogen.py | 13 +++++++++++-- tests/topotests/lib/topotest.py | 22 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 3c500a85dc..d3d50e816c 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -602,7 +602,16 @@ class TopoRouter(TopoGear): # Remove old core files map(os.remove, glob.glob('{}/{}*.dmp'.format(self.logdir, self.name))) - def load_config(self, daemon, source=None): + def check_capability(self, daemon, param): + """ + Checks a capability daemon against an argument option + Return True if capability available. False otherwise + """ + daemonstr = self.RD.get(daemon) + self.logger.info('check capability {} for "{}"'.format(param, daemonstr)) + return self.tgen.net[self.name].checkCapability(daemonstr, param) + + def load_config(self, daemon, source=None, param=None): """ Loads daemon configuration from the specified source Possible daemon values are: TopoRouter.RD_ZEBRA, TopoRouter.RD_RIP, @@ -612,7 +621,7 @@ class TopoRouter(TopoGear): """ daemonstr = self.RD.get(daemon) self.logger.info('loading "{}" configuration: {}'.format(daemonstr, source)) - self.tgen.net[self.name].loadConf(daemonstr, source) + self.tgen.net[self.name].loadConf(daemonstr, source, param) def check_router_running(self): """ diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index 501b8ab053..6fd1e2c179 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -469,6 +469,7 @@ class Router(Node): self.daemons = {'zebra': 0, 'ripd': 0, 'ripngd': 0, 'ospfd': 0, 'ospf6d': 0, 'isisd': 0, 'bgpd': 0, 'pimd': 0, 'ldpd': 0, 'eigrpd': 0, 'nhrpd': 0} + self.daemons_options = {'zebra': ''} def _config_frr(self, **params): "Configure FRR binaries" @@ -569,10 +570,23 @@ class Router(Node): def removeIPs(self): for interface in self.intfNames(): self.cmd('ip address flush', interface) - def loadConf(self, daemon, source=None): + + def checkCapability(self, daemon, param): + if param is not None: + daemon_path = os.path.join(self.daemondir, daemon) + daemon_search_option = param.replace('-','') + output = self.cmd('{0} -h | grep {1}'.format( + daemon_path, daemon_search_option)) + if daemon_search_option not in output: + return False + return True + + def loadConf(self, daemon, source=None, param=None): # print "Daemons before:", self.daemons if daemon in self.daemons.keys(): self.daemons[daemon] = 1 + if param is not None: + self.daemons_options[daemon] = param if source is None: self.cmd('touch /etc/%s/%s.conf' % (self.routertype, daemon)) self.waitOutput() @@ -632,7 +646,6 @@ class Router(Node): logger.info("EIGRP Test, but no eigrpd compiled or installed") return "EIGRP Test, but no eigrpd compiled or installed" - # Init done - now restarting daemons self.restartRouter() return "" def restartRouter(self): @@ -640,8 +653,9 @@ class Router(Node): # Start Zebra first if self.daemons['zebra'] == 1: zebra_path = os.path.join(self.daemondir, 'zebra') - self.cmd('{0} > {1}/{2}-zebra.out 2> {1}/{2}-zebra.err &'.format( - zebra_path, self.logdir, self.name + zebra_option = self.daemons_options['zebra'] + self.cmd('{0} {1} > {2}/{3}-zebra.out 2> {2}/{3}-zebra.err &'.format( + zebra_path, zebra_option, self.logdir, self.name )) self.waitOutput() logger.debug('{}: {} zebra started'.format(self, self.routertype)) -- 2.39.5