From: Lou Berger Date: Tue, 13 Feb 2018 15:38:02 +0000 (-0500) Subject: bgp_l3vpn_to_bgp_vrf: use new ltemplate common functions X-Git-Tag: frr-7.1-dev~151^2~124 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=98a1523fc8e7ff591bf746037cf06754c7c705d2;p=mirror%2Ffrr.git bgp_l3vpn_to_bgp_vrf: use new ltemplate common functions Signed-off-by: Lou Berger --- diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py index 99bc6e1732..3f7c549598 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py @@ -75,7 +75,6 @@ r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0 import os import re -import sys import pytest import platform @@ -84,6 +83,7 @@ import platform from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger +from lib.ltemplate import ltemplateRtrCmd # Required to instantiate the topology builder class. from mininet.topo import Topo @@ -93,9 +93,6 @@ CWD = os.path.dirname(os.path.realpath(__file__)) # test name based on directory TEST = os.path.basename(CWD) -InitSuccess = False -iproute2Ver = None - class ThisTestTopo(Topo): "Test topology builder" def build(self, *_args, **_opts): @@ -144,64 +141,19 @@ class ThisTestTopo(Topo): switch[1].add_link(tgen.gears['r2'], nodeif='r2-eth2') switch[1].add_link(tgen.gears['r3'], nodeif='r3-eth1') -class CustCmd(): - 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 - -cc = CustCmd() - def ltemplatePreRouterStartHook(): + cc = ltemplateRtrCmd() krel = platform.release() tgen = get_topogen() logger.info('pre router-start hook, kernel=' + krel) #check for mpls if tgen.hasmpls != True: logger.info('MPLS not available, skipping setup') - return + return False #check for normal init if len(tgen.net) == 1: logger.info('Topology not configured, skipping setup') - return - #collect/log info on iproute2 - found = cc.doCmd(tgen, 'r2', 'apt-cache policy iproute2', 'Installed: ([\d\.]*)') - if found != None: - global iproute2Ver - iproute2Ver = found.group(1) - logger.info('Have iproute2 version=' + iproute2Ver) + return False #trace errors/unexpected output cc.resetCounts() #configure r2 mpls interfaces @@ -238,53 +190,14 @@ def ltemplatePreRouterStartHook(): for intf in intfs: cc.doCmd(tgen, rtr, 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf)) logger.info('setup {0} vrf {0}-cust2, {0}-eth5. enabled mpls input.'.format(rtr)) - global InitSuccess if cc.getOutput(): InitSuccess = False logger.info('VRF config failed ({}), tests will be skipped'.format(cc.getOutput())) else: InitSuccess = True logger.info('VRF config successful!') - return; + return InitSuccess def ltemplatePostRouterStartHook(): logger.info('post router-start hook') - return; - -def versionCheck(vstr, rname='r1', compstr='<',cli=False, kernel='4.9', iproute2=None): - tgen = get_topogen() - router = tgen.gears[rname] - - if cli: - logger.info('calling mininet CLI') - tgen.mininet_cli() - logger.info('exited mininet CLI') - - if InitSuccess != True: - ret = 'Test not initialized' - return ret - - if 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 iproute2Ver == None or 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 + return True diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/test_bgp_l3vpn_to_bgp_vrf.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/test_bgp_l3vpn_to_bgp_vrf.py index 57313acb8a..5047ac725e 100755 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/test_bgp_l3vpn_to_bgp_vrf.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/test_bgp_l3vpn_to_bgp_vrf.py @@ -33,36 +33,36 @@ def test_check_linux_vrf(): CliOnFail = None # For debugging, uncomment the next line #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'customize.versionCheck(\'3.1\', iproute2=\'4.9\')' + CheckFunc = 'ltemplateVersionCheck(\'3.1\', iproute2=\'4.9\')' #uncomment next line to start cli *before* script is run - #CheckFunc = 'customize.versionCheck(\'3.1\', cli=True, iproute2=\'4.9\')' + #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True, iproute2=\'4.9\')' ltemplateTest('scripts/check_linux_vrf.py', False, CliOnFail, CheckFunc) def test_adjacencies(): CliOnFail = None # For debugging, uncomment the next line #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'customize.versionCheck(\'3.1\')' + CheckFunc = 'ltemplateVersionCheck(\'3.1\')' #uncomment next line to start cli *before* script is run - #CheckFunc = 'customize.versionCheck(\'3.1\', cli=True)' + #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' ltemplateTest('scripts/adjacencies.py', False, CliOnFail, CheckFunc) def SKIP_test_add_routes(): CliOnFail = None # For debugging, uncomment the next line #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'customize.versionCheck(\'3.1\')' + CheckFunc = 'ltemplateVersionCheck(\'3.1\')' #uncomment next line to start cli *before* script is run - #CheckFunc = 'customize.versionCheck(\'3.1\', cli=True)' + #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' ltemplateTest('scripts/add_routes.py', False, CliOnFail, CheckFunc) def test_check_routes(): CliOnFail = None # For debugging, uncomment the next line #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'customize.versionCheck(\'3.1\')' + CheckFunc = 'ltemplateVersionCheck(\'3.1\')' #uncomment next line to start cli *before* script is run - #CheckFunc = 'customize.versionCheck(\'3.1\', cli=True)' + #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' ltemplateTest('scripts/check_routes.py', False, CliOnFail, CheckFunc) #manual data path setup test - remove once have bgp/zebra vrf path working @@ -70,18 +70,18 @@ def test_check_linux_mpls(): CliOnFail = None # For debugging, uncomment the next line #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'customize.versionCheck(\'3.1\', iproute2=\'4.9\')' + CheckFunc = 'ltemplateVersionCheck(\'3.1\', iproute2=\'4.9\')' #uncomment next line to start cli *before* script is run - #CheckFunc = 'customize.versionCheck(\'3.1\', cli=True, iproute2=\'4.9\')' + #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True, iproute2=\'4.9\')' ltemplateTest('scripts/check_linux_mpls.py', False, CliOnFail, CheckFunc) def SKIP_test_cleanup_all(): CliOnFail = None # For debugging, uncomment the next line #CliOnFail = 'tgen.mininet_cli' - CheckFunc = 'customize.versionCheck(\'3.1\')' + CheckFunc = 'ltemplateVersionCheck(\'3.1\')' #uncomment next line to start cli *before* script is run - #CheckFunc = 'customize.versionCheck(\'3.1\', cli=True)' + #CheckFunc = 'ltemplateVersionCheck(\'3.1\', cli=True)' ltemplateTest('scripts/cleanup_all.py', False, CliOnFail, CheckFunc) if __name__ == '__main__':