summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDomen Kožar <domen@dev.si>2021-06-03 13:11:46 +0200
committerGitHub <noreply@github.com>2021-06-03 13:11:46 +0200
commit0f8f64b54ed07966b83db2f20c888d5e035012ef (patch)
tree96e0b2172ecbd709be6b0dee3e92e4d2ae0bcbe6
parentblender: fix darwin build (diff)
parentnixos/tests/test-driver: make it clear when shell is ready (diff)
downloadnixpkgs-0f8f64b54ed07966b83db2f20c888d5e035012ef.tar.gz
Merge pull request #125475 from NixOS/backport-125372-to-release-21.05
[Backport release-21.05] nixos/tests/test-driver: add shell_interact
-rw-r--r--nixos/doc/manual/development/writing-nixos-tests.xml12
-rw-r--r--nixos/lib/test-driver/test-driver.py11
2 files changed, 23 insertions, 0 deletions
diff --git a/nixos/doc/manual/development/writing-nixos-tests.xml b/nixos/doc/manual/development/writing-nixos-tests.xml
index 5a95436915fa..32321deeddf9 100644
--- a/nixos/doc/manual/development/writing-nixos-tests.xml
+++ b/nixos/doc/manual/development/writing-nixos-tests.xml
@@ -436,6 +436,18 @@ machine.systemctl("list-jobs --no-pager", "any-user") # spawns a shell for `any-
</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>
+ <methodname>shell_interact</methodname>
+ </term>
+ <listitem>
+ <para>
+ Allows you to directly interact with the guest shell.
+ This should only be used during test development, not in production tests.
+ Killing the interactive session with <literal>Ctrl-d</literal> or <literal>Ctrl-c</literal> also ends the guest session.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</para>
diff --git a/nixos/lib/test-driver/test-driver.py b/nixos/lib/test-driver/test-driver.py
index e216e566f286..fd5b91e6e4d8 100644
--- a/nixos/lib/test-driver/test-driver.py
+++ b/nixos/lib/test-driver/test-driver.py
@@ -21,6 +21,7 @@ import shutil
import socket
import subprocess
import sys
+import telnetlib
import tempfile
import time
import traceback
@@ -455,6 +456,16 @@ class Machine:
return (status_code, output)
output += chunk
+ def shell_interact(self) -> None:
+ """Allows you to interact with the guest shell
+
+ Should only be used during test development, not in the production test."""
+ self.connect()
+ self.log("Terminal is ready (there is no prompt):")
+ telnet = telnetlib.Telnet()
+ telnet.sock = self.shell # type: ignore
+ telnet.interact()
+
def succeed(self, *commands: str) -> str:
"""Execute each command and check that it succeeds."""
output = ""