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

fix(logs): libvirt prints no errors on the processes' stderr

libvirt's default handler printed each error on stderr without saying
where it came from: in Docker those lines went to docker logs, and a
VM page read of a shut-off VM left one there. Every process that talks to
libvirt imports vrtManager.connection, which now registers a silent
handler; the errors still reach their callers as exceptions. The
console callback's own registration is dropped.
This commit is contained in:
catborise 2026-11-05 15:12:06 +03:00
parent 5d90d3fcf9
commit f670ee7333
3 changed files with 17 additions and 3 deletions

View file

@ -28,9 +28,6 @@ from instances.utils import can_open_console # noqa: E402
from operations.utils import public_error_text # noqa: E402
from vrtManager.connection import connection_manager # noqa: E402
# libvirt prints its errors on stderr, which is the user's terminal: they are
# raised and told in one line instead
libvirt.registerErrorHandler(lambda context, error: None, None)
SEND_WAIT = 5 # seconds a paste may wait for the VM to take it
ACCESS_CHECK = 10 # seconds between checks that the user may still use the console

View file

@ -58,6 +58,10 @@ CLOSE_REASONS = {
SSH_COMMAND = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libvirt-ssh")
logger = logging.getLogger(__name__)
# libvirt prints each error on stderr without saying where it came from; every
# process that talks to libvirt imports this module. The errors are raised to
# the callers, which handle or report them.
libvirt.registerErrorHandler(lambda context, error: None, None)
class wvmEventLoop(threading.Thread):

View file

@ -3,6 +3,8 @@
import contextlib
import os
import socket
import subprocess
import sys
import threading
import time
import unittest
@ -410,3 +412,14 @@ class EventLoopTestCase(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
class LibvirtStderrTestCase(unittest.TestCase):
def test_a_libvirt_error_is_not_printed_on_stderr(self):
script = (
"from django.conf import settings; settings.configure(); "
"import libvirt, vrtManager.connection\n"
"try:\n libvirt.open('test:///default').lookupByName('no-such-vm')\nexcept libvirt.libvirtError:\n pass"
)
result = subprocess.run([sys.executable, "-c", script], cwd=os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), capture_output=True, text=True)
self.assertEqual((result.returncode, result.stderr), (0, ""))