1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-09 19:56: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

@ -1,5 +1,6 @@
"""The serial console worker: a paste reaches the VM whole although its
stream takes it in parts or is busy, and the stream is dropped once."""
stream takes it in parts or is busy, the stream is dropped once, and a VM
that stops is reported."""
from importlib.machinery import SourceFileLoader
from importlib.util import module_from_spec, spec_from_loader
@ -59,6 +60,30 @@ class ConsoleWorkerTests(TestCase):
console.close_stream() # the other thread, a moment later
stream.abort.assert_called_once_with()
def test_a_vm_that_stops_is_reported_although_its_stream_ended_first(self):
console = self.cb.Console.__new__(self.cb.Console)
console.domain = MagicMock()
console.stream = None # from_vm dropped it at the stream's end
console.active = True
console.domain.state.return_value = [self.cb.libvirt.VIR_DOMAIN_SHUTOFF]
with patch.object(self.cb, "say") as say:
console.check()
console.check()
say.assert_called_once_with("The VM is not running: its console opens again when it starts")
def test_a_vm_that_stops_while_its_console_reopens_is_reported(self):
console = self.cb.Console.__new__(self.cb.Console)
console.domain, console.connection = MagicMock(), MagicMock()
console.stream = None
console.active = True
console.domain.state.return_value = [self.cb.libvirt.VIR_DOMAIN_RUNNING]
console.domain.openConsole.side_effect = self.cb.libvirt.libvirtError("domain is not running")
console.domain.isActive.return_value = 0
with patch.object(self.cb, "say") as say:
console.check()
say.assert_called_once_with("The VM is not running: its console opens again when it starts")
self.assertIsNone(console.stream)
def test_a_closed_client_ends_the_worker(self):
with patch.object(self.cb.os, "read", return_value=b""):
self.cb.from_client(None, 0, None, self.console)