diff options
author | Mihai Lindner <mihaix.lindner@linux.intel.com> | 2013-09-05 18:52:41 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-09-06 23:03:23 +0100 |
commit | fbb3e5e11f41de0dd8643a5593f262f1c93bb37a (patch) | |
tree | c1511e16d357908bc3c6ed872c8234b3e7bc3d77 /meta | |
parent | f6fed84380367fff92ba120f4e3e2e92d9cce73c (diff) | |
download | poky-fbb3e5e11f41de0dd8643a5593f262f1c93bb37a.tar.gz |
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>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oeqa/utils/sshcontrol.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/meta/lib/oeqa/utils/sshcontrol.py b/meta/lib/oeqa/utils/sshcontrol.py index 7de7c3eddd..643d0ad362 100644 --- a/meta/lib/oeqa/utils/sshcontrol.py +++ b/meta/lib/oeqa/utils/sshcontrol.py | |||
@@ -6,7 +6,6 @@ | |||
6 | # running commands and copying files to/from a target. | 6 | # running commands and copying files to/from a target. |
7 | # It's used by testimage.bbclass and tests in lib/oeqa/runtime. | 7 | # It's used by testimage.bbclass and tests in lib/oeqa/runtime. |
8 | 8 | ||
9 | |||
10 | import subprocess | 9 | import subprocess |
11 | import time | 10 | import time |
12 | import os | 11 | import os |
@@ -19,6 +18,12 @@ class SSHControl(object): | |||
19 | self._out = '' | 18 | self._out = '' |
20 | self._ret = 126 | 19 | self._ret = 126 |
21 | self.logfile = logfile | 20 | self.logfile = logfile |
21 | self.ssh_options = [ | ||
22 | '-o', 'UserKnownHostsFile=/dev/null', | ||
23 | '-o', 'StrictHostKeyChecking=no', | ||
24 | '-o', 'LogLevel=ERROR' | ||
25 | ] | ||
26 | self.ssh = ['ssh', '-l', 'root'] + self.ssh_options | ||
22 | 27 | ||
23 | def log(self, msg): | 28 | def log(self, msg): |
24 | if self.logfile: | 29 | if self.logfile: |
@@ -28,7 +33,7 @@ class SSHControl(object): | |||
28 | def _internal_run(self, cmd): | 33 | def _internal_run(self, cmd): |
29 | # We need this for a proper PATH | 34 | # We need this for a proper PATH |
30 | cmd = ". /etc/profile; " + cmd | 35 | cmd = ". /etc/profile; " + cmd |
31 | command = ['ssh', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', '-l', 'root', self.host, cmd ] | 36 | command = self.ssh + [self.host, cmd] |
32 | self.log("[Running]$ %s" % " ".join(command)) | 37 | self.log("[Running]$ %s" % " ".join(command)) |
33 | # ssh hangs without os.setsid | 38 | # ssh hangs without os.setsid |
34 | proc = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid) | 39 | proc = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid) |
@@ -40,8 +45,6 @@ class SSHControl(object): | |||
40 | if time is 0 will let cmd run until it finishes. | 45 | if time is 0 will let cmd run until it finishes. |
41 | Time can be passed to here or can be set per class instance.""" | 46 | Time can be passed to here or can be set per class instance.""" |
42 | 47 | ||
43 | |||
44 | |||
45 | if self.host: | 48 | if self.host: |
46 | sshconn = self._internal_run(cmd) | 49 | sshconn = self._internal_run(cmd) |
47 | else: | 50 | else: |
@@ -70,15 +73,14 @@ class SSHControl(object): | |||
70 | else: | 73 | else: |
71 | self._out = sshconn.stdout.read() | 74 | self._out = sshconn.stdout.read() |
72 | self._ret = sshconn.poll() | 75 | self._ret = sshconn.poll() |
73 | # remove first line from output which is always smth like (unless return code is 255 - which is a ssh error): | 76 | # strip the last LF so we can test the output |
74 | # Warning: Permanently added '192.168.7.2' (RSA) to the list of known hosts. | 77 | self._out = self._out.rstrip() |
75 | if self._ret != 255: | ||
76 | self._out = '\n'.join(self._out.splitlines()[1:]) | ||
77 | self.log("%s" % self._out) | 78 | self.log("%s" % self._out) |
78 | self.log("[SSH command returned]: %s" % self._ret) | 79 | self.log("[SSH command returned]: %s" % self._ret) |
79 | return (self._ret, self._out) | 80 | return (self._ret, self._out) |
80 | 81 | ||
81 | def _internal_scp(self, cmd): | 82 | def _internal_scp(self, cmd): |
83 | cmd = ['scp'] + self.ssh_options + cmd | ||
82 | self.log("[Running SCP]$ %s" % " ".join(cmd)) | 84 | self.log("[Running SCP]$ %s" % " ".join(cmd)) |
83 | scpconn = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid) | 85 | scpconn = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=os.setsid) |
84 | out = scpconn.communicate()[0] | 86 | out = scpconn.communicate()[0] |
@@ -90,12 +92,11 @@ class SSHControl(object): | |||
90 | return (ret, out) | 92 | return (ret, out) |
91 | 93 | ||
92 | def copy_to(self, localpath, remotepath): | 94 | def copy_to(self, localpath, remotepath): |
93 | actualcmd = ['scp', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', localpath, 'root@%s:%s' % (self.host, remotepath)] | 95 | actualcmd = [localpath, 'root@%s:%s' % (self.host, remotepath)] |
94 | return self._internal_scp(actualcmd) | 96 | return self._internal_scp(actualcmd) |
95 | 97 | ||
96 | |||
97 | def copy_from(self, remotepath, localpath): | 98 | def copy_from(self, remotepath, localpath): |
98 | actualcmd = ['scp', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'root@%s:%s' % (self.host, remotepath), localpath] | 99 | actualcmd = ['root@%s:%s' % (self.host, remotepath), localpath] |
99 | return self._internal_scp(actualcmd) | 100 | return self._internal_scp(actualcmd) |
100 | 101 | ||
101 | def get_status(self): | 102 | def get_status(self): |