[PATCH v4] Supress error messages while checking vm metadata

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> Changes: v4: Fix make check-local errors v3: Discard all code writed before. Aline suggested me a nice workaround, check if the xml has metadata tag. --- src/kimchi/model/utils.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py index 0c9d519..7f27edd 100644 --- a/src/kimchi/model/utils.py +++ b/src/kimchi/model/utils.py @@ -22,7 +22,6 @@ from lxml import etree, objectify from lxml.builder import E, ElementMaker from kimchi.exception import OperationFailed -from kimchi.model.featuretests import FeatureTests KIMCHI_META_URL = "https://github.com/kimchi-project/kimchi" KIMCHI_NAMESPACE = "kimchi" @@ -84,7 +83,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 +92,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 +149,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") is None: + return False + return True -- 2.1.0

Reviewed-by: Daniel Barboza <dhbarboza82@gmail.com> On 06/04/2015 01:44 AM, Ramon Medeiros wrote:
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>
Changes:
v4: Fix make check-local errors
v3: Discard all code writed before. Aline suggested me a nice workaround, check if the xml has metadata tag. --- src/kimchi/model/utils.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py index 0c9d519..7f27edd 100644 --- a/src/kimchi/model/utils.py +++ b/src/kimchi/model/utils.py @@ -22,7 +22,6 @@ from lxml import etree, objectify from lxml.builder import E, ElementMaker
from kimchi.exception import OperationFailed -from kimchi.model.featuretests import FeatureTests
KIMCHI_META_URL = "https://github.com/kimchi-project/kimchi" KIMCHI_NAMESPACE = "kimchi" @@ -84,7 +83,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 +92,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 +149,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") is None: + return False + return True
participants (3)
-
Aline Manera
-
Daniel Henrique Barboza
-
Ramon Medeiros