[libvirt]log XML if nova fails to parse it
In case nova fails to parse the XML from libvirt the lxml exception is dumped to the log but it only states the location of the error in the XML string like lxml.etree.XMLSyntaxError: StartTag: invalid element name, line 40, column 35 To be able to troubleshoot the actual XML error we need to see the invalid XML as well. So this patch makes sure that if nova fails to parse the XML then the XML itself is dumped to DEBUG log. Change-Id: I14cce6db4c86f663e61d3668d081858741e88add
This commit is contained in:
committed by
Alexey Stupnikov
parent
5b91e78308
commit
87ee88f10a
@@ -13,6 +13,8 @@
|
||||
# under the License.
|
||||
|
||||
import ddt
|
||||
from unittest import mock
|
||||
|
||||
from lxml import etree
|
||||
from oslo_utils.fixture import uuidsentinel as uuids
|
||||
from oslo_utils import units
|
||||
@@ -80,6 +82,17 @@ class LibvirtConfigTest(LibvirtConfigBaseTest):
|
||||
obj = config.LibvirtConfigObject(root_name="demo")
|
||||
obj.parse_str(inxml)
|
||||
|
||||
@mock.patch.object(config.LOG, 'debug')
|
||||
def test_config_parse_error_xml_logged(self, mock_debug):
|
||||
inxml = "<demo><vendor_field index='Z'>6<1</vendor_field></demo>"
|
||||
obj = config.LibvirtConfigObject(root_name="demo")
|
||||
|
||||
self.assertRaises(etree.XMLSyntaxError, obj.parse_str, inxml)
|
||||
|
||||
mock_debug.assert_called_once_with(
|
||||
'Failed to parse the libvirt XML: %s',
|
||||
"<demo><vendor_field index='Z'>6<1</vendor_field></demo>")
|
||||
|
||||
def test_parse_on_off_str(self):
|
||||
obj = config.LibvirtConfigObject(root_name="demo")
|
||||
self.assertTrue(obj.parse_on_off_str('on'))
|
||||
|
||||
@@ -28,6 +28,7 @@ import typing as ty
|
||||
|
||||
from collections import OrderedDict
|
||||
from lxml import etree
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import units
|
||||
|
||||
@@ -37,6 +38,7 @@ from nova.objects import fields
|
||||
from nova.pci import utils as pci_utils
|
||||
from nova.virt import hardware
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# Namespace to use for Nova specific metadata items in XML
|
||||
NOVA_NS = "http://openstack.org/xmlns/libvirt/nova/1.1"
|
||||
@@ -83,7 +85,11 @@ class LibvirtConfigObject(object):
|
||||
return self._new_node(self.root_name)
|
||||
|
||||
def parse_str(self, xmlstr):
|
||||
self.parse_dom(etree.fromstring(xmlstr))
|
||||
try:
|
||||
self.parse_dom(etree.fromstring(xmlstr))
|
||||
except etree.Error:
|
||||
LOG.debug("Failed to parse the libvirt XML: %s", xmlstr)
|
||||
raise
|
||||
|
||||
def parse_dom(self, xmldoc):
|
||||
if self.root_name != xmldoc.tag:
|
||||
|
||||
Reference in New Issue
Block a user