Skip to content

Commit

Permalink
network_cli - ansible_command_timeout not working as expected (ansibl…
Browse files Browse the repository at this point in the history
…e#49922)

* fix for command_timeout

Signed-off-by: Deepak Agrawal <[email protected]>

* fix ci warning

Signed-off-by: Deepak Agrawal <[email protected]>

* fix review comments

Signed-off-by: Deepak Agrawal <[email protected]>
  • Loading branch information
gdpak authored Dec 17, 2018
1 parent 134c1a6 commit 0f2f38b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/ansible/plugins/connection/network_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,11 @@ def receive(self, command=None, prompts=None, answer=None, newline=True, prompt_
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")
Expand All @@ -393,6 +396,8 @@ def receive(self, command=None, prompts=None, answer=None, newline=True, prompt_
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)
Expand Down Expand Up @@ -423,6 +428,8 @@ def receive(self, command=None, prompts=None, answer=None, newline=True, prompt_
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
Expand All @@ -445,7 +452,8 @@ def send(self, command, prompt=None, answer=None, newline=True, sendonly=False,
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"
Expand Down

0 comments on commit 0f2f38b

Please sign in to comment.