From 0f2f38b044efa1de30a28eefa71882ec189d6a61 Mon Sep 17 00:00:00 2001 From: Deepak Agrawal Date: Mon, 17 Dec 2018 13:26:23 +0530 Subject: [PATCH] network_cli - ansible_command_timeout not working as expected (#49922) * fix for command_timeout Signed-off-by: Deepak Agrawal * fix ci warning Signed-off-by: Deepak Agrawal * fix review comments Signed-off-by: Deepak Agrawal --- lib/ansible/plugins/connection/network_cli.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index eb528c8596..1e07e4d0e3 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -370,8 +370,11 @@ class Connection(NetworkConnectionBase): command_prompt_matched = False matched_prompt_window = window_count = 0 + cache_socket_timeout = self._ssh_shell.gettimeout() command_timeout = self.get_option('persistent_command_timeout') self._validate_timeout_value(command_timeout, "persistent_command_timeout") + if cache_socket_timeout != command_timeout: + self._ssh_shell.settimeout(command_timeout) buffer_read_timeout = self.get_option('persistent_buffer_read_timeout') self._validate_timeout_value(buffer_read_timeout, "persistent_buffer_read_timeout") @@ -393,6 +396,8 @@ class Connection(NetworkConnectionBase): signal.alarm(command_timeout) except AnsibleCmdRespRecv: + # reset socket timeout to global timeout + self._ssh_shell.settimeout(cache_socket_timeout) return self._command_response else: data = self._ssh_shell.recv(256) @@ -423,6 +428,8 @@ class Connection(NetworkConnectionBase): resp = self._strip(self._last_response) self._command_response = self._sanitize(resp, command) if buffer_read_timeout == 0.0: + # reset socket timeout to global timeout + self._ssh_shell.settimeout(cache_socket_timeout) return self._command_response else: command_prompt_matched = True @@ -445,7 +452,8 @@ class Connection(NetworkConnectionBase): return to_text(response, errors='surrogate_or_strict') except (socket.timeout, AttributeError): display.vvvv(traceback.format_exc(), host=self._play_context.remote_addr) - raise AnsibleConnectionFailure("timeout trying to send command: %s" % command.strip()) + raise AnsibleConnectionFailure("timeout value %s seconds reached while trying to send command: %s" + % (self._ssh_shell.gettimeout(), command.strip())) def _handle_buffer_read_timeout(self, signum, frame): display.vvvv("Response received, triggered 'persistent_buffer_read_timeout' timer of %s seconds"