summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorStefan Stanacar <stefanx.stanacar@intel.com>2014-04-25 14:35:27 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-04-29 17:20:12 +0100
commit2b822a8458fe904626045c7e9e0291de806e31c1 (patch)
tree01d18ac35bee42980e7b8a0f9cf1563a1902ed4d /meta
parentbdb07c66c8017ec3804b81dd3791fad1b976d95a (diff)
downloadpoky-2b822a8458fe904626045c7e9e0291de806e31c1.tar.gz
oeqa/utils: sshcontrol: realtime logging of output
Log the output of the command as it runs not when it finished, else tail -f tmp/work/minnow-poky-linux/core-image-sato/1.0-r0/testimage/ssh_target_log isn't as useful as it could be. (From OE-Core rev: be8f766f43d85c364b9706b464ed0a59d0fbf0b7) 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>
Diffstat (limited to 'meta')
-rw-r--r--meta/lib/oeqa/utils/sshcontrol.py19
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: