From d81d1190ba886a79273162410c453cec258aa3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amon=20Stopin=C5=A1ek?= Date: Sat, 15 Feb 2025 15:23:24 +0700 Subject: [PATCH] lib/test-driver: fix reading command output for other distros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: - https://github.com/numtide/nix-vm-test/issues/84 - https://github.com/numtide/nix-vm-test/issues/5 --- nixos/lib/test-driver/src/test_driver/machine.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nixos/lib/test-driver/src/test_driver/machine.py b/nixos/lib/test-driver/src/test_driver/machine.py index 4faa377265084..f1fb3436601cb 100644 --- a/nixos/lib/test-driver/src/test_driver/machine.py +++ b/nixos/lib/test-driver/src/test_driver/machine.py @@ -574,9 +574,12 @@ def execute( # While sh is bash on NixOS, this is not the case for every distro. # We explicitly call bash here to allow for the driver to boot other distros as well. - out_command = ( - f"{timeout_str} bash -c {shlex.quote(command)} | (base64 -w 0; echo)\n" - ) + # + # Other distros could send both stdout and stderr to the test-driver. Receiving both + # breaks the code for getting the output since the code assumes it will only receive + # base64 encoded stdout. + # Redirect stderr to /dev/null to avoid these compatibility issues. + out_command = f"{timeout_str} bash -c {shlex.quote(command)} 2> /dev/null | (base64 -w 0; echo)\n" assert self.shell self.shell.send(out_command.encode())