Skip to content
Snippets Groups Projects
Commit a0db555e authored by Chris Hines's avatar Chris Hines
Browse files

put a timeout on executing things via ssh

parent ad1f596a
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ This module handles SSH Connections ...@@ -3,6 +3,7 @@ This module handles SSH Connections
""" """
import subprocess import subprocess
TIMEOUT=10
class SshAgentException(Exception): class SshAgentException(Exception):
""" """
Raised if an SSH Agent isn't running (Normally the SPA client should invoke the agent Raised if an SSH Agent isn't running (Normally the SPA client should invoke the agent
...@@ -270,10 +271,15 @@ class Ssh: ...@@ -270,10 +271,15 @@ class Ssh:
'-p', sshport, '-l', user, host, cmd], '-p', sshport, '-l', user, host, cmd],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE, env=env) stdin=subprocess.PIPE, env=env)
if stdin is not None: try:
(stdout, stderr) = exec_p.communicate(stdin.encode()) if stdin is not None:
else: (stdout, stderr) = exec_p.communicate(stdin.encode(),timeout=TIMEOUT)
else:
(stdout, stderr) = exec_p.communicate(timeout=TIMEOUT)
except subprocess.TimeoutExpired:
exec_p.kill()
(stdout, stderr) = exec_p.communicate() (stdout, stderr) = exec_p.communicate()
return {'stdout':stdout, 'stderr':stderr} return {'stdout':stdout, 'stderr':stderr}
@staticmethod @staticmethod
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment