Skip to content

Commit

Permalink
nixos/lib/test-driver: wire up QMP client
Browse files Browse the repository at this point in the history
Now that we have a QMP client, we can wire it up in the test driver.

For now, it is almost completely useless because of the need of a constant "event loop", especially
for event listening.

In the next commits, we will slowly enable more and more usecases.
  • Loading branch information
RaitoBezarius committed Sep 27, 2023
1 parent 9201646 commit 8b4c520
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions nixos/lib/test-driver/default.nix
Expand Up @@ -23,6 +23,7 @@ python3Packages.buildPythonApplication rec {
netpbm
python3Packages.colorama
python3Packages.ptpython
python3Packages.qemu-qmp
qemu_pkg
socat
vde2
Expand Down
16 changes: 15 additions & 1 deletion nixos/lib/test-driver/test_driver/machine.py
Expand Up @@ -16,6 +16,8 @@
import tempfile
import threading
import time
import asyncio
from qemu.qmp import QMPClient

from test_driver.logger import rootlog

Expand Down Expand Up @@ -144,6 +146,7 @@ class StartCommand:
def cmd(
self,
monitor_socket_path: Path,
qmp_socket_path: Path,
shell_socket_path: Path,
allow_reboot: bool = False,
) -> str:
Expand All @@ -167,6 +170,7 @@ def cmd(

return (
f"{self._cmd}"
f" -qmp unix:{qmp_socket_path},server=on,wait=off"
f" -monitor unix:{monitor_socket_path}"
f" -chardev socket,id=shell,path={shell_socket_path}"
f"{qemu_opts}"
Expand Down Expand Up @@ -194,11 +198,14 @@ def run(
state_dir: Path,
shared_dir: Path,
monitor_socket_path: Path,
qmp_socket_path: Path,
shell_socket_path: Path,
allow_reboot: bool,
) -> subprocess.Popen:
return subprocess.Popen(
self.cmd(monitor_socket_path, shell_socket_path, allow_reboot),
self.cmd(
monitor_socket_path, qmp_socket_path, shell_socket_path, allow_reboot
),
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
Expand Down Expand Up @@ -309,6 +316,7 @@ class Machine:
shared_dir: Path
state_dir: Path
monitor_path: Path
qmp_path: Path
shell_path: Path

start_command: StartCommand
Expand All @@ -317,6 +325,7 @@ class Machine:
process: Optional[subprocess.Popen]
pid: Optional[int]
monitor: Optional[socket.socket]
qmp_client: Optional[QMPClient]
shell: Optional[socket.socket]
serial_thread: Optional[threading.Thread]

Expand Down Expand Up @@ -352,6 +361,7 @@ def __init__(

self.state_dir = self.tmp_dir / f"vm-state-{self.name}"
self.monitor_path = self.state_dir / "monitor"
self.qmp_path = self.state_dir / "qmp"
self.shell_path = self.state_dir / "shell"
if (not self.keep_vm_state) and self.state_dir.exists():
self.cleanup_statedir()
Expand All @@ -360,6 +370,7 @@ def __init__(
self.process = None
self.pid = None
self.monitor = None
self.qmp_client = None
self.shell = None
self.serial_thread = None

Expand Down Expand Up @@ -1083,15 +1094,18 @@ def create_socket(path: Path) -> socket.socket:

monitor_socket = create_socket(clear(self.monitor_path))
shell_socket = create_socket(clear(self.shell_path))
self.qmp_client = QMPClient(self.name)
self.process = self.start_command.run(
self.state_dir,
self.shared_dir,
self.monitor_path,
self.qmp_path,
self.shell_path,
allow_reboot,
)
self.monitor, _ = monitor_socket.accept()
self.shell, _ = shell_socket.accept()
asyncio.run(self.qmp_client.connect(str(self.qmp_path)))

# Store last serial console lines for use
# of wait_for_console_text
Expand Down

0 comments on commit 8b4c520

Please sign in to comment.