mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
adds timeout check when network_cli run without persistence (#20299)
* checks if signal hander is set and sets it if not (will be set if coming from ansible-connection) * will now timeout long running commands based on DEFAULT_TIMEOUT setting
This commit is contained in:
parent
312328e22c
commit
2c197343f3
1 changed files with 7 additions and 0 deletions
|
@ -24,6 +24,7 @@ import json
|
||||||
import signal
|
import signal
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from ansible import constants as C
|
||||||
from ansible.errors import AnsibleConnectionFailure
|
from ansible.errors import AnsibleConnectionFailure
|
||||||
from ansible.module_utils.six.moves import StringIO
|
from ansible.module_utils.six.moves import StringIO
|
||||||
from ansible.plugins import terminal_loader
|
from ansible.plugins import terminal_loader
|
||||||
|
@ -203,6 +204,7 @@ class Connection(_Connection):
|
||||||
|
|
||||||
def alarm_handler(self, signum, frame):
|
def alarm_handler(self, signum, frame):
|
||||||
"""Alarm handler raised in case of command timeout """
|
"""Alarm handler raised in case of command timeout """
|
||||||
|
display.debug('alarm_handler fired!')
|
||||||
self.close_shell()
|
self.close_shell()
|
||||||
|
|
||||||
def exec_command(self, cmd):
|
def exec_command(self, cmd):
|
||||||
|
@ -242,7 +244,12 @@ class Connection(_Connection):
|
||||||
return (1, '', str(exc))
|
return (1, '', str(exc))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if not signal.getsignal(signal.SIGALRM):
|
||||||
|
display.debug('setting alarm handler in network_cli')
|
||||||
|
signal.signal(signal.SIGALRM, self.alarm_handler)
|
||||||
|
signal.alarm(C.DEFAULT_TIMEOUT)
|
||||||
out = self.send(obj)
|
out = self.send(obj)
|
||||||
|
signal.alarm(0)
|
||||||
return (0, out, '')
|
return (0, out, '')
|
||||||
except (AnsibleConnectionFailure, ValueError) as exc:
|
except (AnsibleConnectionFailure, ValueError) as exc:
|
||||||
return (1, '', str(exc))
|
return (1, '', str(exc))
|
||||||
|
|
Loading…
Reference in a new issue