from re import search as re_search
from tempfile import mkdtemp
-import StringIO
import os
import sys
-import ConfigParser
import traceback
import socket
import ipaddress
+if sys.version_info[0] > 2:
+ import io
+ import configparser
+else:
+ import StringIO
+ import ConfigParser as configparser
+
from lib.topolog import logger, logger_config
from lib.topogen import TopoRouter, get_topogen
from lib.topotest import interface_set_status
# NOTE: to save execution logs to log file frrtest_log_dir must be configured
# in `pytest.ini`.
-config = ConfigParser.ConfigParser()
+config = configparser.ConfigParser()
config.read(PYTESTINI_PATH)
config_section = "topogen"
logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
return True
+def getStrIO():
+ """
+ Return a StringIO object appropriate for the current python version.
+ """
+ if sys.version_info[0] > 2:
+ return io.StringIO()
+ else:
+ return StringIO.StringIO()
def reset_config_on_routers(tgen, routerName=None):
"""
raise InvalidCLIError("Unknown error in %s", output)
f = open(dname, "r")
- delta = StringIO.StringIO()
+ delta = getStrIO()
delta.write("configure terminal\n")
t_delta = f.read()
output = router.vtysh_multicmd(delta.getvalue(), pretty_output=False)
delta.close()
- delta = StringIO.StringIO()
+ delta = getStrIO()
cfg = router.run("vtysh -c 'show running'")
for line in cfg.split("\n"):
line = line.strip()
os.chdir("{}/{}".format(TMPDIR, rname))
os.system("touch zebra.conf bgpd.conf")
- except IOError as (errno, strerror):
- logger.error("I/O error({0}): {1}".format(errno, strerror))
+ except IOError as err:
+ logger.error("I/O error({0}): {1}".format(err.errno, err.strerror))
# Loading empty zebra.conf file to router, to start the zebra deamon
router.load_config(
if mask == "32" or mask == "128":
grp_addr = ip
- if not re_search(r"{}".format(grp_addr), result) and mask is not "0":
+ if not re_search(r"{}".format(grp_addr), result) and mask != "0":
errormsg = (
"[DUT: {}]: Kernal route is not added for group"
" address {} Config output: {}".format(router, grp_addr, output)
import sys
import functools
import glob
-import StringIO
import subprocess
import tempfile
import platform
self.cmd("chown {0}:{0}vty /etc/{0}".format(self.routertype))
def terminate(self):
- # Delete Running Quagga or FRR Daemons
+ # Stop running FRR daemons
self.stopRouter()
- # rundaemons = self.cmd('ls -1 /var/run/%s/*.pid' % self.routertype)
- # for d in StringIO.StringIO(rundaemons):
- # self.cmd('kill -7 `cat %s`' % d.rstrip())
- # self.waitOutput()
+
# Disable forwarding
set_sysctl(self, "net.ipv4.ip_forward", 0)
set_sysctl(self, "net.ipv6.conf.all.forwarding", 0)
if re.search(r"No such file or directory", rundaemons):
return 0
if rundaemons is not None:
- for d in StringIO.StringIO(rundaemons):
+ bet = rundaemons.split('\n')
+ for d in bet[:-1]:
daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip()
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
ret.append(os.path.basename(d.rstrip().rsplit(".", 1)[0]))
+
return ret
def stopRouter(self, wait=True, assertOnError=True, minErrorVersion="5.1"):
if re.search(r"No such file or directory", rundaemons):
return errors
if rundaemons is not None:
- for d in StringIO.StringIO(rundaemons):
+ dmns = rundaemons.split('\n')
+ # Exclude empty string at end of list
+ for d in dmns[:-1]:
daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip()
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
daemonname = os.path.basename(d.rstrip().rsplit(".", 1)[0])
if running:
# 2nd round of kill if daemons didn't exit
- for d in StringIO.StringIO(rundaemons):
+ dmns = rundaemons.split('\n')
+ # Exclude empty string at end of list
+ for d in dmns[:-1]:
daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip()
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
logger.info(
for daemon in daemons:
if rundaemons is not None and daemon in rundaemons:
numRunning = 0
- for d in StringIO.StringIO(rundaemons):
+ dmns = rundaemons.split('\n')
+ # Exclude empty string at end of list
+ for d in dmns[:-1]:
if re.search(r"%s" % daemon, d):
daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip()
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
self.name, daemon
),
)
+
# 2nd round of kill if daemons didn't exit
- for d in StringIO.StringIO(rundaemons):
+ for d in dmns[:-1]:
if re.search(r"%s" % daemon, d):
daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip()
if daemonpid.isdigit() and pid_exists(