Capture redacted guest serial while waiting for shutdown

This commit is contained in:
Codex
2026-10-13 05:47:48 +03:00
parent 17ade497a4
commit 4a636924df
2 changed files with 71 additions and 4 deletions
+29 -4
View File
@@ -575,10 +575,35 @@ class VM:
raise
def wait_poweroff(self, timeout):
try:
rc = self.process.wait(timeout=timeout)
except subprocess.TimeoutExpired as exc:
raise SmokeError('Guest failed to power off in time') from exc
deadline = time.monotonic() + timeout
serial_open = True
while self.process.poll() is None:
remaining = deadline - time.monotonic()
if remaining <= 0:
raise SmokeError('Guest failed to power off in time')
if serial_open:
try:
self.console.read(min(remaining, 0.25))
except SmokeError as exc:
if str(exc) != 'Guest console closed':
raise
serial_open = False
else:
try:
self.process.wait(timeout=remaining)
except subprocess.TimeoutExpired as exc:
raise SmokeError('Guest failed to power off in time') from exc
# Capture bytes queued immediately before exit, even if poll observed
# the child exiting before the first serial read.
while serial_open:
try:
if not self.console.read(0):
break
except SmokeError as exc:
if str(exc) != 'Guest console closed':
raise
serial_open = False
rc = self.process.returncode
if rc:
raise SmokeError(f'Test QEMU failed during poweroff ({rc})')