diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index f09c4b473b53..a33c791a9f69 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -63,7 +63,7 @@ let - `config.node.pkgs.` or `config.nodes.foo.nixpkgs.pkgs.` to refer to the Nixpkgs used on the VM guest(s). - `hostPkgs.` when invoking commands on the VM host (e.g. in Python - `os.system("foo")`) + `subprocess.run(["foo"])`) - Since the runTest argument is a module instead of a function, arguments must be passed as option definitions. You may declare explicit `options` for the test parameter(s), or use the diff --git a/nixos/tests/boot.nix b/nixos/tests/boot.nix index a59f94b94edf..ecc6240fc888 100644 --- a/nixos/tests/boot.nix +++ b/nixos/tests/boot.nix @@ -203,11 +203,26 @@ in makeTest { name = "boot-uboot-extlinux"; nodes = { }; - testScript = '' - import os + testScript = /* py */ '' + import subprocess # Create a mutable linked image backed by the read-only SD image - if os.system("${pkgs.qemu}/bin/qemu-img create -f qcow2 -F raw -b ${sdImage} ${mutableImage}") != 0: + if ( + subprocess.run( + [ + "${pkgs.qemu}/bin/qemu-img", + "create", + "-f", + "qcow2", + "-F", + "raw", + "-b", + "${sdImage}", + "${mutableImage}", + ] + ).returncode + != 0 + ): raise RuntimeError("Could not create mutable linked image") machine = create_machine("${startCommand}") diff --git a/nixos/tests/ec2-image.nix b/nixos/tests/ec2-image.nix index df07d14b8ba7..b711ceadc2d5 100644 --- a/nixos/tests/ec2-image.nix +++ b/nixos/tests/ec2-image.nix @@ -135,7 +135,17 @@ in public_key = os.path.join(key_dir, "id_ed25519.pub") # Generate key pair using host SSH tools - ret = os.system(f"${hostPkgs.openssh}/bin/ssh-keygen -t ed25519 -f {private_key} -N \"\"") + ret = subprocess.run( + [ + "${hostPkgs.openssh}/bin/ssh-keygen", + "-t", + "ed25519", + "-f", + private_key, + "-N", + "" + ] + ).returncode if ret != 0: raise Exception("Failed to generate SSH key pair") diff --git a/nixos/tests/ghostunnel-modular.nix b/nixos/tests/ghostunnel-modular.nix index bb4cef2a9f08..7fa301168a46 100644 --- a/nixos/tests/ghostunnel-modular.nix +++ b/nixos/tests/ghostunnel-modular.nix @@ -54,13 +54,13 @@ }; testScript = '' - import os + import subprocess # prepare certificates def cmd(command): print(f"+{command}") - r = os.system(command) + r = subprocess.run(command, shell=True).returncode if r != 0: raise Exception(f"Command {command} failed with exit code {r}") diff --git a/nixos/tests/ghostunnel.nix b/nixos/tests/ghostunnel.nix index acd9c4331835..58749591ffbc 100644 --- a/nixos/tests/ghostunnel.nix +++ b/nixos/tests/ghostunnel.nix @@ -48,13 +48,13 @@ }; testScript = '' - import os + import subprocess # prepare certificates def cmd(command): print(f"+{command}") - r = os.system(command) + r = subprocess.run(command, shell=True).returncode if r != 0: raise Exception(f"Command {command} failed with exit code {r}") diff --git a/nixos/tests/haproxy.nix b/nixos/tests/haproxy.nix index 107010528737..20bcd700bb58 100644 --- a/nixos/tests/haproxy.nix +++ b/nixos/tests/haproxy.nix @@ -69,12 +69,12 @@ }; }; testScript = '' - import os + import subprocess # Helpers def cmd(command): print(f"+{command}") - r = os.system(command) + r = subprocess.run(command, shell=True).returncode if r != 0: raise Exception(f"Command {command} failed with exit code {r}") diff --git a/pkgs/os-specific/linux/usbrelay/test.nix b/pkgs/os-specific/linux/usbrelay/test.nix index b7894b0da773..60118dee1cd3 100644 --- a/pkgs/os-specific/linux/usbrelay/test.nix +++ b/pkgs/os-specific/linux/usbrelay/test.nix @@ -45,9 +45,11 @@ import ../../../../nixos/tests/make-test-python.nix ( documentation.nixos.enable = false; # building nixos manual takes long time }; - testScript = '' + testScript = /* py */ '' import os - if os.waitstatus_to_exitcode(os.system("lsusb -d 16c0:05df")) != 0: + import subprocess + + if os.waitstatus_to_exitcode(subprocess.run(["lsusb", "-d", "16c0:05df"]).returncode) != 0: print("No USB relay detected, skipping test") import sys sys.exit(2)