[PATCH v2] Supress error messages while checking vm metadata

Changes: v2: Improve coding to avoid code duplication 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 | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py index 0c9d519..50b0578 100644 --- a/src/kimchi/model/utils.py +++ b/src/kimchi/model/utils.py @@ -84,7 +84,6 @@ def _kimchi_set_metadata_node(dom, node): def libvirt_get_kimchi_metadata_node(dom, mode="current"): - FeatureTests.disable_libvirt_error_logging() try: xml = dom.metadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT, KIMCHI_META_URL, @@ -115,36 +114,39 @@ def set_metadata_node(dom, node, metadata_support, mode="all"): _kimchi_set_metadata_node(dom, node) -def _kimchi_get_metadata_node(dom, tag): +def _kimchi_get_metadata_node(xml, tag): # some other tools will not let libvirt create a persistent # configuration, just return empty + # remove the "kimchi" prefix of xml + for elem in xml.getiterator(): + if not hasattr(elem.tag, 'find'): + continue + i = elem.tag.find('}') + if i >= 0: + elem.tag = elem.tag[i+1:] + + objectify.deannotate(xml) + etree.cleanup_namespaces(xml) + return xml + + +def get_metadata_node(dom, tag, metadata_support, mode="current"): if not dom.isPersistent(): - return None + 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 not None: - for elem in kimchi.getiterator(): - if not hasattr(elem.tag, 'find'): - continue - i = elem.tag.find('}') - if i >= 0: - elem.tag = elem.tag[i+1:] - - objectify.deannotate(kimchi) - etree.cleanup_namespaces(kimchi) - return kimchi - return None + # remove the "kimchi" prefix of xml + if kimchi is None: + return "" -def get_metadata_node(dom, tag, metadata_support, mode="current"): 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) + kimchi = _kimchi_get_metadata_node(kimchi, tag) if kimchi is not None: node = kimchi.find(tag) -- 2.1.0

Some tests fail with this patch. All of them are related to VM user management - which is related to VM metadata. Please run "sudo make check" to make sure new patches don't break the application. ====================================================================== FAIL: test_nonroot_access (test_authorization.AuthorizationTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_authorization.py", line 146, in test_nonroot_access sorted([v['name'] for v in vms_data])) AssertionError: Lists differ: [u'test-groupa', u'test-me'] != [] First list contains 2 additional elements. First extra element 0: test-groupa - [u'test-groupa', u'test-me'] + [] ====================================================================== FAIL: test_edit_vm (test_rest.HttpsRestTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_rest.py", line 220, in test_edit_vm self.assertEquals(users, info['users']) AssertionError: Lists differ: [u'root', u'sync', u'shutdown'... != [] First list contains 5 additional elements. First extra element 0: root - [u'root', u'sync', u'shutdown', u'halt', u'kimchi'] + [] ====================================================================== FAIL: test_tasks (test_rest.HttpsRestTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_rest.py", line 1035, in test_tasks self.assertEquals(3, len(tasks)) AssertionError: 3 != 2 ====================================================================== FAIL: test_edit_vm (test_rest.RestTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_rest.py", line 220, in test_edit_vm self.assertEquals(users, info['users']) AssertionError: Lists differ: [u'root', u'sync', u'shutdown'... != [] First list contains 5 additional elements. First extra element 0: root - [u'root', u'sync', u'shutdown', u'halt', u'kimchi'] + [] ---------------------------------------------------------------------- On 05-05-2015 10:02, Ramon Medeiros wrote:
Changes:
v2: Improve coding to avoid code duplication
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>

