diff options
Diffstat (limited to 'nixos/lib')
-rw-r--r-- | nixos/lib/make-ext4-fs.nix | 8 | ||||
-rw-r--r-- | nixos/lib/test-driver/test-driver.py | 20 | ||||
-rw-r--r-- | nixos/lib/testing-python.nix | 11 |
3 files changed, 26 insertions, 13 deletions
diff --git a/nixos/lib/make-ext4-fs.nix b/nixos/lib/make-ext4-fs.nix index 33dbc8f5ec4..416beeb32f2 100644 --- a/nixos/lib/make-ext4-fs.nix +++ b/nixos/lib/make-ext4-fs.nix @@ -74,11 +74,9 @@ pkgs.stdenv.mkDerivation { return 1 fi - echo "Resizing to minimum allowed size" - resize2fs -M $img - - # And a final fsck, because of the previous truncating. - fsck.ext4 -n -f $img + # We may want to shrink the file system and resize the image to + # get rid of the unnecessary slack here--but see + # https://github.com/NixOS/nixpkgs/issues/125121 for caveats. if [ ${builtins.toString compressImage} ]; then echo "Compressing image" diff --git a/nixos/lib/test-driver/test-driver.py b/nixos/lib/test-driver/test-driver.py index e216e566f28..9c97ce38343 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 @@ -128,18 +129,18 @@ def create_vlan(vlan_nr: str) -> Tuple[str, str, "subprocess.Popen[bytes]", Any] return (vlan_nr, vde_socket, vde_process, fd) -def retry(fn: Callable) -> None: +def retry(fn: Callable, timeout: int = 900) -> None: """Call the given function repeatedly, with 1 second intervals, until it returns True or a timeout is reached. """ - for _ in range(900): + for _ in range(timeout): if fn(False): return time.sleep(1) if not fn(True): - raise Exception("action timed out") + raise Exception(f"action timed out after {timeout} seconds") class Logger: @@ -440,7 +441,7 @@ class Machine: def execute(self, command: str) -> Tuple[int, str]: self.connect() - out_command = "( {} ); echo '|!=EOF' $?\n".format(command) + out_command = "( set -euo pipefail; {} ); echo '|!=EOF' $?\n".format(command) self.shell.send(out_command.encode()) output = "" @@ -455,6 +456,16 @@ 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 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() + def succeed(self, *commands: str) -> str: """Execute each command and check that it succeeds.""" output = "" @@ -896,7 +907,6 @@ class Machine: def create_machine(args: Dict[str, Any]) -> Machine: global log args["log"] = log - args["redirectSerial"] = os.environ.get("USE_SERIAL", "0") == "1" return Machine(args) diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix index c9d4f0f0861..715482e8730 100644 --- a/nixos/lib/testing-python.nix +++ b/nixos/lib/testing-python.nix @@ -130,7 +130,13 @@ rec { { virtualisation.qemu.package = qemu_pkg; } - ); + ) ++ [( + { + # Ensure we do not use aliases. Ideally this is only set + # when the test framework is used by Nixpkgs NixOS tests. + nixpkgs.config.allowAliases = false; + } + )]; }; # FIXME: get this pkg from the module system @@ -190,8 +196,7 @@ rec { --add-flags "''${vms[*]}" \ ${lib.optionalString enableOCR "--prefix PATH : '${ocrProg}/bin'"} \ --set tests 'start_all(); join_all();' \ - --set VLANS '${toString vlans}' \ - ${lib.optionalString (builtins.length vms == 1) "--set USE_SERIAL 1"} + --set VLANS '${toString vlans}' ''); # " passMeta = drv: drv // lib.optionalAttrs (t ? meta) { |