Fix prompt mismatch issue for ios (#47004)

* Fix prompt mismatch issue for ios

Fixes #40884 #44463

*  If the command prompt is matched check if data is
   still pending to be read from buffer.
*  This fix adds a new timer `buffer_read_timeout`
   which will be trigerred after command prompt
   is matched and data is attempted to be read from channel.
   If not data is present of channel the timer will expire
   and response we be returned to calling function.

* Fix unit test failure

* Update to make buffer timeout float

* Update doc and fix review comment

* Fix CI issues

* Update doc

* Fix review comments

* Fix review comments
This commit is contained in:
Ganesh Nalawade 2018-10-22 21:05:15 +05:30 committed by GitHub
commit 335a979f1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 109 additions and 9 deletions

View file

@ -21,6 +21,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import re
import time
import json
from io import StringIO
@ -28,6 +29,7 @@ from io import StringIO
from units.compat import unittest
from units.compat.mock import patch, MagicMock
from ansible.module_utils._text import to_text
from ansible.errors import AnsibleConnectionFailure
from ansible.playbook.play_context import PlayContext
from ansible.plugins.loader import connection_loader
@ -131,15 +133,14 @@ class TestConnectionClass(unittest.TestCase):
device#
"""
mock__shell.recv.return_value = response
mock__shell.recv.side_effect = [response, None]
output = conn.send(b'command', None, None, None)
mock__shell.sendall.assert_called_with(b'command\r')
self.assertEqual(output, 'command response')
self.assertEqual(to_text(conn._command_response), 'command response')
mock__shell.reset_mock()
mock__shell.recv.return_value = b"ERROR: error message device#"
mock__shell.recv.side_effect = [b"ERROR: error message device#"]
with self.assertRaises(AnsibleConnectionFailure) as exc:
conn.send(b'command', None, None, None)