blob: 79eff3a0636cf94fbffca7a405ae5d71388a7ad8 [file] [log] [blame]
mblighce955fc2009-08-24 21:59:02 +00001# Copyright 2009 Google Inc. Released under the GPL v2
2
3"""
4This file contains the implementation of a host object for the local machine.
5"""
6
7import platform
8from autotest_lib.client.common_lib import hosts, error
9from autotest_lib.client.bin import utils
10
11class 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,
jadmanskif7368c52009-10-13 14:56:23 +000029 stdin=None, args=()):
mblighce955fc2009-08-24 21:59:02 +000030 """
31 @see common_lib.hosts.Host.run()
32 """
showard8e62be12009-10-14 16:07:38 +000033 try:
34 result = utils.run(
jadmanskif7368c52009-10-13 14:56:23 +000035 command, timeout=timeout, ignore_status=True,
36 stdout_tee=stdout_tee, stderr_tee=stderr_tee, stdin=stdin,
37 args=args)
showard8e62be12009-10-14 16:07:38 +000038 except error.CmdError, e:
39 # this indicates a timeout exception
40 raise error.AutotestHostRunError('command timed out', e.result_obj)
mblighce955fc2009-08-24 21:59:02 +000041
42 if not ignore_status and result.exit_status > 0:
43 raise error.AutotestHostRunError('command execution error', result)
44
45 return result