Sorry, Please ignore this patch, it's wrong.


On Thu, Jan 23, 2014 at 6:08 PM, apporc <appleorchard2000@gmail.com> wrote:
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'
*** Feature tests completed ***

By replacing default error handler of libvirt, this patch succeeded to
avoid the error. 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.

Signed-off-by: apporc <appleorchard2000@gmail.com>
---
 src/kimchi/featuretests.py |   14 ++++++++++++--
 src/kimchi/model.py        |    2 --
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py
index a5755a2..d68fcb8 100644
--- a/src/kimchi/featuretests.py
+++ b/src/kimchi/featuretests.py
@@ -57,16 +57,26 @@ class FeatureTests(object):

     @staticmethod
     def libvirt_supports_iso_stream(protocol):
+        def libvirt_errorhandler(userdata, error):
+            # A libvirt error handler to ignore annoying messages in stderr
+            pass
+
         xml = ISO_STREAM_XML % {'protocol': protocol}
         conn = None
         try:
+            # Register the error handler to hide libvirt error in stderr
+            libvirt.registerErrorHandler(f=libvirt_errorhandler, ctx=None)
             conn = libvirt.open('qemu:///system')
             dom = conn.defineXML(xml)
             dom.undefine()
             return True
-        except libvirt.libvirtError:
-            return False
+        except libvirt.libvirtError, e:
+            if e.message == "internal error unknown protocol type '%s'" % protocol:
+                return False
+            else:
+                raise e
         finally:
+            libvirt.registerErrorHandler(f=None, ctx=None)
             conn is None or conn.close()

     @staticmethod
diff --git a/src/kimchi/model.py b/src/kimchi/model.py
index ea528c6..f4f8224 100644
--- a/src/kimchi/model.py
+++ b/src/kimchi/model.py
@@ -225,7 +225,6 @@ class Model(object):
                 sys.exit(1)

     def _set_capabilities(self):
-        kimchi_log.info("*** Running feature tests ***")
         self.qemu_stream = FeatureTests.qemu_supports_iso_stream()
         self.qemu_stream_dns = FeatureTests.qemu_iso_stream_dns()

@@ -234,7 +233,6 @@ class Model(object):
             if FeatureTests.libvirt_supports_iso_stream(p):
                 self.libvirt_stream_protocols.append(p)

-        kimchi_log.info("*** Feature tests completed ***")
     _set_capabilities.priority = 90

     def get_capabilities(self):
--
1.7.9.5




--
Regards,
apporc