]> git.puffer.fish Git - matthieu/frr.git/commitdiff
topotests: to create pid file of topotest router
authorHiroki Shirokura <slank.dev@gmail.com>
Tue, 7 Sep 2021 03:55:01 +0000 (03:55 +0000)
committerHiroki Shirokura <slank.dev@gmail.com>
Tue, 7 Sep 2021 03:55:04 +0000 (03:55 +0000)
Create a pid file for the router created by topotest.
By executing nsenter directly against this pid, developers
can execute commands directly from outside the unet shell.
This allows the developer to use script, tab completion, etc.,
and improves efficiency.

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
doc/developer/topotests.rst
tests/topotests/lib/topogen.py

index 4a8f7bd27de4ef56530237069f9d27fba0cf85b8..14da25768f8d8eb52fba5297a75e8ff779f138b6 100644 (file)
@@ -953,6 +953,32 @@ configuration files (per-daemon) using the following commands:
    end
    r1#
 
+You can also login to the node specified by nsenter using bash, etc.
+A pid file for each node will be created in the relevant test dir.
+You can run scripts inside the node, or use vtysh's <tab> or <?> feature.
+
+.. code:: shell
+
+  [unet shell]
+  # cd tests/topotests/srv6_locator
+  # ./test_srv6_locator.py --topology-only
+  unet> r1 sh segment-routing srv6 locator
+  Locator:
+  Name                 ID      Prefix                   Status
+  -------------------- ------- ------------------------ -------
+  loc1                       1 2001:db8:1:1::/64        Up
+  loc2                       2 2001:db8:2:2::/64        Up
+
+  [Another shell]
+  # nsenter -a -t $(cat /tmp/topotests/srv6_locator.test_srv6_locator/r1.pid) bash --norc
+  # vtysh
+  r1# r1 sh segment-routing srv6 locator
+  Locator:
+  Name                 ID      Prefix                   Status
+  -------------------- ------- ------------------------ -------
+  loc1                       1 2001:db8:1:1::/64        Up
+  loc2                       2 2001:db8:2:2::/64        Up
+
 Writing Tests
 """""""""""""
 
index 325f65dd6fdfe075e2efc24119f90dd2ddfd91f1..a76ceaf16bef21182c680536fb78322a3af7c299 100644 (file)
@@ -771,6 +771,10 @@ class TopoRouter(TopoGear):
         # Mount gear log directory on a common path
         self.net.bind_mount(self.gearlogdir, "/tmp/gearlogdir")
 
+        # Ensure pid file
+        with open(os.path.join(self.logdir, self.name + ".pid"), "w") as f:
+            f.write(str(tgen.net.hosts[self.name].pid))
+
     def __str__(self):
         gear = super(TopoRouter, self).__str__()
         gear += " TopoRouter<>"