Skip to content

Commit 8869265

Browse files
committed
nixos/test-driver: printout instructions on how to connect via AF_VSOCK
1 parent b1394ba commit 8869265

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

nixos/lib/test-driver/src/test_driver/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ def main() -> None:
109109
help="the test script to run",
110110
type=Path,
111111
)
112+
arg_parser.add_argument(
113+
"--dump-vsocks",
114+
help="indicates that the interactive SSH backdoor is active and dumps information about it on start",
115+
action="store_true",
116+
)
112117

113118
args = arg_parser.parse_args()
114119

@@ -136,6 +141,8 @@ def main() -> None:
136141
if args.interactive:
137142
history_dir = os.getcwd()
138143
history_path = os.path.join(history_dir, ".nixos-test-history")
144+
if args.dump_vsocks:
145+
driver.dump_machine_ssh()
139146
ptpython.ipython.embed(
140147
user_ns=driver.test_symbols(),
141148
history_filename=history_path,

nixos/lib/test-driver/src/test_driver/driver.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from typing import Any
1212
from unittest import TestCase
1313

14+
from colorama import Style
15+
1416
from test_driver.errors import MachineError, RequestedAssertionFailed
1517
from test_driver.logger import AbstractLogger
1618
from test_driver.machine import Machine, NixStartScript, retry
@@ -176,6 +178,19 @@ def subtest(name: str) -> Iterator[None]:
176178
)
177179
return {**general_symbols, **machine_symbols, **vlan_symbols}
178180

181+
def dump_machine_ssh(self) -> None:
182+
print("SSH backdoor enabled, the machines can be accessed like this:")
183+
print(
184+
f"{Style.BRIGHT}Note:{Style.RESET_ALL} this requires {Style.BRIGHT}systemd-ssh-proxy(1){Style.RESET_ALL} to be enabled (default on NixOS 25.05 and newer)."
185+
)
186+
names = [machine.name for machine in self.machines]
187+
longest_name = len(max(names, key=len))
188+
for num, name in enumerate(names, start=3):
189+
spaces = " " * (longest_name - len(name) + 2)
190+
print(
191+
f" {name}:{spaces}{Style.BRIGHT}ssh -o User=root vsock/{num}{Style.RESET_ALL}"
192+
)
193+
179194
def test_script(self) -> None:
180195
"""Run the test script"""
181196
with self.logger.nested("run the VM test script"):

nixos/lib/testing-python.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pkgs.lib.throwIf (args ? specialArgs)
7575
),
7676
extraPythonPackages ? (_: [ ]),
7777
interactive ? { },
78+
sshBackdoor ? { },
7879
}@t:
7980
let
8081
testConfig =

nixos/lib/testing/nodes.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ in
181181

182182
passthru.nodes = config.nodesCompat;
183183

184+
extraDriverArgs = mkIf config.sshBackdoor.enable [
185+
"--dump-vsocks"
186+
];
187+
184188
defaults = mkMerge [
185189
(mkIf config.node.pkgsReadOnly {
186190
nixpkgs.pkgs = config.node.pkgs;

0 commit comments

Comments
 (0)