mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame^] | 1 | # Copyright 2009 Google Inc. Released under the GPL v2 |
| 2 | |
| 3 | """ |
| 4 | This file contains the implementation of a host object for the local machine. |
| 5 | """ |
| 6 | |
| 7 | import platform |
| 8 | from autotest_lib.client.common_lib import hosts, error |
| 9 | from autotest_lib.client.bin import utils |
| 10 | |
| 11 | class LocalHost(hosts.Host): |
| 12 | def _initialize(self, hostname=None, *args, **dargs): |
| 13 | super(LocalHost, self)._initialize(*args, **dargs) |
| 14 | |
| 15 | # hostname will be an actual hostname when this client was created |
| 16 | # by an autoserv process |
| 17 | if not hostname: |
| 18 | hostname = platform.node() |
| 19 | self.hostname = hostname |
| 20 | |
| 21 | |
| 22 | def wait_up(self, timeout=None): |
| 23 | # a local host is always up |
| 24 | return True |
| 25 | |
| 26 | |
| 27 | def run(self, command, timeout=3600, ignore_status=False, |
| 28 | stdout_tee=utils.TEE_TO_LOGS, stderr_tee=utils.TEE_TO_LOGS, |
| 29 | stdin=None): |
| 30 | """ |
| 31 | @see common_lib.hosts.Host.run() |
| 32 | """ |
| 33 | result = utils.run(command, timeout=timeout, ignore_status=True, |
| 34 | stdout_tee=stdout_tee, stderr_tee=stderr_tee, stdin=stdin) |
| 35 | |
| 36 | if not ignore_status and result.exit_status > 0: |
| 37 | raise error.AutotestHostRunError('command execution error', result) |
| 38 | |
| 39 | return result |