Fix persistent command timeout handling (#34791)

* Fix persistent command timeout handling

We were using play context timeout on ansible-connect to set
the persistent command timeout handler. Thus, we were ignoring
the persistent_command_timeout setting.
Moreover, even by changing that on ansible-connection, were again
overriding it on cliconf send_command, since in a same process we can
just set a single alarm and cliconf send_command alarm setup is executed
after ansible-connection alarm setup.

* Remove alarm setting on cliconf send_command

The alarm is set regardless before it is executed by ansible-connection.
Setting an alarm again, overrides/disables the previous ones as a single
process can just have a single alarm set.

* Move the setting of persistent command timeout to network_cli

We do also use ansible-connection for connection local, so if a
user provides a timeout via provider that would be ignored if we
set the value on ansible-connection.
Moving that logic to network_cli plugin constructor makes both
connections to work.

* Remove debug statements

* Set the persistent command timeout on task_executor

We can't set the timeout on ansible-connection nor network_cli,
otherwise tasks using provider timeout won't work.
This commit is contained in:
Ricardo Carrillo Cruz 2018-01-13 15:54:44 +01:00 committed by GitHub
parent c548ab0f18
commit a56de25df5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 4 deletions

View file

@ -743,6 +743,7 @@ class TaskExecutor:
self._play_context.set_options_from_plugin(connection) self._play_context.set_options_from_plugin(connection)
if any(((connection.supports_persistence and C.USE_PERSISTENT_CONNECTIONS), connection.force_persistence)): if any(((connection.supports_persistence and C.USE_PERSISTENT_CONNECTIONS), connection.force_persistence)):
self._play_context.timeout = C.PERSISTENT_COMMAND_TIMEOUT
display.vvvv('attempting to start connection', host=self._play_context.remote_addr) display.vvvv('attempting to start connection', host=self._play_context.remote_addr)
display.vvvv('using connection plugin %s' % connection.transport, host=self._play_context.remote_addr) display.vvvv('using connection plugin %s' % connection.transport, host=self._play_context.remote_addr)
socket_path = self._start_connection() socket_path = self._start_connection()

View file

@ -106,11 +106,7 @@ class CliconfBase(with_metaclass(ABCMeta, object)):
if answer is not None: if answer is not None:
kwargs['answer'] = to_bytes(answer) kwargs['answer'] = to_bytes(answer)
if not signal.getsignal(signal.SIGALRM):
signal.signal(signal.SIGALRM, self._alarm_handler)
signal.alarm(self._connection._play_context.timeout)
resp = self._connection.send(**kwargs) resp = self._connection.send(**kwargs)
signal.alarm(0)
return resp return resp
def get_base_rpc(self): def get_base_rpc(self):