summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils/sshcontrol.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/utils/sshcontrol.py')
-rw-r--r--meta/lib/oeqa/utils/sshcontrol.py40
1 files changed, 17 insertions, 23 deletions
diff --git a/meta/lib/oeqa/utils/sshcontrol.py b/meta/lib/oeqa/utils/sshcontrol.py
index 85a09a026f..6c61caa908 100644
--- a/meta/lib/oeqa/utils/sshcontrol.py
+++ b/meta/lib/oeqa/utils/sshcontrol.py
@@ -1,7 +1,6 @@
1import subprocess 1import subprocess
2import time 2import time
3import os 3import os
4import shlex
5 4
6class SSHControl(object): 5class SSHControl(object):
7 6
@@ -18,8 +17,12 @@ class SSHControl(object):
18 f.write("%s\n" % msg) 17 f.write("%s\n" % msg)
19 18
20 def _internal_run(self, cmd): 19 def _internal_run(self, cmd):
20 # We need this for a proper PATH
21 cmd = ". /etc/profile; " + cmd
22 command = ['ssh', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', '-l', 'root', self.host, cmd ]
23 self.log("[Running]$ %s" % " ".join(command))
21 # ssh hangs without os.setsid 24 # ssh hangs without os.setsid
22 proc = subprocess.Popen(shlex.split(cmd), shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid) 25 proc = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid)
23 return proc 26 return proc
24 27
25 def run(self, cmd, timeout=None): 28 def run(self, cmd, timeout=None):
@@ -30,15 +33,12 @@ class SSHControl(object):
30 33
31 34
32 35
33 actualcmd = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root %s '%s'" % (self.host, cmd)
34 if self.host: 36 if self.host:
35 sshconn = self._internal_run(actualcmd) 37 sshconn = self._internal_run(cmd)
36 else: 38 else:
37 raise Exception("Remote IP hasn't been set: '%s'" % actualcmd) 39 raise Exception("Remote IP hasn't been set: '%s'" % actualcmd)
38 40
39 if timeout == 0: 41 if timeout == 0:
40 self.log("[SSH run without timeout]$ %s" % actualcmd)
41 self.log(" # %s" % cmd)
42 self._out = sshconn.communicate()[0] 42 self._out = sshconn.communicate()[0]
43 self._ret = sshconn.poll() 43 self._ret = sshconn.poll()
44 else: 44 else:
@@ -48,8 +48,6 @@ class SSHControl(object):
48 endtime = time.time() + timeout 48 endtime = time.time() + timeout
49 while sshconn.poll() is None and time.time() < endtime: 49 while sshconn.poll() is None and time.time() < endtime:
50 time.sleep(1) 50 time.sleep(1)
51 self.log("[SSH run with timeout]$ %s" % actualcmd)
52 self.log(" # %s" % cmd)
53 # process hasn't returned yet 51 # process hasn't returned yet
54 if sshconn.poll() is None: 52 if sshconn.poll() is None:
55 self._ret = 255 53 self._ret = 255
@@ -70,27 +68,23 @@ class SSHControl(object):
70 return (self._ret, self._out) 68 return (self._ret, self._out)
71 69
72 def _internal_scp(self, cmd): 70 def _internal_scp(self, cmd):
73 self.log("[SCP]$ %s" % cmd) 71 self.log("[Running SCP]$ %s" % " ".join(cmd))
74 scpconn = self._internal_run(cmd) 72 scpconn = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid)
75 try: 73 out = scpconn.communicate()[0]
76 self._out = scpconn.communicate()[0] 74 ret = scpconn.poll()
77 self._ret = scpconn.poll() 75 self.log("%s" % out)
78 if self._ret != 0: 76 if ret != 0:
79 self.log("%s" % self._out) 77 # we raise an exception so that tests fail in setUp and setUpClass without a need for an assert
80 raise Exception("Error copying file") 78 raise Exception("Error running %s, output: %s" % ( " ".join(cmd), out))
81 except Exception as e: 79 return (ret, out)
82 print("Execution failed: %s :" % cmd)
83 print e
84 self.log("%s" % self._out)
85 return (self._ret, self._out)
86 80
87 def copy_to(self, localpath, remotepath): 81 def copy_to(self, localpath, remotepath):
88 actualcmd = "scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no %s root@%s:%s" % (localpath, self.host, remotepath) 82 actualcmd = ['scp', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', localpath, 'root@%s:%s' % (self.host, remotepath)]
89 return self._internal_scp(actualcmd) 83 return self._internal_scp(actualcmd)
90 84
91 85
92 def copy_from(self, remotepath, localpath): 86 def copy_from(self, remotepath, localpath):
93 actualcmd = "scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@%s:%s %s" % (self.host, remotepath, localpath) 87 actualcmd = ['scp', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'root@%s:%s' % (self.host, remotepath), localpath]
94 return self._internal_scp(actualcmd) 88 return self._internal_scp(actualcmd)
95 89
96 def get_status(self): 90 def get_status(self):