* fix issue #60237 when non-ascii is returned from the WLC * update test to work with python3 through use of six library * remove trailing white space
This commit is contained in:
parent
30cc54da8c
commit
50d1cbd30a
3 changed files with 18 additions and 3 deletions
|
@ -120,12 +120,13 @@ from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.network.common.utils import ComplexList
|
from ansible.module_utils.network.common.utils import ComplexList
|
||||||
from ansible.module_utils.network.common.parsing import Conditional
|
from ansible.module_utils.network.common.parsing import Conditional
|
||||||
from ansible.module_utils.six import string_types
|
from ansible.module_utils.six import string_types
|
||||||
|
from ansible.module_utils._text import to_text
|
||||||
|
|
||||||
|
|
||||||
def to_lines(stdout):
|
def to_lines(stdout):
|
||||||
for item in stdout:
|
for item in stdout:
|
||||||
if isinstance(item, string_types):
|
if isinstance(item, string_types):
|
||||||
item = str(item).split('\n')
|
item = to_text(item, errors='surrogate_then_replace').split('\n')
|
||||||
yield item
|
yield item
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -306,7 +306,6 @@ class Connection(NetworkConnectionBase):
|
||||||
|
|
||||||
def __init__(self, play_context, new_stdin, *args, **kwargs):
|
def __init__(self, play_context, new_stdin, *args, **kwargs):
|
||||||
super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)
|
super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)
|
||||||
|
|
||||||
self._ssh_shell = None
|
self._ssh_shell = None
|
||||||
|
|
||||||
self._matched_prompt = None
|
self._matched_prompt = None
|
||||||
|
@ -582,7 +581,7 @@ class Connection(NetworkConnectionBase):
|
||||||
if sendonly:
|
if sendonly:
|
||||||
return
|
return
|
||||||
response = self.receive(command, prompt, answer, newline, prompt_retry_check, check_all)
|
response = self.receive(command, prompt, answer, newline, prompt_retry_check, check_all)
|
||||||
return to_text(response, errors='surrogate_or_strict')
|
return to_text(response, errors='surrogate_then_replace')
|
||||||
except (socket.timeout, AttributeError):
|
except (socket.timeout, AttributeError):
|
||||||
self.queue_message('error', traceback.format_exc())
|
self.queue_message('error', traceback.format_exc())
|
||||||
raise AnsibleConnectionFailure("timeout value %s seconds reached while trying to send command: %s"
|
raise AnsibleConnectionFailure("timeout value %s seconds reached while trying to send command: %s"
|
||||||
|
|
|
@ -25,6 +25,7 @@ from units.compat.mock import patch
|
||||||
from ansible.modules.network.aireos import aireos_command
|
from ansible.modules.network.aireos import aireos_command
|
||||||
from units.modules.utils import set_module_args
|
from units.modules.utils import set_module_args
|
||||||
from .aireos_module import TestCiscoWlcModule, load_fixture
|
from .aireos_module import TestCiscoWlcModule, load_fixture
|
||||||
|
from ansible.module_utils import six
|
||||||
|
|
||||||
|
|
||||||
class TestCiscoWlcCommandModule(TestCiscoWlcModule):
|
class TestCiscoWlcCommandModule(TestCiscoWlcModule):
|
||||||
|
@ -105,3 +106,17 @@ class TestCiscoWlcCommandModule(TestCiscoWlcModule):
|
||||||
commands = ['show sysinfo', 'show sysinfo']
|
commands = ['show sysinfo', 'show sysinfo']
|
||||||
set_module_args(dict(commands=commands, wait_for=wait_for, match='all'))
|
set_module_args(dict(commands=commands, wait_for=wait_for, match='all'))
|
||||||
self.execute_module(failed=True)
|
self.execute_module(failed=True)
|
||||||
|
|
||||||
|
def test_aireos_command_to_lines_non_ascii(self):
|
||||||
|
''' Test data is one variation of the result of a `show run-config commands`
|
||||||
|
command on Cisco WLC version 8.8.120.0 '''
|
||||||
|
test_data = '''
|
||||||
|
wlan flexconnect learn-ipaddr 101 enable
|
||||||
|
`\xc8\x92\xef\xbf\xbdR\x7f`\xc8\x92\xef\xbf\xbdR\x7f`
|
||||||
|
wlan wgb broadcast-tagging disable 1
|
||||||
|
'''.strip()
|
||||||
|
test_string = six.u(test_data)
|
||||||
|
test_stdout = [test_string, ]
|
||||||
|
result = list(aireos_command.to_lines(test_stdout))
|
||||||
|
print(result[0])
|
||||||
|
self.assertEqual(len(result[0]), 3)
|
||||||
|
|
Loading…
Reference in a new issue