Skip to content

Commit

Permalink
Merge pull request #93 from AxFoundation/command_timeout
Browse files Browse the repository at this point in the history
Catch hypervisor command timeouts
  • Loading branch information
darrylmasson authored Apr 13, 2022
2 parents 6ca2617 + 921a3c5 commit 2101d85
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions dispatcher/hypervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def date_now():


class Hypervisor(object):
__version__ = '4.0.2'
__version__ = '4.0.3'
def __init__(self,
db,
logger,
Expand Down Expand Up @@ -67,7 +67,12 @@ def run_over_ssh(self, address: str, cmd: str, rets: list) -> None:
:returns: None
"""
command = "ssh " + address + ' ' + cmd
cp = subprocess.run(command, shell=True, capture_output=True)
try:
cp = subprocess.run(command, shell=True, capture_output=True, timeout=30)
except subprocess.TimeoutExpired:
self.logger.error(f'Timeout while issuing command to {address}')
rets.append({'retcode': -1, 'stdout': '', 'stderr': ''})
return
ret = {'retcode': cp.returncode,
'stdout': cp.stdout.decode() if cp.stdout else '',
'stderr': cp.stderr.decode() if cp.stderr else ''}
Expand Down

0 comments on commit 2101d85

Please sign in to comment.