There are two functions which read a VM metadata on Kimchi:
libvirt_get_kimchi_metadata_node (the one you changed)
and _kimchi_get_metadata_node. Both functions do the same thing but in
different ways: libvirt_get_kimchi_metadata_node uses the libvirt metadata
API to fetch the metadata info from a VM (= easier to use), and
_kimchi_get_metadata_node reads the metadata info from the VM's XML (=
harder to use). As you can see in get_metadata_node, the first function is
called when the host system uses a newer version of Kimchi which supports
the metadata API, and the second function is used otherwise.
Your patch is changing libvirt_get_kimchi_metadata_node so it parses the
XML _and_ uses the metadata API to get the metadata info. If we want to
avoid using the metadata API (because it always prints messages when a VM
has no metadata, which is what this issue is about) we should then use the
function _kimchi_get_metadata_node every time.
Also, we always use the Python lxml API to read XML data. We used to have
mixed APIs in the past and it was hard to maintain, so we decided to use
the same one in order to keep consistency.
On Fri, Apr 24, 2015 at 3:04 PM Ramon Medeiros <ramonn(a)linux.vnet.ibm.com>
wrote:
From: Ramon Medeiros <ramonn(a)jarvis.br.ibm.com>
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(a)linux.vnet.ibm.com>
---
src/kimchi/model/utils.py | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py
index b2739b2..749be93 100644
--- a/src/kimchi/model/utils.py
+++ b/src/kimchi/model/utils.py
@@ -22,6 +22,7 @@ import socket
import urlparse
from lxml import etree, objectify
from lxml.builder import E, ElementMaker
+from xml.dom import minidom
from kimchi.exception import OperationFailed
from kimchi.model.featuretests import FeatureTests
@@ -95,6 +96,13 @@ def _kimchi_set_metadata_node(dom, node):
def libvirt_get_kimchi_metadata_node(dom, mode="current"):
+ # check xml for metadata tag
+ xml = minidom.parseString(dom.XMLDesc(0))
+
+ # no metadata: return
+ if not xml.getElementsByTagName('metadata'):
+ return None
+
FeatureTests.disable_libvirt_error_logging()
try:
xml = dom.metadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT,
--
2.1.0
_______________________________________________
Kimchi-devel mailing list
Kimchi-devel(a)ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel