Skip to content

Commit c6978e8

Browse files
committed
nixos/test-driver: exit early if /dev/vhost-vsock isn't available
Right now it wrongly seems as if you can set `sshBackdoor.enable = true;` for each test and not only for debugging purposes. This is wrong however since you'd need to pass /dev/vhost-vsock into the sandbox for this (which is also a prerequisite for #392117). To make that clear, two things were changed: * add a warning to the manual to communicate this. * exit both interactive and non-interactive driver early if /dev/vhost-vsock is missing and the ssh backdoor is enabled. If that's the case, we pass a CLI flag to the driver already in the interactive case. This change also sets the flag for the non-interactive case. That way we also get a better error if somebody tries to enable this on a system that doesn't support that.
1 parent 079ead6 commit c6978e8

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

nixos/doc/manual/development/running-nixos-tests-interactively.section.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,19 @@ An SSH-based backdoor to log into machines can be enabled with
7171
{
7272
name = "…";
7373
nodes.machines = { /* … */ };
74-
sshBackdoor.enable = true;
74+
interactive.sshBackdoor.enable = true;
7575
}
7676
```
7777

78+
::: {.warning}
79+
Make sure to only enable the backdoor for interactive tests
80+
(i.e. by using `interactive.sshBackdoor.enable`)! This is the only
81+
supported configuration.
82+
83+
Running a test in a sandbox with this will fail because `/dev/vhost-vsock` isn't available
84+
in the sandbox.
85+
:::
86+
7887
This creates a [vsock socket](https://man7.org/linux/man-pages/man7/vsock.7.html)
7988
for each VM to log in with SSH. This configures root login with an empty password.
8089

nixos/lib/testing/run.nix

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,30 @@ in
4343
};
4444

4545
config = {
46-
rawTestDerivation = hostPkgs.stdenv.mkDerivation {
47-
name = "vm-test-run-${config.name}";
46+
rawTestDerivation =
47+
assert lib.assertMsg (!config.sshBackdoor.enable)
48+
"The SSH backdoor is currently not supported for non-interactive testing! Please make sure to only set `interactive.sshBackdoor.enable = true;`!";
49+
hostPkgs.stdenv.mkDerivation {
50+
name = "vm-test-run-${config.name}";
4851

49-
requiredSystemFeatures =
50-
[ "nixos-test" ]
51-
++ lib.optionals hostPkgs.stdenv.hostPlatform.isLinux [ "kvm" ]
52-
++ lib.optionals hostPkgs.stdenv.hostPlatform.isDarwin [ "apple-virt" ];
52+
requiredSystemFeatures =
53+
[ "nixos-test" ]
54+
++ lib.optionals hostPkgs.stdenv.hostPlatform.isLinux [ "kvm" ]
55+
++ lib.optionals hostPkgs.stdenv.hostPlatform.isDarwin [ "apple-virt" ];
5356

54-
buildCommand = ''
55-
mkdir -p $out
57+
buildCommand = ''
58+
mkdir -p $out
5659
57-
# effectively mute the XMLLogger
58-
export LOGFILE=/dev/null
60+
# effectively mute the XMLLogger
61+
export LOGFILE=/dev/null
5962
60-
${config.driver}/bin/nixos-test-driver -o $out
61-
'';
63+
${config.driver}/bin/nixos-test-driver -o $out
64+
'';
6265

63-
passthru = config.passthru;
66+
passthru = config.passthru;
6467

65-
meta = config.meta;
66-
};
68+
meta = config.meta;
69+
};
6770
test = lib.lazyDerivation {
6871
# lazyDerivation improves performance when only passthru items and/or meta are used.
6972
derivation = config.rawTestDerivation;

0 commit comments

Comments
 (0)