From e03862c34a31ad716d56cc90cd67446125d614e9 Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Tue, 7 Sep 2021 03:55:01 +0000 Subject: [PATCH 1/3] topotests: to create pid file of topotest router 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 --- doc/developer/topotests.rst | 26 ++++++++++++++++++++++++++ tests/topotests/lib/topogen.py | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/doc/developer/topotests.rst b/doc/developer/topotests.rst index 4a8f7bd27d..14da25768f 100644 --- a/doc/developer/topotests.rst +++ b/doc/developer/topotests.rst @@ -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 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 """"""""""""" diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 325f65dd6f..a76ceaf16b 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -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<>" From c84159a90a21a2701da1d81f134b1c9d277336c4 Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Tue, 7 Sep 2021 07:07:18 +0000 Subject: [PATCH 2/3] topotests: update file format and resolving id Signed-off-by: Hiroki Shirokura --- tests/topotests/lib/topogen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index a76ceaf16b..33e1388639 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -773,7 +773,7 @@ class TopoRouter(TopoGear): # 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)) + f.write(str(self.net.pid) + "\n") def __str__(self): gear = super(TopoRouter, self).__str__() From 1994c6bc05fa67d02a3665fe2f2050fa544ce6d5 Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Tue, 7 Sep 2021 07:11:20 +0000 Subject: [PATCH 3/3] doc: don't use abbreviate Signed-off-by: Hiroki Shirokura --- doc/developer/topotests.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/developer/topotests.rst b/doc/developer/topotests.rst index 14da25768f..fa6a1ba660 100644 --- a/doc/developer/topotests.rst +++ b/doc/developer/topotests.rst @@ -962,7 +962,7 @@ You can run scripts inside the node, or use vtysh's or feature. [unet shell] # cd tests/topotests/srv6_locator # ./test_srv6_locator.py --topology-only - unet> r1 sh segment-routing srv6 locator + unet> r1 show segment-routing srv6 locator Locator: Name ID Prefix Status -------------------- ------- ------------------------ ------- @@ -972,7 +972,7 @@ You can run scripts inside the node, or use vtysh's or feature. [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 + r1# r1 show segment-routing srv6 locator Locator: Name ID Prefix Status -------------------- ------- ------------------------ -------