blob: 79d2dfa74f39806c383827d9603119dab827ae7a [file] [log] [blame]
mblighdcd57a82007-07-11 23:06:47 +00001#
2# Copyright 2007 Google Inc. Released under the GPL v2
3
mbligh7d2bde82007-08-02 16:26:10 +00004"""
mblighce955fc2009-08-24 21:59:02 +00005This module defines the base classes for the server Host hierarchy.
mblighdcd57a82007-07-11 23:06:47 +00006
7Implementation details:
8You should import the "hosts" package instead of importing each type of host.
9
jadmanski0afbb632008-06-06 21:10:57 +000010 Host: a machine on which you can run programs
11 RemoteHost: a remote machine on which you can run programs
mblighdcd57a82007-07-11 23:06:47 +000012"""
13
mbligh7d2bde82007-08-02 16:26:10 +000014__author__ = """
15mbligh@google.com (Martin J. Bligh),
mblighdcd57a82007-07-11 23:06:47 +000016poirier@google.com (Benjamin Poirier),
mbligh7d2bde82007-08-02 16:26:10 +000017stutsman@google.com (Ryan Stutsman)
18"""
mblighdcd57a82007-07-11 23:06:47 +000019
mblighce955fc2009-08-24 21:59:02 +000020from autotest_lib.client.common_lib import hosts
Prathmesh Prabhufd49f0d2018-09-20 21:02:38 +000021from autotest_lib.server import utils
mblighf5427bb2008-04-09 15:55:57 +000022
mblighdcd57a82007-07-11 23:06:47 +000023
mblighce955fc2009-08-24 21:59:02 +000024class Host(hosts.Host):
jadmanski0afbb632008-06-06 21:10:57 +000025 """
26 This class represents a machine on which you can run programs.
mbligh7d2bde82007-08-02 16:26:10 +000027
jadmanski0afbb632008-06-06 21:10:57 +000028 It may be a local machine, the one autoserv is running on, a remote
29 machine or a virtual machine.
mbligh7d2bde82007-08-02 16:26:10 +000030
jadmanski0afbb632008-06-06 21:10:57 +000031 Implementation details:
32 This is an abstract class, leaf subclasses must implement the methods
33 listed here. You must not instantiate this class but should
34 instantiate one of those leaf subclasses.
jadmanskic7b95302008-06-10 20:44:40 +000035
36 When overriding methods that raise NotImplementedError, the leaf class
37 is fully responsible for the implementation and should not chain calls
38 to super. When overriding methods that are a NOP in Host, the subclass
39 should chain calls to super(). The criteria for fitting a new method into
40 one category or the other should be:
41 1. If two separate generic implementations could reasonably be
42 concatenated, then the abstract implementation should pass and
43 subclasses should chain calls to super.
44 2. If only one class could reasonably perform the stated function
45 (e.g. two separate run() implementations cannot both be executed)
46 then the method should raise NotImplementedError in Host, and
47 the implementor should NOT chain calls to super, to ensure that
48 only one implementation ever gets executed.
jadmanski0afbb632008-06-06 21:10:57 +000049 """
mbligh7d2bde82007-08-02 16:26:10 +000050
jadmanski0afbb632008-06-06 21:10:57 +000051 bootloader = None
mbligha0a27592009-01-24 01:41:36 +000052
mbligh7d2bde82007-08-02 16:26:10 +000053
jadmanskif6562912008-10-21 17:59:01 +000054 def __init__(self, *args, **dargs):
mblighce955fc2009-08-24 21:59:02 +000055 super(Host, self).__init__(*args, **dargs)
56
jadmanskif6562912008-10-21 17:59:01 +000057 self.start_loggers()
jadmanski53aaf382008-11-17 16:22:31 +000058 if self.job:
59 self.job.hosts.add(self)
jadmanskif6562912008-10-21 17:59:01 +000060
61
Richard Barnetteab9769f2016-06-01 15:01:44 -070062 def _initialize(self, *args, **dargs):
mblighce955fc2009-08-24 21:59:02 +000063 super(Host, self)._initialize(*args, **dargs)
64
Prathmesh Prabhufd49f0d2018-09-20 21:02:38 +000065 self.serverdir = utils.get_server_dir()
jadmanski0afbb632008-06-06 21:10:57 +000066 self.env = {}
mbligh7d2bde82007-08-02 16:26:10 +000067
68
jadmanski53aaf382008-11-17 16:22:31 +000069 def close(self):
Richard Barnette7c3c6252018-07-18 14:23:23 -070070 """Release resources held by this Host instance."""
mblighce955fc2009-08-24 21:59:02 +000071 super(Host, self).close()
72
jadmanski53aaf382008-11-17 16:22:31 +000073 if self.job:
74 self.job.hosts.discard(self)