mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-07 09:22:03 +00:00
lib: scope life of Lutil and _lt to a single test run reorg to support regression environment
Signed-off-by: Lou Berger <lberger@labn.net>
This commit is contained in:
parent
b9ff36bed7
commit
9e219b9af7
@ -28,6 +28,7 @@ ltemplate.py: LabN template for FRR tests.
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import pytest
|
import pytest
|
||||||
|
import imp
|
||||||
|
|
||||||
# pylint: disable=C0413
|
# pylint: disable=C0413
|
||||||
# Import topogen and topotest helpers
|
# Import topogen and topotest helpers
|
||||||
@ -38,49 +39,87 @@ from lib.lutil import *
|
|||||||
|
|
||||||
# Required to instantiate the topology builder class.
|
# Required to instantiate the topology builder class.
|
||||||
from mininet.topo import Topo
|
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):
|
def setup_module(mod):
|
||||||
"Sets up the pytest environment"
|
global _lt
|
||||||
# This function initiates the topology build with Topogen...
|
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
tgen = Topogen(ThisTestTopo, mod.__name__)
|
test = mod.__name__[:mod.__name__.rfind(".")]
|
||||||
# ... and here it calls Mininet initialization functions.
|
testdir = os.path.join(root, test)
|
||||||
tgen.start_topology()
|
|
||||||
|
|
||||||
logger.info('Topology started')
|
#don't do this for now as reload didn't work as expected
|
||||||
try:
|
#fixup sys.path, want test dir there only once
|
||||||
ltemplatePreRouterStartHook()
|
#try:
|
||||||
except NameError:
|
# sys.path.remove(testdir)
|
||||||
#not defined
|
#except ValueError:
|
||||||
logger.debug("ltemplatePreRouterStartHook() not defined")
|
# logger.debug(testdir+" not found in original sys.path")
|
||||||
|
#add testdir
|
||||||
|
#sys.path.append(testdir)
|
||||||
|
|
||||||
# This is a sample of configuration loading.
|
#init class
|
||||||
router_list = tgen.routers()
|
_lt = LTemplate(test, testdir)
|
||||||
|
_lt.setup_module(mod)
|
||||||
|
|
||||||
# For all registred routers, load the zebra configuration file
|
#drop testdir
|
||||||
for rname, router in router_list.iteritems():
|
#sys.path.remove(testdir)
|
||||||
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):
|
def teardown_module(mod):
|
||||||
"Teardown the pytest environment"
|
"Teardown the pytest environment"
|
||||||
@ -89,12 +128,6 @@ def teardown_module(mod):
|
|||||||
# This function tears down the whole topology.
|
# This function tears down the whole topology.
|
||||||
tgen.stop_topology()
|
tgen.stop_topology()
|
||||||
|
|
||||||
class LTemplate:
|
|
||||||
scriptdir = None
|
|
||||||
|
|
||||||
#init class
|
|
||||||
_lt = LTemplate()
|
|
||||||
|
|
||||||
def ltemplate_start(testDir):
|
def ltemplate_start(testDir):
|
||||||
logger.info('ltemplate start in ' + testDir)
|
logger.info('ltemplate start in ' + testDir)
|
||||||
test = os.path.basename(testDir)
|
test = os.path.basename(testDir)
|
||||||
@ -143,9 +176,12 @@ def test_memory_leak():
|
|||||||
#clean up ltemplate
|
#clean up ltemplate
|
||||||
|
|
||||||
def test_ltemplate_finish():
|
def test_ltemplate_finish():
|
||||||
|
global _lt
|
||||||
logger.info('Done with ltemplate tests')
|
logger.info('Done with ltemplate tests')
|
||||||
if _lt.scriptdir != None:
|
if _lt != None and _lt.scriptdir != None:
|
||||||
print(luFinish())
|
print(luFinish())
|
||||||
|
#done
|
||||||
|
_lt = None
|
||||||
|
|
||||||
#for testing
|
#for testing
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -221,12 +221,15 @@ Total %-4d %-4d %d\n\
|
|||||||
found = self.command(target, command, regexp, 'pass', '%s +%4.2f secs' % (result, delta))
|
found = self.command(target, command, regexp, 'pass', '%s +%4.2f secs' % (result, delta))
|
||||||
return found
|
return found
|
||||||
|
|
||||||
#init class
|
#initialized by luStart
|
||||||
LUtil=lUtil()
|
LUtil=None
|
||||||
|
|
||||||
#entry calls
|
#entry calls
|
||||||
def luStart(baseScriptDir='.', baseLogDir='.', net='',
|
def luStart(baseScriptDir='.', baseLogDir='.', net='',
|
||||||
fout='output.log', fsum='summary.txt', level=9):
|
fout='output.log', fsum='summary.txt', level=9):
|
||||||
|
global LUtil
|
||||||
|
#init class
|
||||||
|
LUtil=lUtil()
|
||||||
LUtil.base_script_dir = baseScriptDir
|
LUtil.base_script_dir = baseScriptDir
|
||||||
LUtil.base_log_dir = baseLogDir
|
LUtil.base_log_dir = baseLogDir
|
||||||
LUtil.net = net
|
LUtil.net = net
|
||||||
@ -242,23 +245,27 @@ def luCommand(target, command, regexp='.', op='none', result='', time=10):
|
|||||||
else:
|
else:
|
||||||
return LUtil.wait(target, command, regexp, op, result, time)
|
return LUtil.wait(target, command, regexp, op, result, time)
|
||||||
|
|
||||||
|
|
||||||
def luInclude(filename, CallOnFail=None):
|
def luInclude(filename, CallOnFail=None):
|
||||||
global LUtil
|
|
||||||
tstFile = LUtil.base_script_dir + '/' + filename
|
tstFile = LUtil.base_script_dir + '/' + filename
|
||||||
LUtil.setFilename(filename)
|
LUtil.setFilename(filename)
|
||||||
if CallOnFail != None:
|
if CallOnFail != None:
|
||||||
oldCallOnFail = LUtil.getCallOnFail()
|
oldCallOnFail = LUtil.getCallOnFail()
|
||||||
LUtil.setCallOnFail(CallOnFail)
|
LUtil.setCallOnFail(CallOnFail)
|
||||||
if filename.endswith('.py'):
|
if filename.endswith('.py'):
|
||||||
|
LUtil.log("luInclude: execfile "+tstFile)
|
||||||
execfile(tstFile)
|
execfile(tstFile)
|
||||||
else:
|
else:
|
||||||
|
LUtil.log("luInclude: execTestFile "+tstFile)
|
||||||
LUtil.execTestFile(tstFile)
|
LUtil.execTestFile(tstFile)
|
||||||
if CallOnFail != None:
|
if CallOnFail != None:
|
||||||
LUtil.setCallOnFail(oldCallOnFail)
|
LUtil.setCallOnFail(oldCallOnFail)
|
||||||
|
|
||||||
def luFinish():
|
def luFinish():
|
||||||
return LUtil.closeFiles()
|
global LUtil
|
||||||
|
ret = LUtil.closeFiles()
|
||||||
|
#done
|
||||||
|
LUtil = None
|
||||||
|
return ret;
|
||||||
|
|
||||||
def luNumFail():
|
def luNumFail():
|
||||||
return LUtil.l_fail
|
return LUtil.l_fail
|
||||||
|
Loading…
Reference in New Issue
Block a user