summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorlmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4>2010-12-28 15:58:43 +0000
committerlmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4>2010-12-28 15:58:43 +0000
commit0fa7fc22a8aed204c7a3d04e7e49e303f34c45b5 (patch)
treee6277f5dad81c67d5863aa9cecb442d13b83ed3b /server
parent556c231bbb5985ab0021f3cbc259b84a8cdef8a1 (diff)
server: fix logfile following to use ssh username and port
The current logging code assumes that 'root' can be used to log into the client machine, which isn't always the case. This patch makes the logger user the user and port settings saved in the host object. This patch also removes the used-exactly-once run_cmd_on_host() function and inlined it since it doesn't seem like there is any benefit to splitting it out. It instead adds a _make_ssh_cmd() method to the abstract_ssh class which respects the username and port settings. It also eliminates the redirection of stderr from the subprocess.Popen() call. If the command fails, then I want to see the output appear in the log. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> git-svn-id: svn://test.kernel.org/autotest/trunk@5011 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'server')
-rw-r--r--server/hosts/abstract_ssh.py11
-rw-r--r--server/hosts/logfile_monitor.py26
2 files changed, 19 insertions, 18 deletions
diff --git a/server/hosts/abstract_ssh.py b/server/hosts/abstract_ssh.py
index 3d8d9e9b..3723c46b 100644
--- a/server/hosts/abstract_ssh.py
+++ b/server/hosts/abstract_ssh.py
@@ -115,6 +115,17 @@ class AbstractSSHHost(SiteHost):
" ".join(sources), dest)
+ def _make_ssh_cmd(self, cmd):
+ """
+ Create a base ssh command string for the host which can be used
+ to run commands directly on the machine
+ """
+ base_cmd = make_ssh_command(user=self.user, port=self.port,
+ opts=self.master_ssh_option,
+ hosts_file=self.known_hosts_fd)
+
+ return '%s %s "%s"' % (base_cmd, self.hostname, utils.sh_escape(cmd))
+
def _make_scp_cmd(self, sources, dest):
"""
Given a list of source paths and a destination path, produces the
diff --git a/server/hosts/logfile_monitor.py b/server/hosts/logfile_monitor.py
index 1608a6be..9595cc82 100644
--- a/server/hosts/logfile_monitor.py
+++ b/server/hosts/logfile_monitor.py
@@ -26,15 +26,6 @@ class FollowFilesLaunchError(Error):
"""Error occurred launching followfiles remotely."""
-def run_cmd_on_host(hostname, cmd, stdin, stdout, stderr):
- base_cmd = abstract_ssh.make_ssh_command()
- full_cmd = "%s %s \"%s\"" % (base_cmd, hostname,
- server_utils.sh_escape(cmd))
-
- return subprocess.Popen(full_cmd, stdin=stdin, stdout=stdout,
- stderr=stderr, shell=True)
-
-
def list_remote_pythons(host):
"""List out installed pythons on host."""
result = host.run('ls /usr/bin/python[0-9]*')
@@ -72,25 +63,24 @@ def launch_remote_followfiles(host, lastlines_dirpath, follow_paths):
raise FollowFilesLaunchError('No supported Python on host.')
remote_monitordir = copy_monitordir(host)
- remote_script_path = os.path.join(
- remote_monitordir, 'followfiles.py')
+ remote_script_path = os.path.join(remote_monitordir, 'followfiles.py')
followfiles_cmd = '%s %s --lastlines_dirpath=%s %s' % (
supported_python, remote_script_path,
lastlines_dirpath, ' '.join(follow_paths))
- devnull_r = open(os.devnull, 'r')
- devnull_w = open(os.devnull, 'w')
- remote_followfiles_proc = run_cmd_on_host(
- host.hostname, followfiles_cmd, stdout=subprocess.PIPE,
- stdin=devnull_r, stderr=devnull_w)
+ remote_ff_proc = subprocess.Popen(host._make_ssh_cmd(followfiles_cmd),
+ stdin=open(os.devnull, 'r'),
+ stdout=subprocess.PIPE, shell=True)
+
+
# Give it enough time to crash if it's going to (it shouldn't).
time.sleep(5)
- doa = remote_followfiles_proc.poll()
+ doa = remote_ff_proc.poll()
if doa:
raise FollowFilesLaunchError('ssh command crashed.')
- return remote_followfiles_proc
+ return remote_ff_proc
def resolve_patterns_path(patterns_path):