diff --git a/changelogs/fragments/libssh-repeated-text.yaml b/changelogs/fragments/libssh-repeated-text.yaml new file mode 100644 index 000000000..ec29067b8 --- /dev/null +++ b/changelogs/fragments/libssh-repeated-text.yaml @@ -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). diff --git a/plugins/connection/network_cli.py b/plugins/connection/network_cli.py index 466d6285a..800b988b8 100644 --- a/plugins/connection/network_cli.py +++ b/plugins/connection/network_cli.py @@ -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 diff --git a/tests/unit/plugins/connection/test_network_cli.py b/tests/unit/plugins/connection/test_network_cli.py index 131fc1cd8..075885d73 100644 --- a/tests/unit/plugins/connection/test_network_cli.py +++ b/tests/unit/plugins/connection/test_network_cli.py @@ -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), ), ], @@ -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")