summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Stanacar <stefanx.stanacar@intel.com>2013-11-03 14:27:16 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-11-08 17:25:36 +0000
commit1e16634af63a49c3a59335e47d96691ff4df2a7a (patch)
tree1f5075d4b68aa30bea2bc2cae1bd98396f09a5c2
parent26559c581695f60861483691e08eee06f524287f (diff)
downloadpoky-1e16634af63a49c3a59335e47d96691ff4df2a7a.tar.gz
lib/oeqa/utils: sshcontrol: make timeout depend on output
Instead of running the commands with a fixed timeout, we should kill the command if there is no output for timeout seconds. Also changed some strings/comments. (From OE-Core rev: beea86fa9637fd629719980e14beea758847b8f3) Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/utils/sshcontrol.py41
1 files changed, 27 insertions, 14 deletions
diff --git a/meta/lib/oeqa/utils/sshcontrol.py b/meta/lib/oeqa/utils/sshcontrol.py
index 1539ff2a37..07257b8948 100644
--- a/meta/lib/oeqa/utils/sshcontrol.py
+++ b/meta/lib/oeqa/utils/sshcontrol.py
@@ -9,6 +9,7 @@
9import subprocess 9import subprocess
10import time 10import time
11import os 11import os
12import select
12 13
13class SSHControl(object): 14class SSHControl(object):
14 15
@@ -50,32 +51,44 @@ class SSHControl(object):
50 if self.host: 51 if self.host:
51 sshconn = self._internal_run(cmd) 52 sshconn = self._internal_run(cmd)
52 else: 53 else:
53 raise Exception("Remote IP hasn't been set: '%s'" % actualcmd) 54 raise Exception("Remote IP/host hasn't been set, I can't run ssh without one.")
54 55
56 # run the command forever
55 if timeout == 0: 57 if timeout == 0:
56 self._out = sshconn.communicate()[0] 58 output = sshconn.communicate()[0]
57 self._ret = sshconn.poll()
58 else: 59 else:
60 # use the default timeout
59 if timeout is None: 61 if timeout is None:
60 tdelta = self.timeout 62 tdelta = self.timeout
63 # use the specified timeout
61 else: 64 else:
62 tdelta = timeout 65 tdelta = timeout
63 endtime = self._starttime + tdelta 66 endtime = self._starttime + tdelta
64 while sshconn.poll() is None and time.time() < endtime: 67 output = ''
65 time.sleep(1) 68 eof = False
69 while time.time() < endtime and not eof:
70 if select.select([sshconn.stdout], [], [], 5)[0] != []:
71 data = os.read(sshconn.stdout.fileno(), 1024)
72 if not data:
73 sshconn.stdout.close()
74 eof = True
75 else:
76 output += data
77 endtime = time.time() + tdelta
78
66 # process hasn't returned yet 79 # process hasn't returned yet
67 if sshconn.poll() is None: 80 if sshconn.poll() is None:
68 self._ret = 255
69 sshconn.terminate() 81 sshconn.terminate()
70 sshconn.kill() 82 time.sleep(3)
71 self._out = sshconn.stdout.read() 83 try:
72 sshconn.stdout.close() 84 sshconn.kill()
73 self._out += "\n[!!! SSH command timed out after %d seconds and it was killed]" % tdelta 85 except OSError:
74 else: 86 pass
75 self._out = sshconn.stdout.read() 87 output += "\n[!!! SSH command killed - no output for %d seconds. Total running time: %d seconds." % (tdelta, time.time() - self._starttime)
76 self._ret = sshconn.poll() 88
89 self._ret = sshconn.poll()
77 # strip the last LF so we can test the output 90 # strip the last LF so we can test the output
78 self._out = self._out.rstrip() 91 self._out = output.rstrip()
79 self.log("%s" % self._out) 92 self.log("%s" % self._out)
80 self.log("[SSH command returned after %d seconds]: %s" % (time.time() - self._starttime, self._ret)) 93 self.log("[SSH command returned after %d seconds]: %s" % (time.time() - self._starttime, self._ret))
81 return (self._ret, self._out) 94 return (self._ret, self._out)