mirror of
https://git.yoctoproject.org/poky
synced 2026-06-01 13:09:50 +00:00
oeqa/utils/sshcontrol: tweak ssh options
Add ssh_options to be used, the same, by ssh and scp: Decrease LogLevel to ERROR, to suppress warnings (e.g. ssh host verifications, two warnings in case of having openssh with hpn patches); We no longer presume that the first line is a warning. (From OE-Core rev: 1f18d04eec03e586134b6d77ca1c6151c22353dd) Signed-off-by: Mihai Lindner <mihaix.lindner@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
f6fed84380
commit
fbb3e5e11f
@@ -6,7 +6,6 @@
|
|||||||
# running commands and copying files to/from a target.
|
# running commands and copying files to/from a target.
|
||||||
# It's used by testimage.bbclass and tests in lib/oeqa/runtime.
|
# It's used by testimage.bbclass and tests in lib/oeqa/runtime.
|
||||||
|
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
@@ -19,6 +18,12 @@ class SSHControl(object):
|
|||||||
self._out = ''
|
self._out = ''
|
||||||
self._ret = 126
|
self._ret = 126
|
||||||
self.logfile = logfile
|
self.logfile = logfile
|
||||||
|
self.ssh_options = [
|
||||||
|
'-o', 'UserKnownHostsFile=/dev/null',
|
||||||
|
'-o', 'StrictHostKeyChecking=no',
|
||||||
|
'-o', 'LogLevel=ERROR'
|
||||||
|
]
|
||||||
|
self.ssh = ['ssh', '-l', 'root'] + self.ssh_options
|
||||||
|
|
||||||
def log(self, msg):
|
def log(self, msg):
|
||||||
if self.logfile:
|
if self.logfile:
|
||||||
@@ -28,7 +33,7 @@ class SSHControl(object):
|
|||||||
def _internal_run(self, cmd):
|
def _internal_run(self, cmd):
|
||||||
# We need this for a proper PATH
|
# We need this for a proper PATH
|
||||||
cmd = ". /etc/profile; " + cmd
|
cmd = ". /etc/profile; " + cmd
|
||||||
command = ['ssh', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', '-l', 'root', self.host, cmd ]
|
command = self.ssh + [self.host, cmd]
|
||||||
self.log("[Running]$ %s" % " ".join(command))
|
self.log("[Running]$ %s" % " ".join(command))
|
||||||
# ssh hangs without os.setsid
|
# ssh hangs without os.setsid
|
||||||
proc = subprocess.Popen(command, 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)
|
||||||
@@ -40,8 +45,6 @@ class SSHControl(object):
|
|||||||
if time is 0 will let cmd run until it finishes.
|
if time is 0 will let cmd run until it finishes.
|
||||||
Time can be passed to here or can be set per class instance."""
|
Time can be passed to here or can be set per class instance."""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if self.host:
|
if self.host:
|
||||||
sshconn = self._internal_run(cmd)
|
sshconn = self._internal_run(cmd)
|
||||||
else:
|
else:
|
||||||
@@ -70,15 +73,14 @@ class SSHControl(object):
|
|||||||
else:
|
else:
|
||||||
self._out = sshconn.stdout.read()
|
self._out = sshconn.stdout.read()
|
||||||
self._ret = sshconn.poll()
|
self._ret = sshconn.poll()
|
||||||
# remove first line from output which is always smth like (unless return code is 255 - which is a ssh error):
|
# strip the last LF so we can test the output
|
||||||
# Warning: Permanently added '192.168.7.2' (RSA) to the list of known hosts.
|
self._out = self._out.rstrip()
|
||||||
if self._ret != 255:
|
|
||||||
self._out = '\n'.join(self._out.splitlines()[1:])
|
|
||||||
self.log("%s" % self._out)
|
self.log("%s" % self._out)
|
||||||
self.log("[SSH command returned]: %s" % self._ret)
|
self.log("[SSH command returned]: %s" % self._ret)
|
||||||
return (self._ret, self._out)
|
return (self._ret, self._out)
|
||||||
|
|
||||||
def _internal_scp(self, cmd):
|
def _internal_scp(self, cmd):
|
||||||
|
cmd = ['scp'] + self.ssh_options + cmd
|
||||||
self.log("[Running SCP]$ %s" % " ".join(cmd))
|
self.log("[Running SCP]$ %s" % " ".join(cmd))
|
||||||
scpconn = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid)
|
scpconn = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid)
|
||||||
out = scpconn.communicate()[0]
|
out = scpconn.communicate()[0]
|
||||||
@@ -90,12 +92,11 @@ class SSHControl(object):
|
|||||||
return (ret, out)
|
return (ret, out)
|
||||||
|
|
||||||
def copy_to(self, localpath, remotepath):
|
def copy_to(self, localpath, remotepath):
|
||||||
actualcmd = ['scp', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', localpath, 'root@%s:%s' % (self.host, remotepath)]
|
actualcmd = [localpath, 'root@%s:%s' % (self.host, remotepath)]
|
||||||
return self._internal_scp(actualcmd)
|
return self._internal_scp(actualcmd)
|
||||||
|
|
||||||
|
|
||||||
def copy_from(self, remotepath, localpath):
|
def copy_from(self, remotepath, localpath):
|
||||||
actualcmd = ['scp', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'root@%s:%s' % (self.host, remotepath), localpath]
|
actualcmd = ['root@%s:%s' % (self.host, remotepath), localpath]
|
||||||
return self._internal_scp(actualcmd)
|
return self._internal_scp(actualcmd)
|
||||||
|
|
||||||
def get_status(self):
|
def get_status(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user