Created a common_lib host object hierarchy (with site specific override
support) and moved *some* non server specific code from server/hosts to
the common_lib version. Created a client.bin LocalHost host object
inheriting from the common_lib Host and implemented a run() method based
on utils.run() (ie a host object for the local machine). Modified
client/bin/autotest to receive a new --hostname argument to tell it the
hostname to use for the LocalHost.hostname instance attribute and
updated server/autotest.py to send use this argument. Modified
client.bin.job to set a self.host instance attribute with an instance of
LocalHost and updated the unittest. Added an AutotestHostRunError class
(raised on LocalHost.run() failures).

Risk: high (there are modifications in the core server side support code
and some core client code).

Tested with verify/repair and client/server sleeptest jobs.

To be able for SVN to remember code history (that most of the new 
client/common_lib/hosts/base_classes.py is based on the old 
server/hosts/base_classes.py) then the following steps are probably needed 
to apply this patch:
$ svn mkdir client/common_lib/hosts
$ svn copy server/hosts/base_classes.py client/common_lib/hosts
$ patch -p1 ...
$ svn add client/bin/local_host.py client/bin/local_host_unittest.py client/common_lib/hosts/__init__.py client/common_lib/hosts/base_classes_unittest.py

Signed-off-by: Mihai Rusu <dizzy@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@3594 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/bin/local_host.py b/client/bin/local_host.py
new file mode 100644
index 0000000..b131192
--- /dev/null
+++ b/client/bin/local_host.py
@@ -0,0 +1,39 @@
+# Copyright 2009 Google Inc. Released under the GPL v2
+
+"""
+This file contains the implementation of a host object for the local machine.
+"""
+
+import platform
+from autotest_lib.client.common_lib import hosts, error
+from autotest_lib.client.bin import utils
+
+class LocalHost(hosts.Host):
+    def _initialize(self, hostname=None, *args, **dargs):
+        super(LocalHost, self)._initialize(*args, **dargs)
+
+        # hostname will be an actual hostname when this client was created
+        # by an autoserv process
+        if not hostname:
+            hostname = platform.node()
+        self.hostname = hostname
+
+
+    def wait_up(self, timeout=None):
+        # a local host is always up
+        return True
+
+
+    def run(self, command, timeout=3600, ignore_status=False,
+            stdout_tee=utils.TEE_TO_LOGS, stderr_tee=utils.TEE_TO_LOGS,
+            stdin=None):
+        """
+        @see common_lib.hosts.Host.run()
+        """
+        result = utils.run(command, timeout=timeout, ignore_status=True,
+                stdout_tee=stdout_tee, stderr_tee=stderr_tee, stdin=stdin)
+
+        if not ignore_status and result.exit_status > 0:
+            raise error.AutotestHostRunError('command execution error', result)
+
+        return result