From 7d17d5d03b9151bf81d8858fba50394aa1077725 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Fri, 7 Jun 2019 16:56:57 -0400 Subject: [PATCH] virtinst: Run register_libvirt_error_handler on import We basically want this everywhere, and transparently, so run it on import like we do for gettext setup --- tests/utils.py | 1 - virtinst/__init__.py | 16 ++++++++++++++++ virtinst/cli.py | 2 -- virtinst/util.py | 10 ---------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index f74d16cee..d3bf9dae5 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -103,7 +103,6 @@ class _URIs(object): generally every test uses a fresh virConnect, or undoes the persistent changes it makes. """ - virtinst.util.register_libvirt_error_handler() is_testdriver_xml = "/testdriver.xml" in uri if not (is_testdriver_xml and self._testdriver_error): diff --git a/virtinst/__init__.py b/virtinst/__init__.py index 957444254..6db092105 100644 --- a/virtinst/__init__.py +++ b/virtinst/__init__.py @@ -21,7 +21,23 @@ def _setup_i18n(): gettext.install("virt-manager", _CLIConfig.gettext_dir) gettext.bindtextdomain("virt-manager", _CLIConfig.gettext_dir) + +def _set_libvirt_error_handler(): + """ + Ignore libvirt error reporting, we just use exceptions + """ + import libvirt + + def libvirt_callback(userdata, err): + ignore = userdata + ignore = err + ctx = None + libvirt.registerErrorHandler(libvirt_callback, ctx) + + _setup_i18n() +_set_libvirt_error_handler() + from virtinst import util from virtinst.uri import URI diff --git a/virtinst/cli.py b/virtinst/cli.py index 8ac387090..26328e39e 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -185,8 +185,6 @@ def setupLogging(appname, debug_stdout, do_quiet, cli_app=True): if streamHandler: rootLogger.addHandler(streamHandler) - util.register_libvirt_error_handler() - # Log uncaught exceptions def exception_log(typ, val, tb): logging.debug("Uncaught exception:\n%s", diff --git a/virtinst/util.py b/virtinst/util.py index c23e3acf7..6a4eb2e98 100644 --- a/virtinst/util.py +++ b/virtinst/util.py @@ -162,16 +162,6 @@ def get_cache_dir(): return os.path.join(ret, "virt-manager") -def register_libvirt_error_handler(): - """ - Ignore libvirt error reporting, we just use exceptions - """ - def libvirt_callback(userdata, err): - ignore = userdata - ignore = err - libvirt.registerErrorHandler(f=libvirt_callback, ctx=None) - - def ensure_meter(meter): if meter: return meter