about summary refs log tree commit diff
path: root/nixos/lib
diff options
context:
space:
mode:
authorJörg Thalheim <Mic92@users.noreply.github.com>2023-01-27 12:24:08 +0000
committerGitHub <noreply@github.com>2023-01-27 12:24:08 +0000
commite80e3878b3a78d156575637b2afa7e22082a3420 (patch)
tree1752efd3d4705c90f622c533e88e37a5ecd54bd6 /nixos/lib
parent68d1aeab9a627f2533c047361e40295d58b183fa (diff)
parent29db54c373ec765b43d15b1b8f3d7a73075bea9b (diff)
downloadnixlib-e80e3878b3a78d156575637b2afa7e22082a3420.tar
nixlib-e80e3878b3a78d156575637b2afa7e22082a3420.tar.gz
nixlib-e80e3878b3a78d156575637b2afa7e22082a3420.tar.bz2
nixlib-e80e3878b3a78d156575637b2afa7e22082a3420.tar.lz
nixlib-e80e3878b3a78d156575637b2afa7e22082a3420.tar.xz
nixlib-e80e3878b3a78d156575637b2afa7e22082a3420.tar.zst
nixlib-e80e3878b3a78d156575637b2afa7e22082a3420.zip
Merge pull request #178533 from Mic92/nixos-tests-shell
nixos/tests: extend shell_interact to accept alternative socat addresses
Diffstat (limited to 'nixos/lib')
-rw-r--r--nixos/lib/test-driver/test_driver/machine.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/nixos/lib/test-driver/test_driver/machine.py b/nixos/lib/test-driver/test_driver/machine.py
index 6af964a0f588..8f01833bffb4 100644
--- a/nixos/lib/test-driver/test_driver/machine.py
+++ b/nixos/lib/test-driver/test_driver/machine.py
@@ -549,18 +549,27 @@ class Machine:
 
         return (rc, output.decode())
 
-    def shell_interact(self) -> None:
-        """Allows you to interact with the guest shell
+    def shell_interact(self, address: Optional[str] = None) -> None:
+        """Allows you to interact with the guest shell for debugging purposes.
 
-        Should only be used during test development, not in the production test."""
+        @address string passed to socat that will be connected to the guest shell.
+        Check the `Running Tests interactivly` chapter of NixOS manual for an example.
+        """
         self.connect()
-        self.log("Terminal is ready (there is no initial prompt):")
+
+        if address is None:
+            address = "READLINE,prompt=$ "
+            self.log("Terminal is ready (there is no initial prompt):")
 
         assert self.shell
-        subprocess.run(
-            ["socat", "READLINE,prompt=$ ", f"FD:{self.shell.fileno()}"],
-            pass_fds=[self.shell.fileno()],
-        )
+        try:
+            subprocess.run(
+                ["socat", address, f"FD:{self.shell.fileno()}"],
+                pass_fds=[self.shell.fileno()],
+            )
+            # allow users to cancel this command without breaking the test
+        except KeyboardInterrupt:
+            pass
 
     def console_interact(self) -> None:
         """Allows you to interact with QEMU's stdin