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