Browse Source

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:
https://bugs.launchpad.net/python-dracclient/+bug/1779412

Closes-Bug: #1779412
Change-Id: I5003785dee922920dcdd95c8d7e2a26e0bf97a7d
changes/73/579673/4
Christopher Dearborn 4 years ago
parent
commit
0de8b41768
  1. 9
      dracclient/tests/test_wsman.py
  2. 11
      dracclient/wsman.py

9
dracclient/tests/test_wsman.py

@ -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.assertRaises(exceptions.WSManInvalidResponse,
self.client.enumerate, 'resource')
@requests_mock.Mocker()
def test_enumerate_with_invalid_utf8(self, mock_requests):
mock_requests.post('https://1.2.3.4:443/wsman',
content=six.b('<result>yay!\xC0</result>'))
resp = self.client.enumerate('resource')
self.assertEqual('yay!', resp.text)
@requests_mock.Mocker()
def test_enumerate_with_auto_pull(self, mock_requests):
mock_requests.post(

11
dracclient/wsman.py

@ -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)
try:
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]'),
six.b(''),
resp.content))
if auto_pull:
# The first response returns "<wsman:Items>"

Loading…
Cancel
Save