various: replace os.system with subprocess.run

Signed-off-by: phanirithvij <phanirithvij2000@gmail.com>
This commit is contained in:
phanirithvij
2026-07-13 06:06:38 +05:30
parent bdbb37bff4
commit 0cd4659ead
7 changed files with 40 additions and 13 deletions

View File

@@ -63,7 +63,7 @@ let
- `config.node.pkgs.<name>` or `config.nodes.foo.nixpkgs.pkgs.<name>` to refer
to the Nixpkgs used on the VM guest(s).
- `hostPkgs.<name>` 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

View File

@@ -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}")

View File

@@ -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")

View File

@@ -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}")

View File

@@ -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}")

View File

@@ -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}")

View File

@@ -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)