Have the autotest server run the client by calling host.run, instead
of explicitly doing it through ssh. Also, make sure that when
SSHHost does run commands through run it logs the commands being run
and passed on the output to stdout and stderr.

This also disables X11 forwarding in ssh (the -x option) to since we
don't use it and it may just introduce a lot of spurious "remote host
denied forwarding" warnings into the logs.

Signed-off-by: John Admanski <jadmanski@google.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@1002 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/autotest.py b/server/autotest.py
index b4e7cc3..7279476 100644
--- a/server/autotest.py
+++ b/server/autotest.py
@@ -270,25 +270,16 @@
 		print "Executing %s/bin/autotest %s/control phase %d" % \
 					(self.autodir, self.autodir,
 					 section)
-		logfile = "%s/debug/client.log.%d" % (self.results_dir,
-						      section)
-		client_log = open(logfile, 'w', 0)
-		cmd = [os.path.join(self.autodir, 'bin/autotest_client')]
-		if section > 0:
-			cmd.append('-c')
-		cmd.append(self.remote_control_file)
-		# We should *really* be doing this via host.run,
-		# but need to sort out the redirection we use first.
-		ssh = "ssh -q -a -o BatchMode=yes %s@%s" % (self.host.user,
-							    self.host.hostname)
-		env = ' '.join(['='.join(i) for i in self.env.iteritems()])
-		full_cmd = "%s '%s %s'" % (ssh, env, ' '.join(cmd))
-		print full_cmd
 
+		# open up the files we need for our logging
+		client_log_file = os.path.join(self.results_dir, 'debug',
+					       'client.log.%d' % section)
+		client_log = open(client_log_file, 'w', 0)
 		status_log_file = os.path.join(self.results_dir, 'status.log')
 		status_log = open(status_log_file, 'a', 0)
 
-
+		# create a file-like object for catching the stderr text
+		# from the autotest client and extracting status logs from it
 		class StdErrRedirector(object):
 			"""Partial file object to write to both stdout and
 			the status log file.  We only implement those methods
@@ -331,12 +322,19 @@
 				if self.leftover:
 					self._process_line(self.leftover)
 					self.flush()
-
 		redirector = StdErrRedirector()
-		result = utils.run(full_cmd, ignore_status=True,
-				   timeout=timeout,
-				   stdout_tee=client_log,
-				   stderr_tee=redirector)
+
+		# build up the full command we want to run over the host
+		cmd = [os.path.join(self.autodir, 'bin/autotest_client')]
+		if section > 0:
+			cmd.append('-c')
+		cmd.append(self.remote_control_file)
+		full_cmd = ' '.join(cmd)
+
+		result = self.host.run(full_cmd, ignore_status=True,
+				       timeout=timeout,
+				       stdout_tee=client_log,
+				       stderr_tee=redirector)
 		redirector.close()
 
 		if result.exit_status == 1:
diff --git a/server/hosts/ssh_host.py b/server/hosts/ssh_host.py
index 4b18504..b62cfb3 100644
--- a/server/hosts/ssh_host.py
+++ b/server/hosts/ssh_host.py
@@ -44,7 +44,8 @@
 	implement the unimplemented methods in parent classes.
 	"""
 
-	SSH_BASE_COMMAND = '/usr/bin/ssh -a -o BatchMode=yes -o ConnectTimeout=30'
+	SSH_BASE_COMMAND = '/usr/bin/ssh -a -x -o ' + \
+			   'BatchMode=yes -o ConnectTimeout=30'
 	DEFAULT_REBOOT_TIMEOUT = 1800
 	job = None
 
@@ -314,7 +315,8 @@
 					       self.hostname)
 
 
-	def run(self, command, timeout=None, ignore_status=False):
+	def run(self, command, timeout=None, ignore_status=False,
+		stdout_tee=None, stderr_tee=None):
 		"""
 		Run a command on the remote host.
 		
@@ -334,10 +336,14 @@
 			AutoservRunError: the exit code of the command 
 				execution was not 0
 		"""
-		#~ print "running %s" % (command,)
-		result= utils.run(r'%s "%s"' % (self.ssh_command(),
-						utils.sh_escape(command)),
-						timeout, ignore_status)
+		stdout = stdout_tee or sys.stdout
+		stderr = stderr_tee or sys.stderr
+		print "On host %s running %s" % (self.hostname, command)
+		env = " ".join("=".join(pair) for pair in self.env.iteritems())
+		full_cmd = '%s "%s %s"' % (self.ssh_command(), env,
+					   utils.sh_escape(command))
+		result = utils.run(full_cmd, timeout, ignore_status,
+				   stdout, stderr)
 		return result