1*9c5db199SXin Li# 2*9c5db199SXin Li# Copyright 2007 Google Inc. Released under the GPL v2 3*9c5db199SXin Li 4*9c5db199SXin Li""" 5*9c5db199SXin LiThis module defines the base classes for the server Host hierarchy. 6*9c5db199SXin Li 7*9c5db199SXin LiImplementation details: 8*9c5db199SXin LiYou should import the "hosts" package instead of importing each type of host. 9*9c5db199SXin Li 10*9c5db199SXin Li Host: a machine on which you can run programs 11*9c5db199SXin Li RemoteHost: a remote machine on which you can run programs 12*9c5db199SXin Li""" 13*9c5db199SXin Li 14*9c5db199SXin Li__author__ = """ 15*9c5db199SXin Li[email protected] (Martin J. Bligh), 16*9c5db199SXin Li[email protected] (Benjamin Poirier), 17*9c5db199SXin Li[email protected] (Ryan Stutsman) 18*9c5db199SXin Li""" 19*9c5db199SXin Li 20*9c5db199SXin Lifrom autotest_lib.client.common_lib import hosts 21*9c5db199SXin Lifrom autotest_lib.server import utils 22*9c5db199SXin Li 23*9c5db199SXin Li 24*9c5db199SXin Liclass Host(hosts.Host): 25*9c5db199SXin Li """ 26*9c5db199SXin Li This class represents a machine on which you can run programs. 27*9c5db199SXin Li 28*9c5db199SXin Li It may be a local machine, the one autoserv is running on, a remote 29*9c5db199SXin Li machine or a virtual machine. 30*9c5db199SXin Li 31*9c5db199SXin Li Implementation details: 32*9c5db199SXin Li This is an abstract class, leaf subclasses must implement the methods 33*9c5db199SXin Li listed here. You must not instantiate this class but should 34*9c5db199SXin Li instantiate one of those leaf subclasses. 35*9c5db199SXin Li 36*9c5db199SXin Li When overriding methods that raise NotImplementedError, the leaf class 37*9c5db199SXin Li is fully responsible for the implementation and should not chain calls 38*9c5db199SXin Li to super. When overriding methods that are a NOP in Host, the subclass 39*9c5db199SXin Li should chain calls to super(). The criteria for fitting a new method into 40*9c5db199SXin Li one category or the other should be: 41*9c5db199SXin Li 1. If two separate generic implementations could reasonably be 42*9c5db199SXin Li concatenated, then the abstract implementation should pass and 43*9c5db199SXin Li subclasses should chain calls to super. 44*9c5db199SXin Li 2. If only one class could reasonably perform the stated function 45*9c5db199SXin Li (e.g. two separate run() implementations cannot both be executed) 46*9c5db199SXin Li then the method should raise NotImplementedError in Host, and 47*9c5db199SXin Li the implementor should NOT chain calls to super, to ensure that 48*9c5db199SXin Li only one implementation ever gets executed. 49*9c5db199SXin Li """ 50*9c5db199SXin Li 51*9c5db199SXin Li bootloader = None 52*9c5db199SXin Li 53*9c5db199SXin Li 54*9c5db199SXin Li def __init__(self, *args, **dargs): 55*9c5db199SXin Li super(Host, self).__init__(*args, **dargs) 56*9c5db199SXin Li 57*9c5db199SXin Li self.start_loggers() 58*9c5db199SXin Li if self.job: 59*9c5db199SXin Li self.job.hosts.add(self) 60*9c5db199SXin Li 61*9c5db199SXin Li 62*9c5db199SXin Li def _initialize(self, *args, **dargs): 63*9c5db199SXin Li super(Host, self)._initialize(*args, **dargs) 64*9c5db199SXin Li 65*9c5db199SXin Li self.serverdir = utils.get_server_dir() 66*9c5db199SXin Li self.env = {} 67*9c5db199SXin Li 68*9c5db199SXin Li 69*9c5db199SXin Li def close(self): 70*9c5db199SXin Li """Release resources held by this Host instance.""" 71*9c5db199SXin Li super(Host, self).close() 72*9c5db199SXin Li 73*9c5db199SXin Li if self.job: 74*9c5db199SXin Li self.job.hosts.discard(self) 75