Skip to content

Commit

Permalink
nixos/lib/test-driver: fix reading command output for other distros
Browse files Browse the repository at this point in the history
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
  • Loading branch information
am-on authored Feb 15, 2025
1 parent 866edf5 commit 9408901
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nixos/lib/test-driver/src/test_driver/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +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.
#
# Other distros could send both stdout and stderr to the test_driver. Receiving both
# breaks the code for getting the output since stderr isn't base64 encoded.
# Redirect stderr to /dev/null to avoid these compatibility issues.
out_command = (
f"{timeout_str} bash -c {shlex.quote(command)} | (base64 -w 0; echo)\n"
f"{timeout_str} bash -c {shlex.quote(command)} 2> /dev/null | (base64 -w 0; echo)\n"
)

assert self.shell
Expand Down

0 comments on commit 9408901

Please sign in to comment.