[Kimchi-devel] [PATCH] Avoid useless libvirt error log produced by featuretests

Daniel H Barboza danielhb at linux.vnet.ibm.com
Mon Feb 3 16:50:13 UTC 2014


Reviewed-by: Daniel Barboza <danielhb at linux.vnet.ibm.com>


On 01/30/2014 06:01 PM, Aline Manera wrote:
> From: apporc <appleorchard2000 at gmail.com>
>
> When running feature tests, we get bunch of error messages as below:
>
> *** Running feature tests ***
> libvirt: Domain Config error : internal error unknown protocol type 'http'
> libvirt: Domain Config error : internal error unknown protocol type 'https'
> libvirt: Domain Config error : internal error unknown protocol type 'ftp'
> libvirt: Domain Config error : internal error unknown protocol type 'ftps'
> libvirt: Domain Config error : internal error unknown protocol type 'tftp'
> Cannot find '' in path: No such file or directory
> *** Feature tests completed ***
>
> By replacing default error handler of libvirt, this patch succeeded to
> avoid the errors. After Featuretest, the default error handler will be restored.
> The default error handler (in libvirtmod.so) just do one thing, it prints the
> error message to stderr before we catch the exception in python.
>
> Independent of the error, it will be logged into kimchi error log file.
> That way we can easily debug the system.
>
> Signed-off-by: apporc <appleorchard2000 at gmail.com>
> Signed-off-by: Aline Manera <alinefm at br.ibm.com>
> ---
>   src/kimchi/featuretests.py |   31 +++++++++++++++++++++++++++++--
>   1 file changed, 29 insertions(+), 2 deletions(-)
>
> diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py
> index 1557dd9..d924050 100644
> --- a/src/kimchi/featuretests.py
> +++ b/src/kimchi/featuretests.py
> @@ -32,6 +32,7 @@ from lxml.builder import E
>
>
>   from kimchi import config
> +from kimchi.utils import kimchi_log
>
>
>   ISO_STREAM_XML = """
> @@ -60,17 +61,39 @@ ISO_STREAM_XML = """
>   class FeatureTests(object):
>
>       @staticmethod
> +    def disable_screen_error_logging():
> +        def libvirt_errorhandler(userdata, error):
> +            # A libvirt error handler to ignore annoying messages in stderr
> +            pass
> +
> +        # Register the error handler to hide libvirt error in stderr
> +        libvirt.registerErrorHandler(f=libvirt_errorhandler, ctx=None)
> +        # Disable cherrypy screen logging, in order to log errors on kimchi
> +        # file without displaying them on screen
> +        cherrypy.log.screen = False
> +
> +    @staticmethod
> +    def enable_screen_error_logging():
> +        # Unregister the error handler
> +        libvirt.registerErrorHandler(f=None, ctx=None)
> +        # Enable cherrypy screen logging
> +        cherrypy.log.screen = True
> +
> +    @staticmethod
>       def libvirt_supports_iso_stream(protocol):
>           xml = ISO_STREAM_XML % {'protocol': protocol}
>           conn = None
>           try:
> +            FeatureTests.disable_screen_error_logging()
>               conn = libvirt.open('qemu:///system')
>               dom = conn.defineXML(xml)
>               dom.undefine()
>               return True
> -        except libvirt.libvirtError:
> +        except libvirt.libvirtError, e:
> +            kimchi_log.error(e.message)
>               return False
>           finally:
> +            FeatureTests.enable_screen_error_logging()
>               conn is None or conn.close()
>
>       @staticmethod
> @@ -81,14 +104,18 @@ class FeatureTests(object):
>               return xml
>           try:
>               conn = libvirt.open('qemu:///system')
> -            ret = conn.findStoragePoolSources('netfs', _get_xml(), 0)
> +            FeatureTests.disable_screen_error_logging()
> +            conn.findStoragePoolSources('netfs', _get_xml(), 0)
>           except libvirt.libvirtError as e:
> +            kimchi_log.error(e.message)
>               if e.get_error_code() == 38:
>                   # if libvirt cannot find showmount,
>                   # it returns 38--general system call failure
>                   return False
>           finally:
> +            FeatureTests.enable_screen_error_logging()
>               conn is None or conn.close()
> +
>           return True
>
>       @staticmethod




More information about the Kimchi-devel mailing list