mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2007 Google Inc. Released under the GPL v2 |
| 3 | |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 4 | """ |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 5 | This module defines the base classes for the server Host hierarchy. |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 6 | |
| 7 | Implementation details: |
| 8 | You should import the "hosts" package instead of importing each type of host. |
| 9 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 10 | Host: a machine on which you can run programs |
| 11 | RemoteHost: a remote machine on which you can run programs |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 12 | """ |
| 13 | |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 14 | __author__ = """ |
| 15 | mbligh@google.com (Martin J. Bligh), |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 16 | poirier@google.com (Benjamin Poirier), |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 17 | stutsman@google.com (Ryan Stutsman) |
| 18 | """ |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 19 | |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 20 | from autotest_lib.client.common_lib import hosts |
Prathmesh Prabhu | fd49f0d | 2018-09-20 21:02:38 +0000 | [diff] [blame] | 21 | from autotest_lib.server import utils |
mbligh | f5427bb | 2008-04-09 15:55:57 +0000 | [diff] [blame] | 22 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 23 | |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 24 | class Host(hosts.Host): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 25 | """ |
| 26 | This class represents a machine on which you can run programs. |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 27 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 28 | It may be a local machine, the one autoserv is running on, a remote |
| 29 | machine or a virtual machine. |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 30 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 31 | 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. |
jadmanski | c7b9530 | 2008-06-10 20:44:40 +0000 | [diff] [blame] | 35 | |
| 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. |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 49 | """ |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 50 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 51 | bootloader = None |
mbligh | a0a2759 | 2009-01-24 01:41:36 +0000 | [diff] [blame] | 52 | |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 53 | |
jadmanski | f656291 | 2008-10-21 17:59:01 +0000 | [diff] [blame] | 54 | def __init__(self, *args, **dargs): |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 55 | super(Host, self).__init__(*args, **dargs) |
| 56 | |
jadmanski | f656291 | 2008-10-21 17:59:01 +0000 | [diff] [blame] | 57 | self.start_loggers() |
jadmanski | 53aaf38 | 2008-11-17 16:22:31 +0000 | [diff] [blame] | 58 | if self.job: |
| 59 | self.job.hosts.add(self) |
jadmanski | f656291 | 2008-10-21 17:59:01 +0000 | [diff] [blame] | 60 | |
| 61 | |
Richard Barnette | ab9769f | 2016-06-01 15:01:44 -0700 | [diff] [blame] | 62 | def _initialize(self, *args, **dargs): |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 63 | super(Host, self)._initialize(*args, **dargs) |
| 64 | |
Prathmesh Prabhu | fd49f0d | 2018-09-20 21:02:38 +0000 | [diff] [blame] | 65 | self.serverdir = utils.get_server_dir() |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 66 | self.env = {} |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 67 | |
| 68 | |
jadmanski | 53aaf38 | 2008-11-17 16:22:31 +0000 | [diff] [blame] | 69 | def close(self): |
Richard Barnette | 7c3c625 | 2018-07-18 14:23:23 -0700 | [diff] [blame] | 70 | """Release resources held by this Host instance.""" |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 71 | super(Host, self).close() |
| 72 | |
jadmanski | 53aaf38 | 2008-11-17 16:22:31 +0000 | [diff] [blame] | 73 | if self.job: |
| 74 | self.job.hosts.discard(self) |