From df437d254a7f29e5b3538b7367670566314cbe6f Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Wed, 20 Dec 2017 07:43:30 -0500 Subject: lib: add LabN testing template Signed-off-by: Lou Berger --- tests/topotests/lib/ltemplate.py | 151 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 tests/topotests/lib/ltemplate.py (limited to 'tests/topotests/lib/ltemplate.py') diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py new file mode 100644 index 0000000000..89fb6a6330 --- /dev/null +++ b/tests/topotests/lib/ltemplate.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python + +# +# Part of NetDEF Topology Tests +# +# Copyright (c) 2017 by +# Network Device Education Foundation, Inc. ("NetDEF") +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# + +""" +ltemplate.py: LabN template for FRR tests. +""" + +import os +import sys +import pytest + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger +from lib.lutil import * + +# Required to instantiate the topology builder class. +from mininet.topo import Topo +from customize import * + +def setup_module(mod): + "Sets up the pytest environment" + # This function initiates the topology build with Topogen... + tgen = Topogen(ThisTestTopo, mod.__name__) + # ... and here it calls Mininet initialization functions. + tgen.start_topology() + + logger.info('Topology started') + try: + ltemplatePreRouterStartHook() + except NameError: + #not defined + logger.debug("ltemplatePreRouterStartHook() not defined") + + # This is a sample of configuration loading. + router_list = tgen.routers() + + # For all registred routers, load the zebra configuration file + for rname, router in router_list.iteritems(): + print("Setting up %s" % rname) + config = os.path.join(CWD, '{}/zebra.conf'.format(rname)) + if os.path.exists(config): + router.load_config(TopoRouter.RD_ZEBRA, config) + config = os.path.join(CWD, '{}/ospfd.conf'.format(rname)) + if os.path.exists(config): + router.load_config(TopoRouter.RD_OSPF, config) + config = os.path.join(CWD, '{}/ldpd.conf'.format(rname)) + if os.path.exists(config): + router.load_config(TopoRouter.RD_LDP, config) + config = os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + if os.path.exists(config): + router.load_config(TopoRouter.RD_BGP, config) + + # After loading the configurations, this function loads configured daemons. + logger.info('Starting routers') + tgen.start_router() + try: + ltemplatePostRouterStartHook() + except NameError: + #not defined + logger.debug("ltemplatePostRouterStartHook() not defined") + +def teardown_module(mod): + "Teardown the pytest environment" + tgen = get_topogen() + + # This function tears down the whole topology. + tgen.stop_topology() + +class LTemplate: + scriptdir = None + +#init class +_lt = LTemplate() + +def ltemplate_start(testDir): + logger.info('ltemplate start in ' + testDir) + test = os.path.basename(testDir) + logDir = '/tmp/topotests/{0}.test_{0}'.format(test) + tgen = get_topogen() + luStart(baseScriptDir=testDir, baseLogDir=logDir, net=tgen.net) + _lt.scriptdir = testDir + +def ltemplateTest(script, SkipIfFailed=True, CallOnFail=None, CheckFuncStr=None): + tgen = get_topogen() + if not os.path.isfile(script): + if not os.path.isfile(os.path.join(_lt.scriptdir, script)): + logger.error('Could not find script file: ' + script) + assert 'Could not find script file: ' + script + logger.info("Starting template test: " + script) + numEntry = luNumFail() + + if SkipIfFailed and tgen.routers_have_failure(): + pytest.skip(tgen.errors) + if numEntry > 0: + pytest.skip("Have %d errors" % numEntry) + + if CheckFuncStr != None: + check = eval(CheckFuncStr) + if check != True: + pytest.skip("Check function '"+CheckFuncStr+"' returned: " + check) + + luInclude(script, CallOnFail) + numFail = luNumFail() - numEntry + if numFail > 0: + luShowFail() + fatal_error = "%d tests failed" % numFail + assert "scripts/cleanup_all.py failed" == "See summary output above", fatal_error + +# Memory leak test template +def test_memory_leak(): + "Run the memory leak test and report results." + tgen = get_topogen() + if not tgen.is_memleak_enabled(): + pytest.skip('Memory leak test/report is disabled') + + tgen.report_memory_leaks() + +#clean up ltemplate + +def test_ltemplate_finish(): + logger.info('Done with ltemplate tests') + if _lt.scriptdir != None: + print(luFinish()) + +#for testing +if __name__ == '__main__': + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) -- cgit v1.2.3 From 5859c4be6ba897d34e388b01b54e7a3e3b81a98c Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Mon, 22 Jan 2018 21:09:02 -0500 Subject: lib: ltemplate - fix handling of CallOnFail Signed-off-by: Lou Berger --- tests/topotests/lib/ltemplate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/topotests/lib/ltemplate.py') diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index 89fb6a6330..e1d7750a07 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -122,7 +122,7 @@ def ltemplateTest(script, SkipIfFailed=True, CallOnFail=None, CheckFuncStr=None) if check != True: pytest.skip("Check function '"+CheckFuncStr+"' returned: " + check) - luInclude(script, CallOnFail) + luInclude(script, eval(CallOnFail)) numFail = luNumFail() - numEntry if numFail > 0: luShowFail() -- cgit v1.2.3 From 8ab91133c7789960d7404c95a6c875f51c365ee4 Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Tue, 23 Jan 2018 08:10:50 -0500 Subject: lib: ltemplate - fix handling of CallOnFail (take 2) Signed-off-by: Lou Berger --- tests/topotests/lib/ltemplate.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/topotests/lib/ltemplate.py') diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index e1d7750a07..c112235fc0 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -122,7 +122,9 @@ def ltemplateTest(script, SkipIfFailed=True, CallOnFail=None, CheckFuncStr=None) if check != True: pytest.skip("Check function '"+CheckFuncStr+"' returned: " + check) - luInclude(script, eval(CallOnFail)) + if CallOnFail != None: + CallOnFail = eval(CallOnFail) + luInclude(script, CallOnFail) numFail = luNumFail() - numEntry if numFail > 0: luShowFail() -- cgit v1.2.3 From 9e219b9af716cd26356541baded631be95edbccf Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Fri, 26 Jan 2018 08:51:00 -0500 Subject: lib: scope life of Lutil and _lt to a single test run reorg to support regression environment Signed-off-by: Lou Berger --- tests/topotests/lib/ltemplate.py | 132 +++++++++++++++++++++++++-------------- tests/topotests/lib/lutil.py | 17 +++-- 2 files changed, 96 insertions(+), 53 deletions(-) (limited to 'tests/topotests/lib/ltemplate.py') diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index c112235fc0..c141ef7585 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -28,6 +28,7 @@ ltemplate.py: LabN template for FRR tests. import os import sys import pytest +import imp # pylint: disable=C0413 # Import topogen and topotest helpers @@ -38,49 +39,87 @@ from lib.lutil import * # Required to instantiate the topology builder class. from mininet.topo import Topo -from customize import * + +customize = None + +class LTemplate(): + scriptdir = None + test = None + testdir = None + + def __init__(self, test, testdir): + global customize + customize = imp.load_source('customize', os.path.join(testdir, 'customize.py')) + self.test = test + self.testdir = testdir + logger.info('LTemplate: '+test) + + def setup_module(self, mod): + "Sets up the pytest environment" + # This function initiates the topology build with Topogen... + tgen = Topogen(customize.ThisTestTopo, mod.__name__) + # ... and here it calls Mininet initialization functions. + tgen.start_topology() + + logger.info('Topology started') + try: + customize.ltemplatePreRouterStartHook() + except NameError: + #not defined + logger.debug("ltemplatePreRouterStartHook() not defined") + + # This is a sample of configuration loading. + router_list = tgen.routers() + + # For all registred routers, load the zebra configuration file + for rname, router in router_list.iteritems(): + print("Setting up %s" % rname) + config = os.path.join(self.testdir, '{}/zebra.conf'.format(rname)) + if os.path.exists(config): + router.load_config(TopoRouter.RD_ZEBRA, config) + config = os.path.join(self.testdir, '{}/ospfd.conf'.format(rname)) + if os.path.exists(config): + router.load_config(TopoRouter.RD_OSPF, config) + config = os.path.join(self.testdir, '{}/ldpd.conf'.format(rname)) + if os.path.exists(config): + router.load_config(TopoRouter.RD_LDP, config) + config = os.path.join(self.testdir, '{}/bgpd.conf'.format(rname)) + if os.path.exists(config): + router.load_config(TopoRouter.RD_BGP, config) + + # After loading the configurations, this function loads configured daemons. + logger.info('Starting routers') + tgen.start_router() + try: + customize.ltemplatePostRouterStartHook() + except NameError: + #not defined + logger.debug("ltemplatePostRouterStartHook() not defined") + +#initialized by ltemplate_start +_lt = None def setup_module(mod): - "Sets up the pytest environment" - # This function initiates the topology build with Topogen... - tgen = Topogen(ThisTestTopo, mod.__name__) - # ... and here it calls Mininet initialization functions. - tgen.start_topology() - - logger.info('Topology started') - try: - ltemplatePreRouterStartHook() - except NameError: - #not defined - logger.debug("ltemplatePreRouterStartHook() not defined") - - # This is a sample of configuration loading. - router_list = tgen.routers() - - # For all registred routers, load the zebra configuration file - for rname, router in router_list.iteritems(): - print("Setting up %s" % rname) - config = os.path.join(CWD, '{}/zebra.conf'.format(rname)) - if os.path.exists(config): - router.load_config(TopoRouter.RD_ZEBRA, config) - config = os.path.join(CWD, '{}/ospfd.conf'.format(rname)) - if os.path.exists(config): - router.load_config(TopoRouter.RD_OSPF, config) - config = os.path.join(CWD, '{}/ldpd.conf'.format(rname)) - if os.path.exists(config): - router.load_config(TopoRouter.RD_LDP, config) - config = os.path.join(CWD, '{}/bgpd.conf'.format(rname)) - if os.path.exists(config): - router.load_config(TopoRouter.RD_BGP, config) - - # After loading the configurations, this function loads configured daemons. - logger.info('Starting routers') - tgen.start_router() - try: - ltemplatePostRouterStartHook() - except NameError: - #not defined - logger.debug("ltemplatePostRouterStartHook() not defined") + global _lt + root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + test = mod.__name__[:mod.__name__.rfind(".")] + testdir = os.path.join(root, test) + + #don't do this for now as reload didn't work as expected + #fixup sys.path, want test dir there only once + #try: + # sys.path.remove(testdir) + #except ValueError: + # logger.debug(testdir+" not found in original sys.path") + #add testdir + #sys.path.append(testdir) + + #init class + _lt = LTemplate(test, testdir) + _lt.setup_module(mod) + + #drop testdir + #sys.path.remove(testdir) def teardown_module(mod): "Teardown the pytest environment" @@ -89,12 +128,6 @@ def teardown_module(mod): # This function tears down the whole topology. tgen.stop_topology() -class LTemplate: - scriptdir = None - -#init class -_lt = LTemplate() - def ltemplate_start(testDir): logger.info('ltemplate start in ' + testDir) test = os.path.basename(testDir) @@ -143,9 +176,12 @@ def test_memory_leak(): #clean up ltemplate def test_ltemplate_finish(): + global _lt logger.info('Done with ltemplate tests') - if _lt.scriptdir != None: + if _lt != None and _lt.scriptdir != None: print(luFinish()) + #done + _lt = None #for testing if __name__ == '__main__': diff --git a/tests/topotests/lib/lutil.py b/tests/topotests/lib/lutil.py index 8ecaf98d89..fdb1af0539 100755 --- a/tests/topotests/lib/lutil.py +++ b/tests/topotests/lib/lutil.py @@ -221,12 +221,15 @@ Total %-4d %-4d %d\n\ found = self.command(target, command, regexp, 'pass', '%s +%4.2f secs' % (result, delta)) return found -#init class -LUtil=lUtil() +#initialized by luStart +LUtil=None #entry calls def luStart(baseScriptDir='.', baseLogDir='.', net='', fout='output.log', fsum='summary.txt', level=9): + global LUtil + #init class + LUtil=lUtil() LUtil.base_script_dir = baseScriptDir LUtil.base_log_dir = baseLogDir LUtil.net = net @@ -242,23 +245,27 @@ def luCommand(target, command, regexp='.', op='none', result='', time=10): else: return LUtil.wait(target, command, regexp, op, result, time) - def luInclude(filename, CallOnFail=None): - global LUtil tstFile = LUtil.base_script_dir + '/' + filename LUtil.setFilename(filename) if CallOnFail != None: oldCallOnFail = LUtil.getCallOnFail() LUtil.setCallOnFail(CallOnFail) if filename.endswith('.py'): + LUtil.log("luInclude: execfile "+tstFile) execfile(tstFile) else: + LUtil.log("luInclude: execTestFile "+tstFile) LUtil.execTestFile(tstFile) if CallOnFail != None: LUtil.setCallOnFail(oldCallOnFail) def luFinish(): - return LUtil.closeFiles() + global LUtil + ret = LUtil.closeFiles() + #done + LUtil = None + return ret; def luNumFail(): return LUtil.l_fail -- cgit v1.2.3 From 850de337d922ecbb8f55098ecd067e63df0fecd9 Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Sat, 27 Jan 2018 17:00:58 -0500 Subject: lib: ltemplate simplify start/stop Signed-off-by: Lou Berger --- tests/topotests/lib/ltemplate.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'tests/topotests/lib/ltemplate.py') diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index c141ef7585..30ff2cd7f6 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -43,15 +43,18 @@ from mininet.topo import Topo customize = None class LTemplate(): - scriptdir = None test = None testdir = None + scriptdir = None + logdir = None def __init__(self, test, testdir): global customize customize = imp.load_source('customize', os.path.join(testdir, 'customize.py')) self.test = test self.testdir = testdir + self.scriptdir = testdir + self.logdir = '/tmp/topotests/{0}.test_{0}'.format(test) logger.info('LTemplate: '+test) def setup_module(self, mod): @@ -95,6 +98,7 @@ class LTemplate(): except NameError: #not defined logger.debug("ltemplatePostRouterStartHook() not defined") + luStart(baseScriptDir=self.scriptdir, baseLogDir=self.logdir, net=tgen.net) #initialized by ltemplate_start _lt = None @@ -122,19 +126,16 @@ def setup_module(mod): #sys.path.remove(testdir) def teardown_module(mod): + global _lt "Teardown the pytest environment" tgen = get_topogen() + if _lt != None and _lt.scriptdir != None: + print(luFinish()) + # This function tears down the whole topology. tgen.stop_topology() - -def ltemplate_start(testDir): - logger.info('ltemplate start in ' + testDir) - test = os.path.basename(testDir) - logDir = '/tmp/topotests/{0}.test_{0}'.format(test) - tgen = get_topogen() - luStart(baseScriptDir=testDir, baseLogDir=logDir, net=tgen.net) - _lt.scriptdir = testDir + _lt = None def ltemplateTest(script, SkipIfFailed=True, CallOnFail=None, CheckFuncStr=None): tgen = get_topogen() @@ -173,16 +174,6 @@ def test_memory_leak(): tgen.report_memory_leaks() -#clean up ltemplate - -def test_ltemplate_finish(): - global _lt - logger.info('Done with ltemplate tests') - if _lt != None and _lt.scriptdir != None: - print(luFinish()) - #done - _lt = None - #for testing if __name__ == '__main__': args = ["-s"] + sys.argv[1:] -- cgit v1.2.3 From 89b9abd97e787773b35f9a54c4de514a4888ad4b Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Tue, 13 Feb 2018 10:37:23 -0500 Subject: lib: ltemplate add common ltemplateRtrCmd and ltemplateVersionCheck Signed-off-by: Lou Berger --- tests/topotests/lib/ltemplate.py | 106 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 4 deletions(-) (limited to 'tests/topotests/lib/ltemplate.py') diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index 30ff2cd7f6..7ca8828dfe 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -27,6 +27,7 @@ ltemplate.py: LabN template for FRR tests. import os import sys +import platform import pytest import imp @@ -47,6 +48,9 @@ class LTemplate(): testdir = None scriptdir = None logdir = None + prestarthooksuccess = True + poststarthooksuccess = True + iproute2Ver = None def __init__(self, test, testdir): global customize @@ -66,8 +70,8 @@ class LTemplate(): logger.info('Topology started') try: - customize.ltemplatePreRouterStartHook() - except NameError: + self.prestarthooksuccess = customize.ltemplatePreRouterStartHook() + except AttributeError: #not defined logger.debug("ltemplatePreRouterStartHook() not defined") @@ -94,8 +98,8 @@ class LTemplate(): logger.info('Starting routers') tgen.start_router() try: - customize.ltemplatePostRouterStartHook() - except NameError: + self.poststarthooksuccess = customize.ltemplatePostRouterStartHook() + except AttributeError: #not defined logger.debug("ltemplatePostRouterStartHook() not defined") luStart(baseScriptDir=self.scriptdir, baseLogDir=self.logdir, net=tgen.net) @@ -174,6 +178,100 @@ def test_memory_leak(): tgen.report_memory_leaks() +class ltemplateRtrCmd(): + def __init__(self): + self.resetCounts() + + def doCmd(self, tgen, rtr, cmd, checkstr = None): + output = tgen.net[rtr].cmd(cmd).strip() + if len(output): + self.output += 1 + if checkstr != None: + ret = re.search(checkstr, output) + if ret == None: + self.nomatch += 1 + else: + self.match += 1 + return ret + logger.info('command: {} {}'.format(rtr, cmd)) + logger.info('output: ' + output) + self.none += 1 + return None + + def resetCounts(self): + self.match = 0 + self.nomatch = 0 + self.output = 0 + self.none = 0 + + def getMatch(self): + return self.match + + def getNoMatch(self): + return self.nomatch + + def getOutput(self): + return self.output + + def getNone(self): + return self.none + +def ltemplateVersionCheck(vstr, rname='r1', compstr='<',cli=False, kernel='4.9', iproute2=None, mpls=True): + tgen = get_topogen() + router = tgen.gears[rname] + + if cli: + logger.info('calling mininet CLI') + tgen.mininet_cli() + logger.info('exited mininet CLI') + + if _lt == None: + ret = 'Template not initialized' + return ret + + if _lt.prestarthooksuccess != True: + ret = 'ltemplatePreRouterStartHook failed' + return ret + + if _lt.poststarthooksuccess != True: + ret = 'ltemplatePostRouterStartHook failed' + return ret + + if mpls == True and tgen.hasmpls != True: + ret = 'MPLS not initialized' + return ret + + if kernel != None: + krel = platform.release() + if topotest.version_cmp(krel, kernel) < 0: + ret = 'Skipping tests, old kernel ({} < {})'.format(krel, kernel) + return ret + + if iproute2 != None: + if _lt.iproute2Ver == None: + #collect/log info on iproute2 + cc = ltemplateRtrCmd() + found = cc.doCmd(tgen, 'r2', 'apt-cache policy iproute2', 'Installed: ([\d\.]*)') + if found != None: + iproute2Ver = found.group(1) + else: + iproute2Ver = '0-unknown' + logger.info('Have iproute2 version=' + iproute2Ver) + + if topotest.version_cmp(iproute2Ver, iproute2) < 0: + ret = 'Skipping tests, old iproute2 ({} < {})'.format(iproute2Ver, iproute2) + return ret + + ret = True + try: + if router.has_version(compstr, vstr): + ret = 'Skipping tests, old FRR version {} {}'.format(compstr, vstr) + return ret + except: + ret = True + + return ret + #for testing if __name__ == '__main__': args = ["-s"] + sys.argv[1:] -- cgit v1.2.3 From 09da03d50db3ae344a14b59984188f2fff5fe4f1 Mon Sep 17 00:00:00 2001 From: "G. Paul Ziemba" Date: Mon, 26 Feb 2018 07:52:22 -0800 Subject: ltemplate.py: remove dependency on hard-coded router name r2 Signed-off-by: G. Paul Ziemba --- tests/topotests/lib/ltemplate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/topotests/lib/ltemplate.py') diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index 7ca8828dfe..62e11e810e 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -251,7 +251,7 @@ def ltemplateVersionCheck(vstr, rname='r1', compstr='<',cli=False, kernel='4.9', if _lt.iproute2Ver == None: #collect/log info on iproute2 cc = ltemplateRtrCmd() - found = cc.doCmd(tgen, 'r2', 'apt-cache policy iproute2', 'Installed: ([\d\.]*)') + found = cc.doCmd(tgen, rname, 'apt-cache policy iproute2', 'Installed: ([\d\.]*)') if found != None: iproute2Ver = found.group(1) else: -- cgit v1.2.3 From 7fdc42389ab92f2be7bf054e62620dae25459428 Mon Sep 17 00:00:00 2001 From: "G. Paul Ziemba" Date: Wed, 28 Feb 2018 21:44:49 -0800 Subject: ltemplate.py: start isisd when isisd.conf present Signed-off-by: G. Paul Ziemba --- tests/topotests/lib/ltemplate.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/topotests/lib/ltemplate.py') diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index 62e11e810e..9c511f7bc7 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -93,6 +93,9 @@ class LTemplate(): config = os.path.join(self.testdir, '{}/bgpd.conf'.format(rname)) if os.path.exists(config): router.load_config(TopoRouter.RD_BGP, config) + config = os.path.join(self.testdir, '{}/isisd.conf'.format(rname)) + if os.path.exists(config): + router.load_config(TopoRouter.RD_ISIS, config) # After loading the configurations, this function loads configured daemons. logger.info('Starting routers') -- cgit v1.2.3 From 90d56c6cca0a6ac24ff31cfb509211b75e009af3 Mon Sep 17 00:00:00 2001 From: "G. Paul Ziemba" Date: Sat, 3 Mar 2018 12:22:39 -0800 Subject: lib/ltemplate.py: add KeepGoing parameter to ltemplateTest Signed-off-by: G. Paul Ziemba --- tests/topotests/lib/ltemplate.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tests/topotests/lib/ltemplate.py') diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index 9c511f7bc7..5843b4096a 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -144,7 +144,7 @@ def teardown_module(mod): tgen.stop_topology() _lt = None -def ltemplateTest(script, SkipIfFailed=True, CallOnFail=None, CheckFuncStr=None): +def ltemplateTest(script, SkipIfFailed=True, CallOnFail=None, CheckFuncStr=None, KeepGoing=False): tgen = get_topogen() if not os.path.isfile(script): if not os.path.isfile(os.path.join(_lt.scriptdir, script)): @@ -156,7 +156,8 @@ def ltemplateTest(script, SkipIfFailed=True, CallOnFail=None, CheckFuncStr=None) if SkipIfFailed and tgen.routers_have_failure(): pytest.skip(tgen.errors) if numEntry > 0: - pytest.skip("Have %d errors" % numEntry) + if not KeepGoing: + pytest.skip("Have %d errors" % numEntry) if CheckFuncStr != None: check = eval(CheckFuncStr) @@ -170,7 +171,8 @@ def ltemplateTest(script, SkipIfFailed=True, CallOnFail=None, CheckFuncStr=None) if numFail > 0: luShowFail() fatal_error = "%d tests failed" % numFail - assert "scripts/cleanup_all.py failed" == "See summary output above", fatal_error + if not KeepGoing: + assert "scripts/cleanup_all.py failed" == "See summary output above", fatal_error # Memory leak test template def test_memory_leak(): -- cgit v1.2.3 From af01532c458062a14f24b91f5a7c380ef0380ee2 Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Thu, 9 Aug 2018 10:52:48 -0400 Subject: lib: speedup test exit when startup fails Signed-off-by: Lou Berger --- tests/topotests/lib/ltemplate.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests/topotests/lib/ltemplate.py') diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index 5843b4096a..31eaec7009 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -74,6 +74,9 @@ class LTemplate(): except AttributeError: #not defined logger.debug("ltemplatePreRouterStartHook() not defined") + if self.prestarthooksuccess != True: + logger.info('ltemplatePreRouterStartHook() failed, skipping test') + return # This is a sample of configuration loading. router_list = tgen.routers() @@ -137,7 +140,7 @@ def teardown_module(mod): "Teardown the pytest environment" tgen = get_topogen() - if _lt != None and _lt.scriptdir != None: + if _lt != None and _lt.scriptdir != None and _lt.prestarthooksuccess == True: print(luFinish()) # This function tears down the whole topology. @@ -145,6 +148,10 @@ def teardown_module(mod): _lt = None def ltemplateTest(script, SkipIfFailed=True, CallOnFail=None, CheckFuncStr=None, KeepGoing=False): + global _lt + if _lt == None or _lt.prestarthooksuccess != True: + return + tgen = get_topogen() if not os.path.isfile(script): if not os.path.isfile(os.path.join(_lt.scriptdir, script)): -- cgit v1.2.3