diff options
-rw-r--r-- | meta/lib/oeqa/utils/sshcontrol.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/meta/lib/oeqa/utils/sshcontrol.py b/meta/lib/oeqa/utils/sshcontrol.py index d355d5e8e9..1c81795a87 100644 --- a/meta/lib/oeqa/utils/sshcontrol.py +++ b/meta/lib/oeqa/utils/sshcontrol.py | |||
@@ -29,8 +29,15 @@ class SSHProcess(object): | |||
29 | self.output = None | 29 | self.output = None |
30 | self.process = None | 30 | self.process = None |
31 | self.starttime = None | 31 | self.starttime = None |
32 | self.logfile = None | ||
32 | 33 | ||
33 | def run(self, command, timeout=None): | 34 | def log(self, msg): |
35 | if self.logfile: | ||
36 | with open(self.logfile, "a") as f: | ||
37 | f.write("%s" % msg) | ||
38 | |||
39 | def run(self, command, timeout=None, logfile=None): | ||
40 | self.logfile = logfile | ||
34 | self.starttime = time.time() | 41 | self.starttime = time.time() |
35 | output = '' | 42 | output = '' |
36 | self.process = subprocess.Popen(command, **self.options) | 43 | self.process = subprocess.Popen(command, **self.options) |
@@ -45,8 +52,10 @@ class SSHProcess(object): | |||
45 | eof = True | 52 | eof = True |
46 | else: | 53 | else: |
47 | output += data | 54 | output += data |
55 | self.log(data) | ||
48 | endtime = time.time() + timeout | 56 | endtime = time.time() + timeout |
49 | 57 | ||
58 | |||
50 | # process hasn't returned yet | 59 | # process hasn't returned yet |
51 | if not eof: | 60 | if not eof: |
52 | self.process.terminate() | 61 | self.process.terminate() |
@@ -55,9 +64,12 @@ class SSHProcess(object): | |||
55 | self.process.kill() | 64 | self.process.kill() |
56 | except OSError: | 65 | except OSError: |
57 | pass | 66 | pass |
58 | output += "\nProcess killed - no output for %d seconds. Total running time: %d seconds." % (timeout, time.time() - self.starttime) | 67 | lastline = "\nProcess killed - no output for %d seconds. Total running time: %d seconds." % (timeout, time.time() - self.starttime) |
68 | self.log(lastline) | ||
69 | output += lastline | ||
59 | else: | 70 | else: |
60 | output = self.process.communicate()[0] | 71 | output = self.process.communicate()[0] |
72 | self.log(output.rstrip()) | ||
61 | 73 | ||
62 | self.status = self.process.wait() | 74 | self.status = self.process.wait() |
63 | self.output = output.rstrip() | 75 | self.output = output.rstrip() |
@@ -91,9 +103,8 @@ class SSHControl(object): | |||
91 | self.log("[Running]$ %s" % " ".join(command)) | 103 | self.log("[Running]$ %s" % " ".join(command)) |
92 | 104 | ||
93 | proc = SSHProcess() | 105 | proc = SSHProcess() |
94 | status, output = proc.run(command, timeout) | 106 | status, output = proc.run(command, timeout, logfile=self.logfile) |
95 | 107 | ||
96 | self.log("%s" % output) | ||
97 | self.log("[Command returned '%d' after %.2f seconds]" % (status, time.time() - proc.starttime)) | 108 | self.log("[Command returned '%d' after %.2f seconds]" % (status, time.time() - proc.starttime)) |
98 | 109 | ||
99 | if status and not ignore_status: | 110 | if status and not ignore_status: |