nixos/test-driver: handle decoding errors in Machine.execute

The output of a command is not guaranteed to be valid UTF-8, so the
decoding can fail raising UnicodeDecodeError. If this happens during a
`succeeds` the check will be erroneously marked failed.

This changes the error handling to the "replace" mode, where invalid
codepoints are replaced with � (REPLACEMENT CHARACTER U+FFFD) and the
decoding can go on.
This commit is contained in:
rnhmjoj 2023-02-02 13:26:18 +01:00
parent f2929eb949
commit 067d688b16
No known key found for this signature in database
GPG key ID: BFBAF4C975F76450

View file

@ -545,7 +545,7 @@ class Machine:
self.shell.send("echo ${PIPESTATUS[0]}\n".encode())
rc = int(self._next_newline_closed_block_from_shell().strip())
return (rc, output.decode())
return (rc, output.decode(errors="replace"))
def shell_interact(self, address: Optional[str] = None) -> None:
"""Allows you to interact with the guest shell for debugging purposes.