Fix bug introduced into paramiko_host by recent changes to selectively disable rsync support (SVN rev 4077). The new code makes SSH calls within _initialize(), but paramiko_host wasn't sufficiently initialized when the call was being made. In general, executing remote commands within _initialize() is dangerous. This change removes the new code from _initialize() and instead makes AbstractSSHHost compute the new information lazily.
Signed-off-by: Steve Howard <[email protected]>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@4131 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/hosts/abstract_ssh.py b/server/hosts/abstract_ssh.py
index 49797bc..860a722 100644
--- a/server/hosts/abstract_ssh.py
+++ b/server/hosts/abstract_ssh.py
@@ -43,6 +43,7 @@
self.user = user
self.port = port
self.password = password
+ self._use_rsync = None
"""
Master SSH connection background job, socket temp directory and socket
@@ -53,10 +54,15 @@
self.master_ssh_tempdir = None
self.master_ssh_option = ''
+
+ def use_rsync(self):
+ if self._use_rsync is not None:
+ return self._use_rsync
+
# Check if rsync is available on the remote host. If it's not,
# don't try to use it for any future file transfers.
- self.use_rsync = self._check_rsync()
- if not self.use_rsync:
+ self._use_rsync = self._check_rsync()
+ if not self._use_rsync:
logging.warn("rsync not available on remote host %s -- disabled",
self.hostname)
@@ -247,17 +253,17 @@
dest = os.path.abspath(dest)
# If rsync is disabled or fails, try scp.
- try_scp = not self.use_rsync
- if self.use_rsync:
+ try_scp = True
+ if self.use_rsync():
try:
remote_source = self._encode_remote_paths(source)
local_dest = utils.sh_escape(dest)
rsync = self._make_rsync_cmd([remote_source], local_dest,
delete_dest, preserve_symlinks)
utils.run(rsync)
+ try_scp = False
except error.CmdError, e:
logging.warn("trying scp, rsync failed: %s" % e)
- try_scp = True
if try_scp:
# scp has no equivalent to --delete, just drop the entire dest dir
@@ -323,16 +329,16 @@
remote_dest = self._encode_remote_paths([dest])
# If rsync is disabled or fails, try scp.
- try_scp = not self.use_rsync
- if self.use_rsync:
+ try_scp = True
+ if self.use_rsync():
try:
local_sources = [utils.sh_escape(path) for path in source]
rsync = self._make_rsync_cmd(local_sources, remote_dest,
delete_dest, preserve_symlinks)
utils.run(rsync)
+ try_scp = False
except error.CmdError, e:
logging.warn("trying scp, rsync failed: %s" % e)
- try_scp = True
if try_scp:
# scp has no equivalent to --delete, just drop the entire dest dir