diff options
-rw-r--r-- | meta/lib/oeqa/utils/sshcontrol.py | 41 |
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 @@ | |||
9 | import subprocess | 9 | import subprocess |
10 | import time | 10 | import time |
11 | import os | 11 | import os |
12 | import select | ||
12 | 13 | ||
13 | class SSHControl(object): | 14 | class 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) |