# test name based on directory
TEST = os.path.basename(CWD)
+InitSuccess = False
+
class ThisTestTopo(Topo):
"Test topology builder"
def build(self, *_args, **_opts):
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()
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']
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']
'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():
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):