Filter out non-ASCII characters on invalid UTF8

When an enumerate is done, it is possible that the iDRAC may return
invalid UTF8 that contains non-ASCII characters.  This causes an
XMLSyntaxError to be thrown.  This fix detects that situation and
filters out all non-ASCII characters to bypass the error.

See the following bug for further details:

Closes-Bug: #1779412
Change-Id: I5003785dee922920dcdd95c8d7e2a26e0bf97a7d
Christopher Dearborn 2018-07-02 15:33:34 -04:00
parent 413bfce123
commit 0de8b41768
2 changed files with 19 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import lxml.objectify
import mock
import requests.exceptions
import requests_mock
import six
from dracclient import exceptions
from dracclient.tests import base
@ -55,6 +56,14 @@ class ClientTestCase(base.BaseTest):
self.client.enumerate, 'resource')
def test_enumerate_with_invalid_utf8(self, mock_requests):'',
resp = self.client.enumerate('resource')
self.assertEqual('yay!', resp.text)
def test_enumerate_with_auto_pull(self, mock_requests):

View File

@ -12,6 +12,8 @@
# under the License.
import logging
import re
import six
import time
import uuid
@ -157,7 +159,14 @@ class Client(object):
filter_query, filter_dialect)
resp = self._do_request(payload)
resp_xml = ElementTree.fromstring(resp.content)
resp_xml = ElementTree.fromstring(resp.content)
except ElementTree.XMLSyntaxError:
LOG.warning('Received invalid content from iDRAC. Filtering out '
'non-ASCII characters: ' + repr(resp.content))
resp_xml = ElementTree.fromstring(re.sub(six.b('[^\x00-\x7f]'),
if auto_pull:
# The first response returns "<wsman:Items>"