1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 04:36:48 +00:00

fix(console): a serial console reports its VM's stop

When a VM stopped, its console's stream could end before the worker's
next check saw the VM shut off. The check then found no stream to drop and
said nothing, or, seeing the VM still running, opened the console again,
which libvirt refused, and the session ended. The worker now remembers
whether the VM ran at its last check, and a console that cannot be opened
again because the VM stopped meanwhile is a stop: the terminal says the VM
is not running and the console opens again when it starts. A new stream is
the console's before its callback is registered, which may end it at once.

The live serial test's VM now repeats its BIOS banner (it reboots right
after finding no boot disk), so a console attached late still gets one,
and the test waits for the superuser's console to show it before the VM
stops. A run of the whole live suite over the socket missed the banner of
the paused-then-resumed VM before.
This commit is contained in:
catborise 2026-10-31 22:34:55 +03:00
parent 8b7b7bdc3e
commit 30864b507e
3 changed files with 49 additions and 14 deletions

View file

@ -47,19 +47,28 @@ class Console:
self.domain = connection.lookupByUUIDString(uuid)
self.connection = connection
self.stream = None
self.active = False # the VM ran at the last check
self.running = True
def check(self):
"""Open the stream while the VM runs, drop it while it does not."""
"""Open the stream while the VM runs, drop it while it does not. The
stream may have ended first: the VM's stop is still reported."""
active = self.domain.state()[0] in (libvirt.VIR_DOMAIN_RUNNING, libvirt.VIR_DOMAIN_PAUSED)
if active and self.stream is None:
stream = self.connection.newStream(libvirt.VIR_STREAM_NONBLOCK)
self.domain.openConsole(None, stream, 0) # a console in use is refused
stream.eventAddCallback(libvirt.VIR_STREAM_EVENT_READABLE, from_vm, self)
self.stream = stream
elif not active and self.stream is not None:
try:
self.domain.openConsole(None, stream, 0) # a console in use is refused
except libvirt.libvirtError:
if self.domain.isActive():
raise
active = False # it stopped meanwhile
else:
self.stream = stream # first: the callback may end it at once
stream.eventAddCallback(libvirt.VIR_STREAM_EVENT_READABLE, from_vm, self)
if not active and self.active:
self.close_stream()
say("The VM is not running: its console opens again when it starts")
self.active = active
def close_stream(self):
stream, self.stream = self.stream, None