diff options
-rw-r--r-- | nixos/lib/test-driver/test_driver/driver.py | 1 | ||||
-rw-r--r-- | nixos/lib/test-driver/test_driver/machine.py | 28 | ||||
-rw-r--r-- | nixos/tests/login.nix | 13 |
3 files changed, 28 insertions, 14 deletions
diff --git a/nixos/lib/test-driver/test_driver/driver.py b/nixos/lib/test-driver/test_driver/driver.py index de6abbb4679e..ad52f365737c 100644 --- a/nixos/lib/test-driver/test_driver/driver.py +++ b/nixos/lib/test-driver/test_driver/driver.py @@ -179,7 +179,6 @@ class Driver: start_command=cmd, name=name, keep_vm_state=args.get("keep_vm_state", False), - allow_reboot=args.get("allow_reboot", False), ) def serial_stdout_on(self) -> None: diff --git a/nixos/lib/test-driver/test_driver/machine.py b/nixos/lib/test-driver/test_driver/machine.py index 0db7930f496b..4929f2048ecc 100644 --- a/nixos/lib/test-driver/test_driver/machine.py +++ b/nixos/lib/test-driver/test_driver/machine.py @@ -144,7 +144,7 @@ class StartCommand: self, monitor_socket_path: Path, shell_socket_path: Path, - allow_reboot: bool = False, # TODO: unused, legacy? + allow_reboot: bool = False, ) -> str: display_opts = "" display_available = any(x in os.environ for x in ["DISPLAY", "WAYLAND_DISPLAY"]) @@ -152,16 +152,14 @@ class StartCommand: display_opts += " -nographic" # qemu options - qemu_opts = "" - qemu_opts += ( - "" - if allow_reboot - else " -no-reboot" + qemu_opts = ( " -device virtio-serial" " -device virtconsole,chardev=shell" " -device virtio-rng-pci" " -serial stdio" ) + if not allow_reboot: + qemu_opts += " -no-reboot" # TODO: qemu script already catpures this env variable, legacy? qemu_opts += " " + os.environ.get("QEMU_OPTS", "") @@ -195,9 +193,10 @@ class StartCommand: shared_dir: Path, monitor_socket_path: Path, shell_socket_path: Path, + allow_reboot: bool, ) -> subprocess.Popen: return subprocess.Popen( - self.cmd(monitor_socket_path, shell_socket_path), + self.cmd(monitor_socket_path, shell_socket_path, allow_reboot), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, @@ -312,7 +311,6 @@ class Machine: start_command: StartCommand keep_vm_state: bool - allow_reboot: bool process: Optional[subprocess.Popen] pid: Optional[int] @@ -337,13 +335,11 @@ class Machine: start_command: StartCommand, name: str = "machine", keep_vm_state: bool = False, - allow_reboot: bool = False, callbacks: Optional[List[Callable]] = None, ) -> None: self.out_dir = out_dir self.tmp_dir = tmp_dir self.keep_vm_state = keep_vm_state - self.allow_reboot = allow_reboot self.name = name self.start_command = start_command self.callbacks = callbacks if callbacks is not None else [] @@ -874,7 +870,7 @@ class Machine: self.process.stdin.write(chars.encode()) self.process.stdin.flush() - def start(self) -> None: + def start(self, allow_reboot: bool = False) -> None: if self.booted: return @@ -898,6 +894,7 @@ class Machine: self.shared_dir, self.monitor_path, self.shell_path, + allow_reboot, ) self.monitor, _ = monitor_socket.accept() self.shell, _ = shell_socket.accept() @@ -946,6 +943,15 @@ class Machine: self.send_monitor_command("quit") self.wait_for_shutdown() + def reboot(self) -> None: + """Press Ctrl+Alt+Delete in the guest. + + Prepares the machine to be reconnected which is useful if the + machine was started with `allow_reboot = True` + """ + self.send_key(f"ctrl-alt-delete") + self.connected = False + def wait_for_x(self) -> None: """Wait until it is possible to connect to the X server. Note that testing the existence of /tmp/.X11-unix/X0 is insufficient. diff --git a/nixos/tests/login.nix b/nixos/tests/login.nix index 2cff38d20059..67f5764a0a16 100644 --- a/nixos/tests/login.nix +++ b/nixos/tests/login.nix @@ -13,6 +13,8 @@ import ./make-test-python.nix ({ pkgs, latestKernel ? false, ... }: }; testScript = '' + machine.start(allow_reboot = True) + machine.wait_for_unit("multi-user.target") machine.wait_until_succeeds("pgrep -f 'agetty.*tty1'") machine.screenshot("postboot") @@ -53,7 +55,14 @@ import ./make-test-python.nix ({ pkgs, latestKernel ? false, ... }: machine.screenshot("getty") with subtest("Check whether ctrl-alt-delete works"): - machine.send_key("ctrl-alt-delete") - machine.wait_for_shutdown() + boot_id1 = machine.succeed("cat /proc/sys/kernel/random/boot_id").strip() + assert boot_id1 != "" + + machine.reboot() + + boot_id2 = machine.succeed("cat /proc/sys/kernel/random/boot_id").strip() + assert boot_id2 != "" + + assert boot_id1 != boot_id2 ''; }) |