nixos/test-driver: exit early if /dev/vhost-vsock isn't available (#406455)

This commit is contained in:
Jacek Galowicz 2025-05-13 11:59:34 +02:00 committed by GitHub
commit cd79d4189d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 16 deletions

View file

@ -71,10 +71,19 @@ An SSH-based backdoor to log into machines can be enabled with
{ {
name = "…"; name = "…";
nodes.machines = { /* … */ }; nodes.machines = { /* … */ };
sshBackdoor.enable = true; interactive.sshBackdoor.enable = true;
} }
``` ```
::: {.warning}
Make sure to only enable the backdoor for interactive tests
(i.e. by using `interactive.sshBackdoor.enable`)! This is the only
supported configuration.
Running a test in a sandbox with this will fail because `/dev/vhost-vsock` isn't available
in the sandbox.
:::
This creates a [vsock socket](https://man7.org/linux/man-pages/man7/vsock.7.html) This creates a [vsock socket](https://man7.org/linux/man-pages/man7/vsock.7.html)
for each VM to log in with SSH. This configures root login with an empty password. for each VM to log in with SSH. This configures root login with an empty password.

View file

@ -43,27 +43,30 @@ in
}; };
config = { config = {
rawTestDerivation = hostPkgs.stdenv.mkDerivation { rawTestDerivation =
name = "vm-test-run-${config.name}"; assert lib.assertMsg (!config.sshBackdoor.enable)
"The SSH backdoor is currently not supported for non-interactive testing! Please make sure to only set `interactive.sshBackdoor.enable = true;`!";
hostPkgs.stdenv.mkDerivation {
name = "vm-test-run-${config.name}";
requiredSystemFeatures = requiredSystemFeatures =
[ "nixos-test" ] [ "nixos-test" ]
++ lib.optionals hostPkgs.stdenv.hostPlatform.isLinux [ "kvm" ] ++ lib.optionals hostPkgs.stdenv.hostPlatform.isLinux [ "kvm" ]
++ lib.optionals hostPkgs.stdenv.hostPlatform.isDarwin [ "apple-virt" ]; ++ lib.optionals hostPkgs.stdenv.hostPlatform.isDarwin [ "apple-virt" ];
buildCommand = '' buildCommand = ''
mkdir -p $out mkdir -p $out
# effectively mute the XMLLogger # effectively mute the XMLLogger
export LOGFILE=/dev/null export LOGFILE=/dev/null
${config.driver}/bin/nixos-test-driver -o $out ${config.driver}/bin/nixos-test-driver -o $out
''; '';
passthru = config.passthru; passthru = config.passthru;
meta = config.meta; meta = config.meta;
}; };
test = lib.lazyDerivation { test = lib.lazyDerivation {
# lazyDerivation improves performance when only passthru items and/or meta are used. # lazyDerivation improves performance when only passthru items and/or meta are used.
derivation = config.rawTestDerivation; derivation = config.rawTestDerivation;