Capture redacted guest serial while waiting for shutdown
This commit is contained in:
+29
-4
@@ -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})')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user