From: Christian Hopps Date: Wed, 19 Apr 2023 04:40:48 +0000 (-0400) Subject: tests: add --pcap and --pause-at-end options X-Git-Tag: base_9.0~147^2~7 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=773fd82ed5b632e0e33004d3f9a80f6a60fab9f0;p=mirror%2Ffrr.git tests: add --pcap and --pause-at-end options Signed-off-by: Christian Hopps --- diff --git a/tests/topotests/conftest.py b/tests/topotests/conftest.py index 06d3c3a396..87eee2e9f4 100755 --- a/tests/topotests/conftest.py +++ b/tests/topotests/conftest.py @@ -67,6 +67,12 @@ def pytest_addoption(parser): help="Pause after each test", ) + parser.addoption( + "--pause-at-end", + action="store_true", + help="Pause before taking munet down", + ) + parser.addoption( "--pause-on-error", action="store_true", @@ -80,6 +86,13 @@ def pytest_addoption(parser): help="Do not pause after (disables default when --shell or -vtysh given)", ) + parser.addoption( + "--pcap", + default="", + metavar="NET[,NET...]", + help="Comma-separated list of networks to capture packets on, or 'all'", + ) + 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) diff --git a/tests/topotests/lib/micronet_compat.py b/tests/topotests/lib/micronet_compat.py index 974823c34c..f820136568 100644 --- a/tests/topotests/lib/micronet_compat.py +++ b/tests/topotests/lib/micronet_compat.py @@ -377,6 +377,24 @@ ff02::2\tip6-allrouters def start(self): """Start the micronet topology.""" + pcapopt = self.cfgopt.get_option_list("--pcap") + if "all" in pcapopt: + pcapopt = self.switches.keys() + for pcap in pcapopt: + if ":" in pcap: + host, intf = pcap.split(":") + pcap = f"{host}-{intf}" + host = self.hosts[host] + else: + host = self + intf = pcap + pcapfile = f"{self.rundir}/capture-{pcap}.pcap" + host.run_in_window( + f"tshark -s 9200 -i {intf} -P -w {pcapfile}", + background=True, + title=f"cap:{pcap}", + ) + self.logger.debug("%s: Starting (no-op).", self) def stop(self): diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 17cf8a4f90..3583ce17ed 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -43,6 +43,7 @@ import lib.topolog as topolog from lib.micronet import Commander from lib.micronet_compat import Mininet from lib.topolog import logger +from munet.testing.util import pause_test from lib import topotest @@ -450,7 +451,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()