On 05/05/2015 10:02, Ramon Medeiros wrote:
Changes:
v2: Improve coding to avoid code duplication
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 | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py index 0c9d519..50b0578 100644 --- a/src/kimchi/model/utils.py +++ b/src/kimchi/model/utils.py @@ -84,7 +84,6 @@ def _kimchi_set_metadata_node(dom, node):
def libvirt_get_kimchi_metadata_node(dom, mode="current"): - FeatureTests.disable_libvirt_error_logging() try: xml = dom.metadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT, KIMCHI_META_URL, @@ -115,36 +114,39 @@ def set_metadata_node(dom, node, metadata_support, mode="all"): _kimchi_set_metadata_node(dom, node)
The 'finally' statement can also be removed and then the FeatureTests import.
-def _kimchi_get_metadata_node(dom, tag): +def _kimchi_get_metadata_node(xml, tag): # some other tools will not let libvirt create a persistent # configuration, just return empty + # remove the "kimchi" prefix of xml + for elem in xml.getiterator(): + if not hasattr(elem.tag, 'find'): + continue + i = elem.tag.find('}') + if i >= 0: + elem.tag = elem.tag[i+1:] + + objectify.deannotate(xml) + etree.cleanup_namespaces(xml) + return xml + + +def get_metadata_node(dom, tag, metadata_support, mode="current"): if not dom.isPersistent(): - return None + 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 not None: - for elem in kimchi.getiterator(): - if not hasattr(elem.tag, 'find'): - continue - i = elem.tag.find('}') - if i >= 0: - elem.tag = elem.tag[i+1:] - - objectify.deannotate(kimchi) - etree.cleanup_namespaces(kimchi) - return kimchi - return None
+ # remove the "kimchi" prefix of xml + if kimchi is None: + return ""
-def get_metadata_node(dom, tag, metadata_support, mode="current"): 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) + kimchi = _kimchi_get_metadata_node(kimchi, tag)
if kimchi is not None: node = kimchi.find(tag)

On 05/05/2015 10:02, Ramon Medeiros wrote:
Changes:
v2: Improve coding to avoid code duplication
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 | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py index 0c9d519..50b0578 100644 --- a/src/kimchi/model/utils.py +++ b/src/kimchi/model/utils.py @@ -84,7 +84,6 @@ def _kimchi_set_metadata_node(dom, node):
def libvirt_get_kimchi_metadata_node(dom, mode="current"): - FeatureTests.disable_libvirt_error_logging() try: xml = dom.metadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT, KIMCHI_META_URL, @@ -115,36 +114,39 @@ def set_metadata_node(dom, node, metadata_support, mode="all"): _kimchi_set_metadata_node(dom, node)
-def _kimchi_get_metadata_node(dom, tag): +def _kimchi_get_metadata_node(xml, tag): # some other tools will not let libvirt create a persistent # configuration, just return empty + # remove the "kimchi" prefix of xml + for elem in xml.getiterator(): + if not hasattr(elem.tag, 'find'): + continue + i = elem.tag.find('}') + if i >= 0: + elem.tag = elem.tag[i+1:] + + objectify.deannotate(xml) + etree.cleanup_namespaces(xml) + return xml + + +def get_metadata_node(dom, tag, metadata_support, mode="current"): if not dom.isPersistent(): - return None + return "" xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) root = etree.fromstring(xml)
kimchi = root.find("metadata/{%s}kimchi" % KIMCHI_META_URL)
The tests are failing because of the above check. When libvirt has .metadata() support the guest XML will not have the tag "{%s}kimchi % KIMCHI_META_URL". I suggest create a new function, _get_metadata(dom) def _get_metadata(dom): if not dom.isPersistent(): return None xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) root = etree.fromstring(xml) metadata = root.find("metadata") if metadata is None: return None return metadata Then in get_metadata_node(): metadata = _get_metadata(dom) if metadata is None: return "" if metadata_support: kimchi = libvirt_get_kimchi_metadata_node(dom, mode) else: kimchi = _kimchi_get_metadata_node(metadata, tag) And in _kimchi_get_metadata_node(metadata, tag) add: kimchi = metadata.find("{%s}kimchi" % KIMCHI_META_URL) Note that libvirt_get_kimchi_metadata_node() is also called by set_metadata_node() so we need to do the metadata check there too to avoid the libvirt errors on logs.
- # remove the "kimchi" prefix of xml - if kimchi is not None: - for elem in kimchi.getiterator(): - if not hasattr(elem.tag, 'find'): - continue - i = elem.tag.find('}') - if i >= 0: - elem.tag = elem.tag[i+1:] - - objectify.deannotate(kimchi) - etree.cleanup_namespaces(kimchi) - return kimchi - return None
+ # remove the "kimchi" prefix of xml + if kimchi is None: + return ""
-def get_metadata_node(dom, tag, metadata_support, mode="current"): 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) + kimchi = _kimchi_get_metadata_node(kimchi, tag)
if kimchi is not None: node = kimchi.find(tag)
participants (3)
-
Aline Manera
-
CrÃstian Deives
-
Ramon Medeiros