network_cli - ansible_command_timeout not working as expected (#49922)
* fix for command_timeout Signed-off-by: Deepak Agrawal <deepacks@gmail.com> * fix ci warning Signed-off-by: Deepak Agrawal <deepacks@gmail.com> * fix review comments Signed-off-by: Deepak Agrawal <deepacks@gmail.com>
This commit is contained in:
parent
134c1a624e
commit
0f2f38b044
1 changed files with 9 additions and 1 deletions
|
@ -370,8 +370,11 @@ class Connection(NetworkConnectionBase):
|
||||||
command_prompt_matched = False
|
command_prompt_matched = False
|
||||||
matched_prompt_window = window_count = 0
|
matched_prompt_window = window_count = 0
|
||||||
|
|
||||||
|
cache_socket_timeout = self._ssh_shell.gettimeout()
|
||||||
command_timeout = self.get_option('persistent_command_timeout')
|
command_timeout = self.get_option('persistent_command_timeout')
|
||||||
self._validate_timeout_value(command_timeout, "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')
|
buffer_read_timeout = self.get_option('persistent_buffer_read_timeout')
|
||||||
self._validate_timeout_value(buffer_read_timeout, "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)
|
signal.alarm(command_timeout)
|
||||||
|
|
||||||
except AnsibleCmdRespRecv:
|
except AnsibleCmdRespRecv:
|
||||||
|
# reset socket timeout to global timeout
|
||||||
|
self._ssh_shell.settimeout(cache_socket_timeout)
|
||||||
return self._command_response
|
return self._command_response
|
||||||
else:
|
else:
|
||||||
data = self._ssh_shell.recv(256)
|
data = self._ssh_shell.recv(256)
|
||||||
|
@ -423,6 +428,8 @@ class Connection(NetworkConnectionBase):
|
||||||
resp = self._strip(self._last_response)
|
resp = self._strip(self._last_response)
|
||||||
self._command_response = self._sanitize(resp, command)
|
self._command_response = self._sanitize(resp, command)
|
||||||
if buffer_read_timeout == 0.0:
|
if buffer_read_timeout == 0.0:
|
||||||
|
# reset socket timeout to global timeout
|
||||||
|
self._ssh_shell.settimeout(cache_socket_timeout)
|
||||||
return self._command_response
|
return self._command_response
|
||||||
else:
|
else:
|
||||||
command_prompt_matched = True
|
command_prompt_matched = True
|
||||||
|
@ -445,7 +452,8 @@ class Connection(NetworkConnectionBase):
|
||||||
return to_text(response, errors='surrogate_or_strict')
|
return to_text(response, errors='surrogate_or_strict')
|
||||||
except (socket.timeout, AttributeError):
|
except (socket.timeout, AttributeError):
|
||||||
display.vvvv(traceback.format_exc(), host=self._play_context.remote_addr)
|
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):
|
def _handle_buffer_read_timeout(self, signum, frame):
|
||||||
display.vvvv("Response received, triggered 'persistent_buffer_read_timeout' timer of %s seconds"
|
display.vvvv("Response received, triggered 'persistent_buffer_read_timeout' timer of %s seconds"
|
||||||
|
|
Loading…
Reference in a new issue