mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-12 16:00:25 +00:00
Merge pull request #7019 from mjstapp/fix_topo_stringio
tests: small topotest improvements for python3
This commit is contained in:
commit
c90242e8c8
@ -30,14 +30,19 @@ from functools import wraps
|
|||||||
from re import search as re_search
|
from re import search as re_search
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
|
|
||||||
import StringIO
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import ConfigParser
|
|
||||||
import traceback
|
import traceback
|
||||||
import socket
|
import socket
|
||||||
import ipaddress
|
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.topolog import logger, logger_config
|
||||||
from lib.topogen import TopoRouter, get_topogen
|
from lib.topogen import TopoRouter, get_topogen
|
||||||
from lib.topotest import interface_set_status
|
from lib.topotest import interface_set_status
|
||||||
@ -61,7 +66,7 @@ TMPDIR = None
|
|||||||
|
|
||||||
# NOTE: to save execution logs to log file frrtest_log_dir must be configured
|
# NOTE: to save execution logs to log file frrtest_log_dir must be configured
|
||||||
# in `pytest.ini`.
|
# in `pytest.ini`.
|
||||||
config = ConfigParser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(PYTESTINI_PATH)
|
config.read(PYTESTINI_PATH)
|
||||||
|
|
||||||
config_section = "topogen"
|
config_section = "topogen"
|
||||||
@ -393,6 +398,14 @@ def check_router_status(tgen):
|
|||||||
logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
|
logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
|
||||||
return True
|
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):
|
def reset_config_on_routers(tgen, routerName=None):
|
||||||
"""
|
"""
|
||||||
@ -465,7 +478,7 @@ def reset_config_on_routers(tgen, routerName=None):
|
|||||||
raise InvalidCLIError("Unknown error in %s", output)
|
raise InvalidCLIError("Unknown error in %s", output)
|
||||||
|
|
||||||
f = open(dname, "r")
|
f = open(dname, "r")
|
||||||
delta = StringIO.StringIO()
|
delta = getStrIO()
|
||||||
delta.write("configure terminal\n")
|
delta.write("configure terminal\n")
|
||||||
t_delta = f.read()
|
t_delta = f.read()
|
||||||
|
|
||||||
@ -499,7 +512,7 @@ def reset_config_on_routers(tgen, routerName=None):
|
|||||||
output = router.vtysh_multicmd(delta.getvalue(), pretty_output=False)
|
output = router.vtysh_multicmd(delta.getvalue(), pretty_output=False)
|
||||||
|
|
||||||
delta.close()
|
delta.close()
|
||||||
delta = StringIO.StringIO()
|
delta = getStrIO()
|
||||||
cfg = router.run("vtysh -c 'show running'")
|
cfg = router.run("vtysh -c 'show running'")
|
||||||
for line in cfg.split("\n"):
|
for line in cfg.split("\n"):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
@ -713,8 +726,8 @@ def start_topology(tgen):
|
|||||||
os.chdir("{}/{}".format(TMPDIR, rname))
|
os.chdir("{}/{}".format(TMPDIR, rname))
|
||||||
os.system("touch zebra.conf bgpd.conf")
|
os.system("touch zebra.conf bgpd.conf")
|
||||||
|
|
||||||
except IOError as (errno, strerror):
|
except IOError as err:
|
||||||
logger.error("I/O error({0}): {1}".format(errno, strerror))
|
logger.error("I/O error({0}): {1}".format(err.errno, err.strerror))
|
||||||
|
|
||||||
# Loading empty zebra.conf file to router, to start the zebra deamon
|
# Loading empty zebra.conf file to router, to start the zebra deamon
|
||||||
router.load_config(
|
router.load_config(
|
||||||
@ -2191,7 +2204,7 @@ def addKernelRoute(
|
|||||||
if mask == "32" or mask == "128":
|
if mask == "32" or mask == "128":
|
||||||
grp_addr = ip
|
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 = (
|
errormsg = (
|
||||||
"[DUT: {}]: Kernal route is not added for group"
|
"[DUT: {}]: Kernal route is not added for group"
|
||||||
" address {} Config output: {}".format(router, grp_addr, output)
|
" address {} Config output: {}".format(router, grp_addr, output)
|
||||||
|
@ -29,7 +29,6 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
import functools
|
import functools
|
||||||
import glob
|
import glob
|
||||||
import StringIO
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
import platform
|
import platform
|
||||||
@ -1013,12 +1012,9 @@ class Router(Node):
|
|||||||
self.cmd("chown {0}:{0}vty /etc/{0}".format(self.routertype))
|
self.cmd("chown {0}:{0}vty /etc/{0}".format(self.routertype))
|
||||||
|
|
||||||
def terminate(self):
|
def terminate(self):
|
||||||
# Delete Running Quagga or FRR Daemons
|
# Stop running FRR daemons
|
||||||
self.stopRouter()
|
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
|
# Disable forwarding
|
||||||
set_sysctl(self, "net.ipv4.ip_forward", 0)
|
set_sysctl(self, "net.ipv4.ip_forward", 0)
|
||||||
set_sysctl(self, "net.ipv6.conf.all.forwarding", 0)
|
set_sysctl(self, "net.ipv6.conf.all.forwarding", 0)
|
||||||
@ -1033,10 +1029,12 @@ class Router(Node):
|
|||||||
if re.search(r"No such file or directory", rundaemons):
|
if re.search(r"No such file or directory", rundaemons):
|
||||||
return 0
|
return 0
|
||||||
if rundaemons is not None:
|
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()
|
daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip()
|
||||||
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
|
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
|
||||||
ret.append(os.path.basename(d.rstrip().rsplit(".", 1)[0]))
|
ret.append(os.path.basename(d.rstrip().rsplit(".", 1)[0]))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def stopRouter(self, wait=True, assertOnError=True, minErrorVersion="5.1"):
|
def stopRouter(self, wait=True, assertOnError=True, minErrorVersion="5.1"):
|
||||||
@ -1046,7 +1044,9 @@ class Router(Node):
|
|||||||
if re.search(r"No such file or directory", rundaemons):
|
if re.search(r"No such file or directory", rundaemons):
|
||||||
return errors
|
return errors
|
||||||
if rundaemons is not None:
|
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()
|
daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip()
|
||||||
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
|
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
|
||||||
daemonname = os.path.basename(d.rstrip().rsplit(".", 1)[0])
|
daemonname = os.path.basename(d.rstrip().rsplit(".", 1)[0])
|
||||||
@ -1080,7 +1080,9 @@ class Router(Node):
|
|||||||
|
|
||||||
if running:
|
if running:
|
||||||
# 2nd round of kill if daemons didn't exit
|
# 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()
|
daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip()
|
||||||
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
|
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
|
||||||
logger.info(
|
logger.info(
|
||||||
@ -1330,7 +1332,9 @@ class Router(Node):
|
|||||||
for daemon in daemons:
|
for daemon in daemons:
|
||||||
if rundaemons is not None and daemon in rundaemons:
|
if rundaemons is not None and daemon in rundaemons:
|
||||||
numRunning = 0
|
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):
|
if re.search(r"%s" % daemon, d):
|
||||||
daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip()
|
daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip()
|
||||||
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
|
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
|
||||||
@ -1351,8 +1355,9 @@ class Router(Node):
|
|||||||
self.name, daemon
|
self.name, daemon
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
# 2nd round of kill if daemons didn't exit
|
# 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):
|
if re.search(r"%s" % daemon, d):
|
||||||
daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip()
|
daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip()
|
||||||
if daemonpid.isdigit() and pid_exists(
|
if daemonpid.isdigit() and pid_exists(
|
||||||
|
Loading…
Reference in New Issue
Block a user