diff options
author | Stefan Stanacar <stefanx.stanacar@intel.com> | 2013-07-09 17:52:55 +0300 |
---|---|---|
committer | Saul Wold <sgw@linux.intel.com> | 2013-07-15 10:29:26 -0700 |
commit | 1988de2fad86e8e34070ed6573a7be09fff5c0a2 (patch) | |
tree | 9b2d9d38fbd06121e570c089bcd8f375899e2bb5 /meta/lib | |
parent | c072fed6531f2ce3c687f8342a97f593ebf37653 (diff) | |
download | openembedded-core-1988de2fad86e8e34070ed6573a7be09fff5c0a2.tar.gz openembedded-core-1988de2fad86e8e34070ed6573a7be09fff5c0a2.tar.bz2 openembedded-core-1988de2fad86e8e34070ed6573a7be09fff5c0a2.zip |
lib/oeqa/utils/sshcontrol.py: fix passing command to subprocess
Don't use shlex.split in subprocess call and also prepend
. /etc/profile, because PATH over ssh is always
/usr/bin:/bin which isn't what many tests expect.
Changed in v2:
We now need to use a separate call for scp command.
Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oeqa/utils/sshcontrol.py | 40 |
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 @@ import subprocess import time import os -import shlex class SSHControl(object): @@ -18,8 +17,12 @@ class SSHControl(object): f.write("%s\n" % msg) def _internal_run(self, cmd): + # We need this for a proper PATH + cmd = ". /etc/profile; " + cmd + command = ['ssh', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', '-l', 'root', self.host, cmd ] + self.log("[Running]$ %s" % " ".join(command)) # ssh hangs without os.setsid - proc = subprocess.Popen(shlex.split(cmd), shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid) + proc = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid) return proc def run(self, cmd, timeout=None): @@ -30,15 +33,12 @@ class SSHControl(object): - actualcmd = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root %s '%s'" % (self.host, cmd) if self.host: - sshconn = self._internal_run(actualcmd) + sshconn = self._internal_run(cmd) else: raise Exception("Remote IP hasn't been set: '%s'" % actualcmd) if timeout == 0: - self.log("[SSH run without timeout]$ %s" % actualcmd) - self.log(" # %s" % cmd) self._out = sshconn.communicate()[0] self._ret = sshconn.poll() else: @@ -48,8 +48,6 @@ class SSHControl(object): endtime = time.time() + timeout while sshconn.poll() is None and time.time() < endtime: time.sleep(1) - self.log("[SSH run with timeout]$ %s" % actualcmd) - self.log(" # %s" % cmd) # process hasn't returned yet if sshconn.poll() is None: self._ret = 255 @@ -70,27 +68,23 @@ class SSHControl(object): return (self._ret, self._out) def _internal_scp(self, cmd): - self.log("[SCP]$ %s" % cmd) - scpconn = self._internal_run(cmd) - try: - self._out = scpconn.communicate()[0] - self._ret = scpconn.poll() - if self._ret != 0: - self.log("%s" % self._out) - raise Exception("Error copying file") - except Exception as e: - print("Execution failed: %s :" % cmd) - print e - self.log("%s" % self._out) - return (self._ret, self._out) + self.log("[Running SCP]$ %s" % " ".join(cmd)) + scpconn = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid) + out = scpconn.communicate()[0] + ret = scpconn.poll() + self.log("%s" % out) + if ret != 0: + # we raise an exception so that tests fail in setUp and setUpClass without a need for an assert + raise Exception("Error running %s, output: %s" % ( " ".join(cmd), out)) + return (ret, out) def copy_to(self, localpath, remotepath): - actualcmd = "scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no %s root@%s:%s" % (localpath, self.host, remotepath) + actualcmd = ['scp', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', localpath, 'root@%s:%s' % (self.host, remotepath)] return self._internal_scp(actualcmd) def copy_from(self, remotepath, localpath): - actualcmd = "scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@%s:%s %s" % (self.host, remotepath, localpath) + actualcmd = ['scp', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'root@%s:%s' % (self.host, remotepath), localpath] return self._internal_scp(actualcmd) def get_status(self): |