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
This commit is contained in:
parent
413bfce123
commit
0de8b41768
@ -19,6 +19,7 @@ import lxml.objectify
|
|||||||
import mock
|
import mock
|
||||||
import requests.exceptions
|
import requests.exceptions
|
||||||
import requests_mock
|
import requests_mock
|
||||||
|
import six
|
||||||
|
|
||||||
from dracclient import exceptions
|
from dracclient import exceptions
|
||||||
from dracclient.tests import base
|
from dracclient.tests import base
|
||||||
@ -55,6 +56,14 @@ class ClientTestCase(base.BaseTest):
|
|||||||
self.assertRaises(exceptions.WSManInvalidResponse,
|
self.assertRaises(exceptions.WSManInvalidResponse,
|
||||||
self.client.enumerate, 'resource')
|
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()
|
@requests_mock.Mocker()
|
||||||
def test_enumerate_with_auto_pull(self, mock_requests):
|
def test_enumerate_with_auto_pull(self, mock_requests):
|
||||||
mock_requests.post(
|
mock_requests.post(
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
import six
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@ -157,7 +159,14 @@ class Client(object):
|
|||||||
filter_query, filter_dialect)
|
filter_query, filter_dialect)
|
||||||
|
|
||||||
resp = self._do_request(payload)
|
resp = self._do_request(payload)
|
||||||
|
try:
|
||||||
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]'),
|
||||||
|
six.b(''),
|
||||||
|
resp.content))
|
||||||
|
|
||||||
if auto_pull:
|
if auto_pull:
|
||||||
# The first response returns "<wsman:Items>"
|
# The first response returns "<wsman:Items>"
|
||||||
|
Loading…
Reference in New Issue
Block a user