On 28/04/2015 11:19, Ramon Medeiros wrote:
Changes

v2: Use parse functions present on model/utils.py

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@linux.vnet.ibm.com>
---
 src/kimchi/model/utils.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py
index b2739b2..1b114f6 100644
--- a/src/kimchi/model/utils.py
+++ b/src/kimchi/model/utils.py
@@ -95,6 +95,9 @@ def _kimchi_set_metadata_node(dom, node):


 def libvirt_get_kimchi_metadata_node(dom, mode="current"):
+    if _kimchi_get_metadata_node(dom, "metadata") == None:
+        return
+

Doing that we will have 2 type of data processing to do the same thing.

I suggest change the get_metadata_node() to return empty string as far as the metadata node was not identified in the guest XML.

Some thing like:

def get_metadata_node(dom, tag, metadata_support, mode="current"):
   if not dom.isPersistent():                                                  
        return ""                                                            
    xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)                         
    root = etree.fromstring(xml)                                               
    kimchi = root.find("metadata/{%s}kimchi" % KIMCHI_META_URL)                
    # remove the "kimchi" prefix of xml                                        
    if kimchi is None:
        return ""

    if metadata_support:                                                       
        kimchi = libvirt_get_kimchi_metadata_node(dom, mode)                   
    else:                                                                      
        # FIXME remove this code when all distro libvirt supports metadata     
        # element                                                              
        kimchi = _kimchi_get_metadata_node(dom, tag)                           
                                                                                                                  
    node = kimchi.find(tag)                                                
    return etree.tostring(node)

The code in bold was moved from _kimchi_get_metadata_node(). So there you can change the function to receive the "kimchi" node instead of 'dom' element.

Also as the code will be run only and if only the metadata node is present we don't need to the FeatureTests.disable[enable]_libvirt_error_logging() in the _kimchi_get_metadata_node()
function.

Hope it makes sense. =)

     FeatureTests.disable_libvirt_error_logging()
     try:
         xml = dom.metadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT,