Skip to content

Commit d81d119

Browse files
committed
lib/test-driver: fix reading command output for other distros
When running the test-driver on other distros (e.g., via [https://github.com/numtide/nix-vm-test/](nix-vm-test)) executing a command can fail if the driver receives both stdout and stderr. The test-driver’s logic for reading output currently assumes it will only read base64 encoded stdout, so any extra stderr content leads to unexpected failures. This commit fixes the issue by redirecting the stderr to /dev/null, ensuring the driver only sees stdout. The tradeoff is losing stderr messages in the machine logs. Users can work around this by redirecting stderr to stdout in the command they are sending to the machine: ```python machine.execute("some_command 2>&1") ``` Related issues: - numtide/nix-vm-test#84 - numtide/nix-vm-test#5
1 parent 866edf5 commit d81d119

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

nixos/lib/test-driver/src/test_driver/machine.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,12 @@ def execute(
574574

575575
# While sh is bash on NixOS, this is not the case for every distro.
576576
# We explicitly call bash here to allow for the driver to boot other distros as well.
577-
out_command = (
578-
f"{timeout_str} bash -c {shlex.quote(command)} | (base64 -w 0; echo)\n"
579-
)
577+
#
578+
# Other distros could send both stdout and stderr to the test-driver. Receiving both
579+
# breaks the code for getting the output since the code assumes it will only receive
580+
# base64 encoded stdout.
581+
# Redirect stderr to /dev/null to avoid these compatibility issues.
582+
out_command = f"{timeout_str} bash -c {shlex.quote(command)} 2> /dev/null | (base64 -w 0; echo)\n"
580583

581584
assert self.shell
582585
self.shell.send(out_command.encode())

0 commit comments

Comments
 (0)