summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorStefan Stanacar <stefanx.stanacar@intel.com>2013-09-19 15:36:15 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-09-22 12:19:33 +0100
commitf3ab2fc731e5e64e2408eefd6b255a2714c44c30 (patch)
treeadda0229aa9a9714b5c4765bbd5960354074d199 /meta/lib
parentcb2496c607016e4d89af9ff0ef51bcea0701bd53 (diff)
downloadpoky-f3ab2fc731e5e64e2408eefd6b255a2714c44c30.tar.gz
lib/oeqa/utils: sshcontrol: log how long the last command take
It might be useful for debugging to have in the ssh log the number of seconds a command has run. (From OE-Core rev: 48b9e45b9716130b015ae2ab7398d6aa243933dc) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oeqa/utils/sshcontrol.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/meta/lib/oeqa/utils/sshcontrol.py b/meta/lib/oeqa/utils/sshcontrol.py
index 643d0ad362..1539ff2a37 100644
--- a/meta/lib/oeqa/utils/sshcontrol.py
+++ b/meta/lib/oeqa/utils/sshcontrol.py
@@ -15,6 +15,7 @@ class SSHControl(object):
15 def __init__(self, host=None, timeout=300, logfile=None): 15 def __init__(self, host=None, timeout=300, logfile=None):
16 self.host = host 16 self.host = host
17 self.timeout = timeout 17 self.timeout = timeout
18 self._starttime = None
18 self._out = '' 19 self._out = ''
19 self._ret = 126 20 self._ret = 126
20 self.logfile = logfile 21 self.logfile = logfile
@@ -35,6 +36,7 @@ class SSHControl(object):
35 cmd = ". /etc/profile; " + cmd 36 cmd = ". /etc/profile; " + cmd
36 command = self.ssh + [self.host, cmd] 37 command = self.ssh + [self.host, cmd]
37 self.log("[Running]$ %s" % " ".join(command)) 38 self.log("[Running]$ %s" % " ".join(command))
39 self._starttime = time.time()
38 # ssh hangs without os.setsid 40 # ssh hangs without os.setsid
39 proc = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid) 41 proc = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid)
40 return proc 42 return proc
@@ -58,7 +60,7 @@ class SSHControl(object):
58 tdelta = self.timeout 60 tdelta = self.timeout
59 else: 61 else:
60 tdelta = timeout 62 tdelta = timeout
61 endtime = time.time() + tdelta 63 endtime = self._starttime + tdelta
62 while sshconn.poll() is None and time.time() < endtime: 64 while sshconn.poll() is None and time.time() < endtime:
63 time.sleep(1) 65 time.sleep(1)
64 # process hasn't returned yet 66 # process hasn't returned yet
@@ -69,23 +71,24 @@ class SSHControl(object):
69 self._out = sshconn.stdout.read() 71 self._out = sshconn.stdout.read()
70 sshconn.stdout.close() 72 sshconn.stdout.close()
71 self._out += "\n[!!! SSH command timed out after %d seconds and it was killed]" % tdelta 73 self._out += "\n[!!! SSH command timed out after %d seconds and it was killed]" % tdelta
72 self.log("[!!! SSH command timed out after %d seconds and it was killed]" % tdelta)
73 else: 74 else:
74 self._out = sshconn.stdout.read() 75 self._out = sshconn.stdout.read()
75 self._ret = sshconn.poll() 76 self._ret = sshconn.poll()
76 # strip the last LF so we can test the output 77 # strip the last LF so we can test the output
77 self._out = self._out.rstrip() 78 self._out = self._out.rstrip()
78 self.log("%s" % self._out) 79 self.log("%s" % self._out)
79 self.log("[SSH command returned]: %s" % self._ret) 80 self.log("[SSH command returned after %d seconds]: %s" % (time.time() - self._starttime, self._ret))
80 return (self._ret, self._out) 81 return (self._ret, self._out)
81 82
82 def _internal_scp(self, cmd): 83 def _internal_scp(self, cmd):
83 cmd = ['scp'] + self.ssh_options + cmd 84 cmd = ['scp'] + self.ssh_options + cmd
84 self.log("[Running SCP]$ %s" % " ".join(cmd)) 85 self.log("[Running SCP]$ %s" % " ".join(cmd))
86 self._starttime = time.time()
85 scpconn = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid) 87 scpconn = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid)
86 out = scpconn.communicate()[0] 88 out = scpconn.communicate()[0]
87 ret = scpconn.poll() 89 ret = scpconn.poll()
88 self.log("%s" % out) 90 self.log("%s" % out)
91 self.log("[SCP command returned after %d seconds]: %s" % (time.time() - self._starttime, ret))
89 if ret != 0: 92 if ret != 0:
90 # we raise an exception so that tests fail in setUp and setUpClass without a need for an assert 93 # we raise an exception so that tests fail in setUp and setUpClass without a need for an assert
91 raise Exception("Error running %s, output: %s" % ( " ".join(cmd), out)) 94 raise Exception("Error running %s, output: %s" % ( " ".join(cmd), out))