11from __future__ import annotations
22
33import json
4+ import logging
45import os
56import platform
67from collections .abc import AsyncGenerator
2526from jumpstarter .driver import Driver , export
2627
2728
29+ class QmpLogFilter (logging .Filter ):
30+ def filter (self , record ):
31+ return False
32+
33+
2834@dataclass (kw_only = True )
2935class QemuFlasher (FlasherInterface , Driver ):
3036 parent : Qemu
@@ -50,6 +56,10 @@ class QemuPower(PowerInterface, Driver):
5056
5157 @export
5258 async def on (self ) -> None : # noqa: C901
59+ if hasattr (self , "_process" ):
60+ self .logger .warning ("already powered on, ignoring request" )
61+ return
62+
5363 root = self .parent .validate_partition ("root" )
5464 bios = self .parent .validate_partition ("bios" )
5565 ovmf_code = self .parent .validate_partition ("OVMF_CODE.fd" )
@@ -165,6 +175,10 @@ async def on(self) -> None: # noqa: C901
165175
166176 qmp = QMPClient (self .parent .hostname )
167177
178+ logging .getLogger (
179+ "qemu.qmp.protocol.{}" .format (self .parent .hostname ),
180+ ).addFilter (QmpLogFilter ())
181+
168182 with fail_after (10 ):
169183 while qmp .runstate != Runstate .RUNNING :
170184 try :
@@ -174,6 +188,7 @@ async def on(self) -> None: # noqa: C901
174188
175189 chardevs = await qmp .execute ("query-chardev" )
176190 pty = next (c for c in chardevs if c ["label" ] == "serial0" )["filename" ].lstrip ("pty:" )
191+ Path (self .parent ._pty ).unlink (missing_ok = True )
177192 Path (self .parent ._pty ).symlink_to (pty )
178193
179194 await qmp .execute ("system_reset" )
@@ -188,6 +203,8 @@ def off(self) -> None:
188203 except TimeoutExpired :
189204 self ._process .kill ()
190205 del self ._process
206+ else :
207+ self .logger .warning ("already powered off, ignoring request" )
191208
192209 if hasattr (self , "_cidata" ):
193210 del self ._cidata
0 commit comments