[Kimchi-devel] [PATCH v3] Supress error messages while checking vm metadata

Ramon Medeiros ramonn at linux.vnet.ibm.com
Thu Jun 4 03:45:56 UTC 2015


The function FeatureTests.disable_libvirt_error_logging only removes the
error message that will be displayed on the console. Libvirt also logs
errors on messages log. To avoid flood messages log with metadata errors,
it will be verified manually if the xml has the tag.

Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>

Changes:

v3:
Discard all code writed before. Aline suggested me a nice workaround, check
if the xml has metadata tag.
---
 src/kimchi/model/utils.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py
index 0c9d519..d4994d5 100644
--- a/src/kimchi/model/utils.py
+++ b/src/kimchi/model/utils.py
@@ -84,7 +84,8 @@ def _kimchi_set_metadata_node(dom, node):
 
 
 def libvirt_get_kimchi_metadata_node(dom, mode="current"):
-    FeatureTests.disable_libvirt_error_logging()
+    if not metadata_exists(dom):
+        return None
     try:
         xml = dom.metadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT,
                            KIMCHI_META_URL,
@@ -92,8 +93,6 @@ def libvirt_get_kimchi_metadata_node(dom, mode="current"):
         return etree.fromstring(xml)
     except libvirt.libvirtError:
         return None
-    finally:
-        FeatureTests.enable_libvirt_error_logging()
 
 
 def set_metadata_node(dom, node, metadata_support, mode="all"):
@@ -151,3 +150,12 @@ def get_metadata_node(dom, tag, metadata_support, mode="current"):
         if node is not None:
             return etree.tostring(node)
     return ""
+
+def metadata_exists(dom):
+     xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)
+     root = etree.fromstring(xml)
+
+     if root.find("metadata") == None:
+        return False
+     return True
+
-- 
2.1.0




More information about the Kimchi-devel mailing list