Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network_cli (libssh): Don't repeat previous response windows #521

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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