From e3e37d20ceb5efbc98ecad66d10db4a11d3f700b Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Wed, 2 Jun 2021 14:19:08 +0200 Subject: [PATCH 1/4] nixos/tests/test-driver: add shell_interact (cherry picked from commit 5a589b5ba8941d734e9c3aebbf2be2f50d7c32a5) --- nixos/lib/test-driver/test-driver.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nixos/lib/test-driver/test-driver.py b/nixos/lib/test-driver/test-driver.py index e216e566f28..90ae2e558ef 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,15 @@ 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 testing, not in the production test.""" + self.connect() + 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 = "" From 90469965436d93465080d551e2e251ff291cec1d Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Wed, 2 Jun 2021 14:49:59 +0200 Subject: [PATCH 2/4] nixos/tests/test-driver: document shell_interact (cherry picked from commit 9469433e341f7337308468bb4b9ccfff84b2951b) --- nixos/doc/manual/development/writing-nixos-tests.xml | 11 +++++++++++ nixos/lib/test-driver/test-driver.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/nixos/doc/manual/development/writing-nixos-tests.xml b/nixos/doc/manual/development/writing-nixos-tests.xml index 5a95436915f..c29f2b01064 100644 --- a/nixos/doc/manual/development/writing-nixos-tests.xml +++ b/nixos/doc/manual/development/writing-nixos-tests.xml @@ -436,6 +436,17 @@ machine.systemctl("list-jobs --no-pager", "any-user") # spawns a shell for `any- + + + shell_interact + + + + Allows you to directly interact with the guest shell. + This should only be used during test development, not in production tests. + + + diff --git a/nixos/lib/test-driver/test-driver.py b/nixos/lib/test-driver/test-driver.py index 90ae2e558ef..6669c914f76 100644 --- a/nixos/lib/test-driver/test-driver.py +++ b/nixos/lib/test-driver/test-driver.py @@ -459,7 +459,7 @@ class Machine: def shell_interact(self) -> None: """Allows you to interact with the guest shell - Should only be used during testing, not in the production test.""" + Should only be used during test development, not in the production test.""" self.connect() telnet = telnetlib.Telnet() telnet.sock = self.shell # type: ignore From 5ed752dd354b38d7c99e827fc24058158c246798 Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Wed, 2 Jun 2021 14:58:51 +0200 Subject: [PATCH 3/4] nixos/tests/test-driver: mention drawback (cherry picked from commit 287144273162acd869f514f7770a3daae4649d37) --- nixos/doc/manual/development/writing-nixos-tests.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos/doc/manual/development/writing-nixos-tests.xml b/nixos/doc/manual/development/writing-nixos-tests.xml index c29f2b01064..32321deeddf 100644 --- a/nixos/doc/manual/development/writing-nixos-tests.xml +++ b/nixos/doc/manual/development/writing-nixos-tests.xml @@ -444,6 +444,7 @@ machine.systemctl("list-jobs --no-pager", "any-user") # spawns a shell for `any- 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 Ctrl-d or Ctrl-c also ends the guest session. From 9452c8fb4b993823b32e45b3687fa26ab744c37e Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Thu, 3 Jun 2021 11:20:26 +0200 Subject: [PATCH 4/4] nixos/tests/test-driver: make it clear when shell is ready MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Domen Kožar (cherry picked from commit fd739c4dee12fbe57199f73c44ec22db2355028e) --- nixos/lib/test-driver/test-driver.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos/lib/test-driver/test-driver.py b/nixos/lib/test-driver/test-driver.py index 6669c914f76..fd5b91e6e4d 100644 --- a/nixos/lib/test-driver/test-driver.py +++ b/nixos/lib/test-driver/test-driver.py @@ -461,6 +461,7 @@ class Machine: 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()