From: Lou Berger Date: Wed, 7 Feb 2018 16:58:09 +0000 (-0500) Subject: bgp_l3vpn_to_bgp_vrf: catch linux setup failures X-Git-Tag: frr-7.1-dev~151^2~134 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=f2f902aca87c853de2625b3e6ddb80e8b1c66ec6;p=matthieu%2Ffrr.git bgp_l3vpn_to_bgp_vrf: catch linux setup failures 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 6a5af3d3f3..beb9bffcc5 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py @@ -93,6 +93,8 @@ CWD = os.path.dirname(os.path.realpath(__file__)) # test name based on directory TEST = os.path.basename(CWD) +InitSuccess = False + class ThisTestTopo(Topo): "Test topology builder" def build(self, *_args, **_opts): @@ -136,13 +138,45 @@ class ThisTestTopo(Topo): switch[1].add_link(tgen.gears['r2'], nodeif='r2-eth2') switch[1].add_link(tgen.gears['r3'], nodeif='r3-eth1') -def doCmd(tgen, rtr, cmd, checkstr = None): - output = tgen.net[rtr].cmd(cmd).strip() - if len(output): - if checkstr != None: - return re.search(checkstr, output) - logger.info('command output: ' + output) - return None +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(): krel = platform.release() @@ -152,14 +186,16 @@ def ltemplatePreRouterStartHook(): if tgen.hasmpls != True: logger.info('MPLS not available, skipping setup') return + #collect/log info on iproute2 + cc.doCmd(tgen, 'r2', 'apt-cache policy iproute2') + cc.doCmd(tgen, 'r2', 'yum info iproute2') + cc.doCmd(tgen, 'r2', 'yum info iproute') + + cc.resetCounts() #configure r2 mpls interfaces intfs = ['lo', 'r2-eth0', 'r2-eth1', 'r2-eth2'] for intf in intfs: - doCmd(tgen, 'r2', 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf)) - #collect/log info on iproute2 - doCmd(tgen, 'r2', 'apt-cache policy iproute2') - doCmd(tgen, 'r2', 'yum info iproute2') - doCmd(tgen, 'r2', 'yum info iproute') + cc.doCmd(tgen, 'r2', 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf)) #configure cust1 VRFs & MPLS rtrs = ['r1', 'r3', 'r4'] @@ -170,11 +206,11 @@ def ltemplatePreRouterStartHook(): for rtr in rtrs: router = tgen.gears[rtr] for cmd in cmds: - doCmd(tgen, rtr, cmd) - doCmd(tgen, rtr, 'ip link set dev {}-eth4 master cust1'.format(rtr)) + cc.doCmd(tgen, rtr, cmd) + cc.doCmd(tgen, rtr, 'ip link set dev {}-eth4 master cust1'.format(rtr)) intfs = ['cust1', 'lo', rtr+'-eth0', rtr+'-eth4'] for intf in intfs: - doCmd(tgen, rtr, 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf)) + cc.doCmd(tgen, rtr, 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf)) logger.info('setup {0} vrf cust1, {0}-eth4. enabled mpls input.'.format(rtr)) #configure cust2 VRFs & MPLS rtrs = ['r4'] @@ -184,12 +220,19 @@ def ltemplatePreRouterStartHook(): 'ip link set dev cust2 up'] for rtr in rtrs: for cmd in cmds: - doCmd(tgen, rtr, cmd) - doCmd(tgen, rtr, 'ip link set dev {}-eth5 master cust2'.format(rtr)) + cc.doCmd(tgen, rtr, cmd) + cc.doCmd(tgen, rtr, 'ip link set dev {}-eth5 master cust2'.format(rtr)) intfs = ['cust2', rtr+'-eth5'] for intf in intfs: - doCmd(tgen, rtr, 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf)) + cc.doCmd(tgen, rtr, 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf)) logger.info('setup {0} vrf 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; def ltemplatePostRouterStartHook(): @@ -205,6 +248,10 @@ def versionCheck(vstr, rname='r1', compstr='<',cli=False, kernel='4.9'): ret = 'MPLS not initialized' return ret + if InitSuccess != True: + ret = 'Test not successfully initialized' + return ret + ret = True try: if router.has_version(compstr, vstr):