diff options
Diffstat (limited to 'tests/topotests/lib/topogen.py')
| -rw-r--r-- | tests/topotests/lib/topogen.py | 71 |
1 files changed, 42 insertions, 29 deletions
diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 41da660b7d..2d6138990e 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -25,6 +25,7 @@ Basic usage instructions: * After running stop Mininet with: tgen.stop_topology() """ +import configparser import grp import inspect import json @@ -33,20 +34,16 @@ import os import platform import pwd import re +import shlex import subprocess import sys from collections import OrderedDict -if sys.version_info[0] > 2: - import configparser -else: - import ConfigParser as configparser - import lib.topolog as topolog from lib.micronet import Commander from lib.micronet_compat import Mininet from lib.topolog import logger -from lib.topotest import g_extra_config +from munet.testing.util import pause_test from lib import topotest @@ -192,7 +189,7 @@ class Topogen(object): self._load_config() # Create new log directory - self.logdir = topotest.get_logs_path(g_extra_config["rundir"]) + self.logdir = topotest.get_logs_path(topotest.g_pytest_config.option.rundir) subprocess.check_call( "mkdir -p {0} && chmod 1777 {0}".format(self.logdir), shell=True ) @@ -212,7 +209,10 @@ class Topogen(object): # Mininet(Micronet) to build the actual topology. assert not inspect.isclass(topodef) - self.net = Mininet(controller=None) + self.net = Mininet(rundir=self.logdir, pytestconfig=topotest.g_pytest_config) + + # Adjust the parent namespace + topotest.fix_netns_limits(self.net) # New direct way: Either a dictionary defines the topology or a build function # is supplied, or a json filename all of which build the topology by calling @@ -236,7 +236,6 @@ class Topogen(object): self.add_topology_from_dict(topodef) def add_topology_from_dict(self, topodef): - keylist = ( topodef.keys() if isinstance(topodef, OrderedDict) @@ -451,7 +450,18 @@ class Topogen(object): first is a simple kill with no sleep, the second will sleep if not killed and try with a different signal. """ + pause = bool(self.net.cfgopt.get_option("--pause-at-end")) + pause = pause or bool(self.net.cfgopt.get_option("--pause")) + if pause: + try: + pause_test("Before MUNET delete") + except KeyboardInterrupt: + print("^C...continuing") + except Exception as error: + self.logger.error("\n...continuing after error: %s", error) + logger.info("stopping topology: {}".format(self.modname)) + errors = "" for gear in self.gears.values(): errors += gear.stop() @@ -504,7 +514,7 @@ class Topogen(object): def set_error(self, message, code=None): "Sets an error message and signal other tests to skip." - logger.info(message) + logger.info("setting error msg: %s", message) # If no code is defined use a sequential number if code is None: @@ -749,8 +759,8 @@ class TopoRouter(TopoGear): """ super(TopoRouter, self).__init__(tgen, name, **params) self.routertype = params.get("routertype", "frr") - if "privateDirs" not in params: - params["privateDirs"] = self.PRIVATE_DIRS + if "private_mounts" not in params: + params["private_mounts"] = self.PRIVATE_DIRS # Propagate the router log directory logfile = self._setup_tmpdir() @@ -799,7 +809,7 @@ class TopoRouter(TopoGear): grep_cmd = "grep 'ip {}' {}".format(daemonstr, source) else: grep_cmd = "grep 'router {}' {}".format(daemonstr, source) - result = self.run(grep_cmd).strip() + result = self.run(grep_cmd, warn=False).strip() if result: self.load_config(daemon) else: @@ -822,7 +832,7 @@ class TopoRouter(TopoGear): all routers. """ daemonstr = self.RD.get(daemon) - self.logger.info('loading "{}" configuration: {}'.format(daemonstr, source)) + self.logger.debug('loading "{}" configuration: {}'.format(daemonstr, source)) self.net.loadConf(daemonstr, source, param) def check_router_running(self): @@ -858,7 +868,7 @@ class TopoRouter(TopoGear): "conf t", "log file {}.log debug".format(daemon), "log commands", - "log timestamp precision 3", + "log timestamp precision 6", ] ), daemon=daemon, @@ -908,7 +918,7 @@ class TopoRouter(TopoGear): "conf t", "log file {}.log debug".format(daemon), "log commands", - "log timestamp precision 3", + "log timestamp precision 6", ] ), daemon=daemon, @@ -943,18 +953,20 @@ class TopoRouter(TopoGear): if daemon is not None: dparam += "-d {}".format(daemon) - vtysh_command = 'vtysh {} -c "{}" 2>/dev/null'.format(dparam, command) + vtysh_command = "vtysh {} -c {} 2>/dev/null".format( + dparam, shlex.quote(command) + ) - self.logger.info('vtysh command => "{}"'.format(command)) + self.logger.debug("vtysh command => {}".format(shlex.quote(command))) output = self.run(vtysh_command) dbgout = output.strip() if dbgout: if "\n" in dbgout: dbgout = dbgout.replace("\n", "\n\t") - self.logger.info("vtysh result:\n\t{}".format(dbgout)) + self.logger.debug("vtysh result:\n\t{}".format(dbgout)) else: - self.logger.info('vtysh result: "{}"'.format(dbgout)) + self.logger.debug('vtysh result: "{}"'.format(dbgout)) if isjson is False: return output @@ -994,7 +1006,7 @@ class TopoRouter(TopoGear): dbgcmds = commands if is_string(commands) else "\n".join(commands) dbgcmds = "\t" + dbgcmds.replace("\n", "\n\t") - self.logger.info("vtysh command => FILE:\n{}".format(dbgcmds)) + self.logger.debug("vtysh command => FILE:\n{}".format(dbgcmds)) res = self.run(vtysh_command) os.unlink(fname) @@ -1003,9 +1015,9 @@ class TopoRouter(TopoGear): if dbgres: if "\n" in dbgres: dbgres = dbgres.replace("\n", "\n\t") - self.logger.info("vtysh result:\n\t{}".format(dbgres)) + self.logger.debug("vtysh result:\n\t{}".format(dbgres)) else: - self.logger.info('vtysh result: "{}"'.format(dbgres)) + self.logger.debug('vtysh result: "{}"'.format(dbgres)) return res def report_memory_leaks(self, testname): @@ -1097,7 +1109,7 @@ class TopoHost(TopoGear): * `ip`: the IP address (string) for the host interface * `defaultRoute`: the default route that will be installed (e.g. 'via 10.0.0.1') - * `privateDirs`: directories that will be mounted on a different domain + * `private_mounts`: directories that will be mounted on a different domain (e.g. '/etc/important_dir'). """ super(TopoHost, self).__init__(tgen, name, **params) @@ -1117,10 +1129,10 @@ class TopoHost(TopoGear): def __str__(self): gear = super(TopoHost, self).__str__() - gear += ' TopoHost<ip="{}",defaultRoute="{}",privateDirs="{}">'.format( + gear += ' TopoHost<ip="{}",defaultRoute="{}",private_mounts="{}">'.format( self.params["ip"], self.params["defaultRoute"], - str(self.params["privateDirs"]), + str(self.params["private_mounts"]), ) return gear @@ -1143,10 +1155,10 @@ class TopoExaBGP(TopoHost): (e.g. 'via 10.0.0.1') Note: the different between a host and a ExaBGP peer is that this class - has a privateDirs already defined and contains functions to handle ExaBGP - things. + has a private_mounts already defined and contains functions to handle + ExaBGP things. """ - params["privateDirs"] = self.PRIVATE_DIRS + params["private_mounts"] = self.PRIVATE_DIRS super(TopoExaBGP, self).__init__(tgen, name, **params) def __str__(self): @@ -1191,6 +1203,7 @@ class TopoExaBGP(TopoHost): # Diagnostic function # + # Disable linter branch warning. It is expected to have these here. # pylint: disable=R0912 def diagnose_env_linux(rundir): |
