]> git.proxmox.com Git - mirror_frr.git/blobdiff - tests/topotests/lib/topogen.py
Merge pull request #13455 from sri-mohan1/srib-ldpd
[mirror_frr.git] / tests / topotests / lib / topogen.py
index f5b3ad06d94db26fb8b077f955a7d13faf809944..2d6138990ef87e3dcd37c58690d28a7ebdacd645 100644 (file)
@@ -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,7 @@ class Topogen(object):
         # Mininet(Micronet) to build the actual topology.
         assert not inspect.isclass(topodef)
 
-        self.net = Mininet()
+        self.net = Mininet(rundir=self.logdir, pytestconfig=topotest.g_pytest_config)
 
         # Adjust the parent namespace
         topotest.fix_netns_limits(self.net)
@@ -239,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)
@@ -454,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()
@@ -752,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()
@@ -861,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,
@@ -911,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,
@@ -946,9 +953,11 @@ 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.debug('vtysh command => "{}"'.format(command))
+        self.logger.debug("vtysh command => {}".format(shlex.quote(command)))
         output = self.run(vtysh_command)
 
         dbgout = output.strip()
@@ -1100,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)
@@ -1120,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
 
@@ -1146,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):
@@ -1194,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):