Skip to content

Commit

Permalink
network_cli (libssh): Don't repeat previous response windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Mar 1, 2023
1 parent 4bd105c commit fa11dbe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions changelogs/fragments/libssh-repeated-text.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
bugfixes:
- network_cli - when receiving longer responses with libssh, parts of the
response were sometimes repeated. The response is now returned as it is
received (https://github.com/ansible-collections/community.routeros/issues/132).
2 changes: 1 addition & 1 deletion plugins/connection/network_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ def receive_libssh(
if errored_response:
raise AnsibleConnectionFailure(errored_response)
self._last_response = data
self._command_response += self._sanitize(
self._command_response = self._sanitize(
resp, command, strip_prompt
)
command_prompt_matched = True
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/plugins/connection/test_network_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ def test_network_cli_exec_command(conn, command):
@pytest.mark.parametrize(
"response",
[
b"device#command\ncommand response\n\ndevice#",
[b"device#command\ncommand response\n\ndevice#"],
[b"device#command\ncommand ", b"response\n\ndevice#"],
pytest.param(
b"ERROR: error message device#",
[b"ERROR: error message device#"],
marks=pytest.mark.xfail(raises=AnsibleConnectionFailure),
),
],
Expand All @@ -181,9 +182,9 @@ def test_network_cli_send(conn, response, ssh_type):
conn._connected = True

if conn.ssh_type == "paramiko":
mock__shell.recv.side_effect = [response, None]
mock__shell.recv.side_effect = [*response, None]
elif conn.ssh_type == "libssh":
mock__shell.read_bulk_response.side_effect = [response, None]
mock__shell.read_bulk_response.side_effect = [*response, None]
conn.send(b"command")

mock__shell.sendall.assert_called_with(b"command\r")
Expand Down

0 comments on commit fa11dbe

Please sign in to comment.