diff --git a/tests/utils.py b/tests/utils.py index 3a75f1b5c..fc04a53ba 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -71,6 +71,7 @@ def openconn(uri): generally every test uses a fresh virConnect, or undoes the persistent changes it makes. """ + virtinst.util.register_libvirt_error_handler() conn = virtinst.cli.getConnection(uri) if uri not in _conn_cache: diff --git a/virtinst/cli.py b/virtinst/cli.py index 44f288d93..d8c921af5 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -200,12 +200,7 @@ def setupLogging(appname, debug_stdout, do_quiet, cli_app=True): if streamHandler: rootLogger.addHandler(streamHandler) - # Register libvirt handler - def libvirt_callback(ignore, err): - if err[3] != libvirt.VIR_ERR_ERROR: - # Don't log libvirt errors: global error handler will do that - logging.warn("Non-error from libvirt: '%s'", err[2]) - libvirt.registerErrorHandler(f=libvirt_callback, ctx=None) + util.register_libvirt_error_handler() # Log uncaught exceptions def exception_log(typ, val, tb): diff --git a/virtinst/util.py b/virtinst/util.py index 08966b045..f1b7efa88 100644 --- a/virtinst/util.py +++ b/virtinst/util.py @@ -517,3 +517,13 @@ def convert_units(value, old_unit, new_unit): power = get_power(new_unit) return in_bytes / pow(factor, power) + + +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)