]> git.proxmox.com Git - mirror_frr.git/commitdiff
tests: add --pcap and --pause-at-end options
authorChristian Hopps <chopps@labn.net>
Wed, 19 Apr 2023 04:40:48 +0000 (00:40 -0400)
committerChristian Hopps <chopps@labn.net>
Sat, 22 Apr 2023 02:10:54 +0000 (22:10 -0400)
Signed-off-by: Christian Hopps <chopps@labn.net>
tests/topotests/conftest.py
tests/topotests/lib/micronet_compat.py
tests/topotests/lib/topogen.py

index 06d3c3a396a3c7fd9e484a721c1bd2165601518d..87eee2e9f4d37bd8f40091aff227501879557ca3 100755 (executable)
@@ -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)
index 974823c34c551e8733d54f5934d4f56fdb87533b..f820136568c32be72d3f4c99d1f9a28e41f62667 100644 (file)
@@ -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):
index 17cf8a4f90a7707f21fa6c72faa70625f81f18d6..3583ce17edf5b13de8b732af30fc51931a69feae 100644 (file)
@@ -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()