2017-06-15 05:25:54 +02:00
|
|
|
"""
|
|
|
|
Topotest conftest.py file.
|
|
|
|
"""
|
|
|
|
|
2021-06-12 11:07:24 +02:00
|
|
|
import glob
|
2021-03-04 03:56:46 +01:00
|
|
|
import os
|
|
|
|
import pdb
|
2021-06-12 11:07:24 +02:00
|
|
|
import re
|
2021-07-27 01:23:20 +02:00
|
|
|
import sys
|
|
|
|
import time
|
2021-03-04 03:56:46 +01:00
|
|
|
|
2021-07-27 01:23:20 +02:00
|
|
|
import pytest
|
|
|
|
import lib.fixtures
|
|
|
|
from lib import topolog
|
|
|
|
from lib.micronet import Commander
|
|
|
|
from lib.micronet_cli import cli
|
|
|
|
from lib.micronet_compat import Mininet, cleanup_current, cleanup_previous
|
|
|
|
from lib.topogen import diagnose_env, get_topogen
|
2017-07-27 19:52:51 +02:00
|
|
|
from lib.topolog import logger
|
2021-07-27 01:23:20 +02:00
|
|
|
from lib.topotest import g_extra_config as topotest_extra_config
|
|
|
|
from lib.topotest import json_cmp_result
|
2020-04-03 13:05:24 +02:00
|
|
|
|
2021-06-12 11:07:24 +02:00
|
|
|
try:
|
|
|
|
from _pytest._code.code import ExceptionInfo
|
2021-07-27 01:23:20 +02:00
|
|
|
|
2021-06-12 11:07:24 +02:00
|
|
|
leak_check_ok = True
|
|
|
|
except ImportError:
|
|
|
|
leak_check_ok = False
|
|
|
|
|
2021-04-08 19:04:26 +02:00
|
|
|
|
2017-06-15 05:25:54 +02:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
"""
|
|
|
|
Add topology-only option to the topology tester. This option makes pytest
|
|
|
|
only run the setup_module() to setup the topology without running any tests.
|
|
|
|
"""
|
2021-07-09 11:22:51 +02:00
|
|
|
parser.addoption(
|
|
|
|
"--asan-abort",
|
|
|
|
action="store_true",
|
|
|
|
help="Configure address sanitizer to abort process on error",
|
|
|
|
)
|
|
|
|
|
2021-07-27 01:23:20 +02:00
|
|
|
parser.addoption(
|
|
|
|
"--cli-on-error",
|
|
|
|
action="store_true",
|
|
|
|
help="Mininet cli on test failure",
|
|
|
|
)
|
|
|
|
|
2021-03-04 03:56:46 +01:00
|
|
|
parser.addoption(
|
|
|
|
"--gdb-breakpoints",
|
|
|
|
metavar="SYMBOL[,SYMBOL...]",
|
|
|
|
help="Comma-separated list of functions to set gdb breakpoints on",
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.addoption(
|
|
|
|
"--gdb-daemons",
|
|
|
|
metavar="DAEMON[,DAEMON...]",
|
|
|
|
help="Comma-separated list of daemons to spawn gdb on, or 'all'",
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.addoption(
|
|
|
|
"--gdb-routers",
|
|
|
|
metavar="ROUTER[,ROUTER...]",
|
|
|
|
help="Comma-separated list of routers to spawn gdb on, or 'all'",
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.addoption(
|
2021-07-27 01:23:20 +02:00
|
|
|
"--pause",
|
2021-03-04 03:56:46 +01:00
|
|
|
action="store_true",
|
2021-07-27 01:23:20 +02:00
|
|
|
help="Pause after each test",
|
2021-03-04 03:56:46 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
parser.addoption(
|
2021-07-27 01:23:20 +02:00
|
|
|
"--pause-on-error",
|
2021-03-04 03:56:46 +01:00
|
|
|
action="store_true",
|
2021-07-27 01:23:20 +02:00
|
|
|
help="Do not pause after (disables default when --shell or -vtysh given)",
|
2021-03-04 03:56:46 +01:00
|
|
|
)
|
|
|
|
|
2021-07-27 01:23:20 +02:00
|
|
|
parser.addoption(
|
|
|
|
"--no-pause-on-error",
|
|
|
|
dest="pause_on_error",
|
|
|
|
action="store_false",
|
|
|
|
help="Do not pause after (disables default when --shell or -vtysh given)",
|
|
|
|
)
|
|
|
|
|
|
|
|
rundir_help="directory for running in and log files"
|
|
|
|
parser.addini("rundir", rundir_help, default="/tmp/topotests")
|
|
|
|
parser.addoption("--rundir", metavar="DIR", help=rundir_help)
|
|
|
|
|
2021-03-04 03:56:46 +01:00
|
|
|
parser.addoption(
|
|
|
|
"--shell",
|
|
|
|
metavar="ROUTER[,ROUTER...]",
|
|
|
|
help="Comma-separated list of routers to spawn shell on, or 'all'",
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.addoption(
|
|
|
|
"--shell-on-error",
|
|
|
|
action="store_true",
|
|
|
|
help="Spawn shell on all routers on test failure",
|
|
|
|
)
|
|
|
|
|
2021-07-09 11:22:51 +02:00
|
|
|
parser.addoption(
|
|
|
|
"--strace-daemons",
|
|
|
|
metavar="DAEMON[,DAEMON...]",
|
|
|
|
help="Comma-separated list of daemons to strace, or 'all'",
|
|
|
|
)
|
|
|
|
|
2017-06-15 05:25:54 +02:00
|
|
|
parser.addoption(
|
|
|
|
"--topology-only",
|
|
|
|
action="store_true",
|
2021-03-23 23:15:58 +01:00
|
|
|
default=False,
|
2017-06-15 05:25:54 +02:00
|
|
|
help="Only set up this topology, don't run tests",
|
|
|
|
)
|
2020-04-03 13:05:24 +02:00
|
|
|
|
2021-06-12 11:07:24 +02:00
|
|
|
parser.addoption(
|
|
|
|
"--valgrind-extra",
|
|
|
|
action="store_true",
|
|
|
|
help="Generate suppression file, and enable more precise (slower) valgrind checks",
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.addoption(
|
|
|
|
"--valgrind-memleaks",
|
|
|
|
action="store_true",
|
|
|
|
help="Run all daemons under valgrind for memleak detection",
|
|
|
|
)
|
|
|
|
|
2021-03-04 03:56:46 +01:00
|
|
|
parser.addoption(
|
|
|
|
"--vtysh",
|
|
|
|
metavar="ROUTER[,ROUTER...]",
|
|
|
|
help="Comma-separated list of routers to spawn vtysh on, or 'all'",
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.addoption(
|
|
|
|
"--vtysh-on-error",
|
|
|
|
action="store_true",
|
|
|
|
help="Spawn vtysh on all routers on test failure",
|
|
|
|
)
|
|
|
|
|
2017-06-15 05:25:54 +02:00
|
|
|
|
2021-06-12 11:07:24 +02:00
|
|
|
def check_for_memleaks():
|
|
|
|
if not topotest_extra_config["valgrind_memleaks"]:
|
|
|
|
return
|
|
|
|
|
|
|
|
leaks = []
|
|
|
|
tgen = get_topogen()
|
|
|
|
latest = []
|
|
|
|
existing = []
|
|
|
|
if tgen is not None:
|
2021-07-27 01:23:20 +02:00
|
|
|
logdir = tgen.logdir
|
2021-06-12 11:07:24 +02:00
|
|
|
if hasattr(tgen, "valgrind_existing_files"):
|
|
|
|
existing = tgen.valgrind_existing_files
|
|
|
|
latest = glob.glob(os.path.join(logdir, "*.valgrind.*"))
|
|
|
|
|
|
|
|
for vfile in latest:
|
|
|
|
if vfile in existing:
|
|
|
|
continue
|
|
|
|
with open(vfile) as vf:
|
|
|
|
vfcontent = vf.read()
|
|
|
|
match = re.search(r"ERROR SUMMARY: (\d+) errors", vfcontent)
|
|
|
|
if match and match.group(1) != "0":
|
2021-07-27 01:23:20 +02:00
|
|
|
emsg = "{} in {}".format(match.group(1), vfile)
|
2021-06-12 11:07:24 +02:00
|
|
|
leaks.append(emsg)
|
|
|
|
|
|
|
|
if leaks:
|
|
|
|
if leak_check_ok:
|
|
|
|
pytest.fail("Memleaks found:\n\t" + "\n\t".join(leaks))
|
|
|
|
else:
|
|
|
|
logger.error("Memleaks found:\n\t" + "\n\t".join(leaks))
|
|
|
|
|
|
|
|
|
2021-07-27 01:23:20 +02:00
|
|
|
def pytest_runtest_logstart(nodeid, location):
|
|
|
|
# location is (filename, lineno, testname)
|
|
|
|
topolog.logstart(nodeid, location, topotest_extra_config["rundir"])
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_runtest_logfinish(nodeid, location):
|
|
|
|
# location is (filename, lineno, testname)
|
|
|
|
topolog.logfinish(nodeid, location)
|
|
|
|
|
|
|
|
|
2017-06-15 05:25:54 +02:00
|
|
|
def pytest_runtest_call():
|
|
|
|
"""
|
|
|
|
This function must be run after setup_module(), it does standarized post
|
|
|
|
setup routines. It is only being used for the 'topology-only' option.
|
|
|
|
"""
|
2021-03-04 03:56:46 +01:00
|
|
|
if topotest_extra_config["topology_only"]:
|
2017-06-29 15:49:11 +02:00
|
|
|
tgen = get_topogen()
|
|
|
|
if tgen is not None:
|
|
|
|
# Allow user to play with the setup.
|
2021-07-27 01:23:20 +02:00
|
|
|
tgen.cli()
|
2017-06-29 15:49:11 +02:00
|
|
|
|
2017-06-15 05:25:54 +02:00
|
|
|
pytest.exit("the topology executed successfully")
|
2020-04-03 13:05:24 +02:00
|
|
|
|
2017-06-29 17:18:46 +02:00
|
|
|
|
|
|
|
def pytest_assertrepr_compare(op, left, right):
|
|
|
|
"""
|
|
|
|
Show proper assertion error message for json_cmp results.
|
|
|
|
"""
|
2021-03-04 03:56:46 +01:00
|
|
|
del op
|
|
|
|
|
2017-06-29 17:18:46 +02:00
|
|
|
json_result = left
|
|
|
|
if not isinstance(json_result, json_cmp_result):
|
|
|
|
json_result = right
|
|
|
|
if not isinstance(json_result, json_cmp_result):
|
|
|
|
return None
|
|
|
|
|
tests: introduce a proper JSON diff for topotests
Diff'ing JSON objects is a crucial operation in the topotests for
comparing e.g. vtysh output (formatted as JSON) with a file which
covers the expectation of the tests. The current diff functionality
is 'self-written' and intended to test a JSON object d2 on being a
subset of another JSON object d1. For mismatches a diff is generated
based on a normalized textual representation of the JSON objects.
This approach has several disadvantages:
* the human provided JSON text might not be normalized, hence
a diff with line numbers might be worthless since it provides
close to zero orientation what the problem is
* the diff contains changes like commatas which are meaningless
* the diff might contain a lot of changes about meaningless
content which is present in d1 but not in d2
* there is no proper functionality to test for 'equality' of
d1 and d2
* it is not possible to test for order, e.g. JSON arrays are
just tested with respect to being a subset of another array
* it is not possible to check if a key exists without also
checking the value of that particular key
This commit attempts to solve these issues. An error report is
generated which includes the "JSON Path" to the problematic JSON
elements and also hints on what the actual problem is (e.g. missing
key, mismatch in dict values etc.).
A special parameter 'exact' was introduced such that equality can be
tested. Also there was a convention that absence of keys can be
tested using the key in question with value 'None'. This convention
is still honored such that full backwards compatiiblity is in
place.
Further order can be tested using the new tag '__ordered__' in
lists (as first element). Example:
d1 = [1, 2, 3]
d2 = ['__ordered__', 1, 3, 2]
Tesing d1 and d2 this way will now result in an error.
Key existence can now be tested using an asterisk '*'. Example:
d1 = [1, 2, 3]
d2 = [1, '*', 3]
d1 = {'a': 1, 'b': 2}
d2 = {'a': '*'}
Both cases will result now in a clean diff for d1 and d2.
Signed-off-by: GalaxyGorilla <sascha@netdef.org>
2020-04-23 16:06:37 +02:00
|
|
|
return json_result.gen_report()
|
2017-07-18 21:44:27 +02:00
|
|
|
|
2020-04-03 13:05:24 +02:00
|
|
|
|
2017-07-18 21:44:27 +02:00
|
|
|
def pytest_configure(config):
|
2021-03-04 03:56:46 +01:00
|
|
|
"""
|
|
|
|
Assert that the environment is correctly configured, and get extra config.
|
|
|
|
"""
|
2019-05-02 20:43:18 +02:00
|
|
|
|
2021-07-27 01:23:20 +02:00
|
|
|
if "PYTEST_XDIST_WORKER" not in os.environ:
|
|
|
|
os.environ["PYTEST_XDIST_MODE"] = config.getoption("dist", "no")
|
|
|
|
os.environ["PYTEST_TOPOTEST_WORKER"] = ""
|
|
|
|
is_xdist = os.environ["PYTEST_XDIST_MODE"] != "no"
|
|
|
|
is_worker = False
|
|
|
|
else:
|
|
|
|
os.environ["PYTEST_TOPOTEST_WORKER"] = os.environ["PYTEST_XDIST_WORKER"]
|
|
|
|
is_xdist = True
|
|
|
|
is_worker = True
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------------------
|
|
|
|
# Set some defaults for the pytest.ini [pytest] section
|
|
|
|
# ---------------------------------------------------
|
|
|
|
|
|
|
|
rundir = config.getoption("--rundir")
|
|
|
|
if not rundir:
|
|
|
|
rundir = config.getini("rundir")
|
|
|
|
if not rundir:
|
|
|
|
rundir = "/tmp/topotests"
|
|
|
|
if not config.getoption("--junitxml"):
|
|
|
|
config.option.xmlpath = os.path.join(rundir, "topotests.xml")
|
|
|
|
xmlpath = config.option.xmlpath
|
|
|
|
|
|
|
|
# Save an existing topotest.xml
|
|
|
|
if os.path.exists(xmlpath):
|
|
|
|
fmtime = time.localtime(os.path.getmtime(xmlpath))
|
|
|
|
suffix = "-" + time.strftime("%Y%m%d%H%M%S", fmtime)
|
|
|
|
commander = Commander("pytest")
|
|
|
|
mv_path = commander.get_exec_path("mv")
|
|
|
|
commander.cmd_status([mv_path, xmlpath, xmlpath + suffix])
|
|
|
|
|
|
|
|
topotest_extra_config["rundir"] = rundir
|
|
|
|
|
|
|
|
# Set the log_file (exec) to inside the rundir if not specified
|
|
|
|
if not config.getoption("--log-file") and not config.getini("log_file"):
|
|
|
|
config.option.log_file = os.path.join(rundir, "exec.log")
|
|
|
|
|
|
|
|
# Turn on live logging if user specified verbose and the config has a CLI level set
|
|
|
|
if config.getoption("--verbose") and not is_xdist and not config.getini("log_cli"):
|
|
|
|
if config.getoption("--log-cli-level", None) is None:
|
|
|
|
# By setting the CLI option to the ini value it enables log_cli=1
|
|
|
|
cli_level = config.getini("log_cli_level")
|
|
|
|
if cli_level is not None:
|
|
|
|
config.option.log_cli_level = cli_level
|
|
|
|
# ---------------------------------------
|
|
|
|
# Record our options in global dictionary
|
|
|
|
# ---------------------------------------
|
|
|
|
|
|
|
|
topotest_extra_config["rundir"] = rundir
|
2021-03-04 03:56:46 +01:00
|
|
|
|
2021-07-09 11:22:51 +02:00
|
|
|
asan_abort = config.getoption("--asan-abort")
|
|
|
|
topotest_extra_config["asan_abort"] = asan_abort
|
|
|
|
|
2021-03-04 03:56:46 +01:00
|
|
|
gdb_routers = config.getoption("--gdb-routers")
|
|
|
|
gdb_routers = gdb_routers.split(",") if gdb_routers else []
|
|
|
|
topotest_extra_config["gdb_routers"] = gdb_routers
|
|
|
|
|
|
|
|
gdb_daemons = config.getoption("--gdb-daemons")
|
|
|
|
gdb_daemons = gdb_daemons.split(",") if gdb_daemons else []
|
|
|
|
topotest_extra_config["gdb_daemons"] = gdb_daemons
|
|
|
|
|
|
|
|
gdb_breakpoints = config.getoption("--gdb-breakpoints")
|
|
|
|
gdb_breakpoints = gdb_breakpoints.split(",") if gdb_breakpoints else []
|
|
|
|
topotest_extra_config["gdb_breakpoints"] = gdb_breakpoints
|
|
|
|
|
2021-07-27 01:23:20 +02:00
|
|
|
cli_on_error = config.getoption("--cli-on-error")
|
|
|
|
topotest_extra_config["cli_on_error"] = cli_on_error
|
2017-07-27 19:52:51 +02:00
|
|
|
|
2021-03-04 03:56:46 +01:00
|
|
|
shell = config.getoption("--shell")
|
|
|
|
topotest_extra_config["shell"] = shell.split(",") if shell else []
|
|
|
|
|
2021-07-09 11:22:51 +02:00
|
|
|
strace = config.getoption("--strace-daemons")
|
|
|
|
topotest_extra_config["strace_daemons"] = strace.split(",") if strace else []
|
|
|
|
|
2021-03-04 03:56:46 +01:00
|
|
|
shell_on_error = config.getoption("--shell-on-error")
|
|
|
|
topotest_extra_config["shell_on_error"] = shell_on_error
|
|
|
|
|
2021-06-12 11:07:24 +02:00
|
|
|
topotest_extra_config["valgrind_extra"] = config.getoption("--valgrind-extra")
|
|
|
|
topotest_extra_config["valgrind_memleaks"] = config.getoption("--valgrind-memleaks")
|
|
|
|
|
2021-03-04 03:56:46 +01:00
|
|
|
vtysh = config.getoption("--vtysh")
|
|
|
|
topotest_extra_config["vtysh"] = vtysh.split(",") if vtysh else []
|
|
|
|
|
|
|
|
vtysh_on_error = config.getoption("--vtysh-on-error")
|
|
|
|
topotest_extra_config["vtysh_on_error"] = vtysh_on_error
|
|
|
|
|
2021-07-27 01:23:20 +02:00
|
|
|
pause_on_error = vtysh or shell or config.getoption("--pause-on-error")
|
|
|
|
if config.getoption("--no-pause-on-error"):
|
|
|
|
pause_on_error = False
|
|
|
|
|
|
|
|
topotest_extra_config["pause_on_error"] = pause_on_error
|
|
|
|
topotest_extra_config["pause"] = config.getoption("--pause")
|
2021-03-04 03:56:46 +01:00
|
|
|
|
|
|
|
topotest_extra_config["topology_only"] = config.getoption("--topology-only")
|
2019-05-02 20:43:18 +02:00
|
|
|
|
2021-07-27 01:23:20 +02:00
|
|
|
# Check environment now that we have config
|
|
|
|
if not diagnose_env(rundir):
|
|
|
|
pytest.exit("environment has errors, please read the logs")
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True, scope="session")
|
|
|
|
def setup_session_auto():
|
|
|
|
if "PYTEST_TOPOTEST_WORKER" not in os.environ:
|
|
|
|
is_worker = False
|
|
|
|
elif not os.environ["PYTEST_TOPOTEST_WORKER"]:
|
|
|
|
is_worker = False
|
|
|
|
else:
|
|
|
|
is_worker = True
|
|
|
|
|
|
|
|
logger.debug("Before the run (is_worker: %s)", is_worker)
|
|
|
|
if not is_worker:
|
|
|
|
cleanup_previous()
|
|
|
|
yield
|
|
|
|
if not is_worker:
|
|
|
|
cleanup_current()
|
|
|
|
logger.debug("After the run (is_worker: %s)", is_worker)
|
|
|
|
|
2020-04-03 13:05:24 +02:00
|
|
|
|
2017-07-27 19:52:51 +02:00
|
|
|
def pytest_runtest_makereport(item, call):
|
|
|
|
"Log all assert messages to default logger with error level"
|
|
|
|
|
2021-03-04 03:56:46 +01:00
|
|
|
# Nothing happened
|
|
|
|
if call.when == "call":
|
2021-07-27 01:23:20 +02:00
|
|
|
pause = topotest_extra_config["pause"]
|
2021-03-04 03:56:46 +01:00
|
|
|
else:
|
|
|
|
pause = False
|
2017-07-28 02:44:51 +02:00
|
|
|
|
2021-06-12 11:07:24 +02:00
|
|
|
if call.excinfo is None and call.when == "call":
|
|
|
|
try:
|
|
|
|
check_for_memleaks()
|
|
|
|
except:
|
|
|
|
call.excinfo = ExceptionInfo()
|
|
|
|
|
2021-07-27 01:23:20 +02:00
|
|
|
title='unset'
|
|
|
|
|
2021-03-04 03:56:46 +01:00
|
|
|
if call.excinfo is None:
|
|
|
|
error = False
|
|
|
|
else:
|
|
|
|
parent = item.parent
|
|
|
|
modname = parent.module.__name__
|
|
|
|
|
|
|
|
# Treat skips as non errors, don't pause after
|
2021-06-30 17:43:42 +02:00
|
|
|
if call.excinfo.typename == "Skipped":
|
2021-03-04 03:56:46 +01:00
|
|
|
pause = False
|
|
|
|
error = False
|
|
|
|
logger.info(
|
2021-06-30 17:43:42 +02:00
|
|
|
'test skipped at "{}/{}": {}'.format(
|
2021-03-04 03:56:46 +01:00
|
|
|
modname, item.name, call.excinfo.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
error = True
|
|
|
|
# Handle assert failures
|
2021-04-08 19:04:26 +02:00
|
|
|
parent._previousfailed = item # pylint: disable=W0212
|
2021-03-04 03:56:46 +01:00
|
|
|
logger.error(
|
2021-06-30 17:43:42 +02:00
|
|
|
'test failed at "{}/{}": {}'.format(
|
2021-04-08 19:04:26 +02:00
|
|
|
modname, item.name, call.excinfo.value
|
|
|
|
)
|
2017-07-28 02:44:51 +02:00
|
|
|
)
|
2021-07-27 01:23:20 +02:00
|
|
|
title = "{}/{}".format(modname, item.name)
|
2019-10-01 02:15:15 +02:00
|
|
|
|
2021-07-09 11:22:51 +02:00
|
|
|
# We want to pause, if requested, on any error not just test cases
|
|
|
|
# (e.g., call.when == "setup")
|
|
|
|
if not pause:
|
2021-07-27 01:23:20 +02:00
|
|
|
pause = (
|
|
|
|
topotest_extra_config["pause_on_error"]
|
|
|
|
or topotest_extra_config["pause"]
|
|
|
|
)
|
2021-07-09 11:22:51 +02:00
|
|
|
|
2021-03-04 03:56:46 +01:00
|
|
|
# (topogen) Set topology error to avoid advancing in the test.
|
|
|
|
tgen = get_topogen()
|
|
|
|
if tgen is not None:
|
|
|
|
# This will cause topogen to report error on `routers_have_failure`.
|
|
|
|
tgen.set_error("{}/{}".format(modname, item.name))
|
|
|
|
|
2021-07-27 01:23:20 +02:00
|
|
|
commander = Commander("pytest")
|
|
|
|
isatty = sys.stdout.isatty()
|
|
|
|
error_cmd = None
|
2021-03-04 03:56:46 +01:00
|
|
|
|
|
|
|
if error and topotest_extra_config["vtysh_on_error"]:
|
2021-07-27 01:23:20 +02:00
|
|
|
error_cmd = commander.get_exec_path(["vtysh"])
|
|
|
|
elif error and topotest_extra_config["shell_on_error"]:
|
|
|
|
error_cmd = os.getenv("SHELL", commander.get_exec_path(["bash"]))
|
|
|
|
|
|
|
|
if error_cmd:
|
|
|
|
# Really would like something better than using this global here.
|
|
|
|
# Not all tests use topogen though so get_topogen() won't work.
|
|
|
|
win_info = None
|
|
|
|
wait_for_channels = []
|
|
|
|
for node in Mininet.g_mnet_inst.hosts.values():
|
2021-03-04 03:56:46 +01:00
|
|
|
pause = True
|
|
|
|
|
2021-07-27 01:23:20 +02:00
|
|
|
channel = "{}-{}".format(os.getpid(), Commander.tmux_wait_gen) if not isatty else None
|
|
|
|
Commander.tmux_wait_gen += 1
|
|
|
|
wait_for_channels.append(channel)
|
|
|
|
|
|
|
|
pane_info = node.run_in_window(
|
|
|
|
error_cmd,
|
|
|
|
new_window=win_info is None,
|
|
|
|
background=True,
|
|
|
|
title="{} ({})".format(title, node.name),
|
|
|
|
name=title,
|
|
|
|
tmux_target=win_info,
|
|
|
|
wait_for=channel
|
|
|
|
)
|
|
|
|
if win_info is None:
|
|
|
|
win_info = pane_info
|
|
|
|
|
|
|
|
# Now wait on any channels
|
|
|
|
for channel in wait_for_channels:
|
|
|
|
logger.debug("Waiting on TMUX channel %s", channel)
|
|
|
|
commander.cmd_raises([commander.get_exec_path("tmux"), "wait", channel])
|
|
|
|
|
|
|
|
if error and topotest_extra_config["cli_on_error"]:
|
|
|
|
# Really would like something better than using this global here.
|
|
|
|
# Not all tests use topogen though so get_topogen() won't work.
|
|
|
|
if Mininet.g_mnet_inst:
|
|
|
|
cli(Mininet.g_mnet_inst, title=title, background=False)
|
|
|
|
else:
|
|
|
|
logger.error("Could not launch CLI b/c no mininet exists yet")
|
2021-03-04 03:56:46 +01:00
|
|
|
|
2021-07-27 01:23:20 +02:00
|
|
|
while pause and isatty:
|
2021-03-04 03:56:46 +01:00
|
|
|
try:
|
2021-07-27 01:23:20 +02:00
|
|
|
user = raw_input(
|
|
|
|
'PAUSED, "cli" for CLI, "pdb" to debug, "Enter" to continue: '
|
|
|
|
)
|
2021-03-04 03:56:46 +01:00
|
|
|
except NameError:
|
2021-07-27 01:23:20 +02:00
|
|
|
user = input(
|
|
|
|
'PAUSED, "cli" for CLI, "pdb" to debug, "Enter" to continue: '
|
|
|
|
)
|
|
|
|
user = user.strip()
|
|
|
|
|
|
|
|
if user == "cli":
|
|
|
|
cli(Mininet.g_mnet_inst)
|
|
|
|
elif user == "pdb":
|
2021-03-04 03:56:46 +01:00
|
|
|
pdb.set_trace()
|
2021-07-27 01:23:20 +02:00
|
|
|
elif user:
|
|
|
|
print('Unrecognized input: "%s"' % user)
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Add common fixtures available to all tests as parameters
|
|
|
|
#
|
|
|
|
tgen = pytest.fixture(lib.fixtures.tgen)
|
|
|
|
topo = pytest.fixture(lib.fixtures.topo)
|