| OLD | NEW |
| 1 import cPickle, os, tempfile, logging | 1 import cPickle, os, tempfile, logging |
| 2 import common | 2 import common |
| 3 from autotest_lib.scheduler import drone_utility, email_manager | 3 from autotest_lib.scheduler import drone_utility, email_manager |
| 4 from autotest_lib.client.common_lib import error, global_config | 4 from autotest_lib.client.common_lib import error, global_config |
| 5 | 5 |
| 6 | 6 |
| 7 AUTOTEST_INSTALL_DIR = global_config.global_config.get_config_value('SCHEDULER', | 7 AUTOTEST_INSTALL_DIR = global_config.global_config.get_config_value('SCHEDULER', |
| 8 'drone_installation_directory') | 8 'drone_installation_directory') |
| 9 | 9 |
| 10 class DroneUnreachable(Exception): | |
| 11 """The drone is non-sshable.""" | |
| 12 pass | |
| 13 | |
| 14 | |
| 15 class _AbstractDrone(object): | 10 class _AbstractDrone(object): |
| 16 """ | 11 """ |
| 17 Attributes: | 12 Attributes: |
| 18 * allowed_users: set of usernames allowed to use this drone. if None, | 13 * allowed_users: set of usernames allowed to use this drone. if None, |
| 19 any user can use this drone. | 14 any user can use this drone. |
| 20 """ | 15 """ |
| 21 def __init__(self): | 16 def __init__(self): |
| 22 self._calls = [] | 17 self._calls = [] |
| 23 self.hostname = None | 18 self.hostname = None |
| 24 self.enabled = True | 19 self.enabled = True |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 else: | 104 else: |
| 110 self.queue_call('send_file_to', drone.hostname, source_path, | 105 self.queue_call('send_file_to', drone.hostname, source_path, |
| 111 destination_path, can_fail) | 106 destination_path, can_fail) |
| 112 | 107 |
| 113 | 108 |
| 114 class _RemoteDrone(_AbstractDrone): | 109 class _RemoteDrone(_AbstractDrone): |
| 115 def __init__(self, hostname): | 110 def __init__(self, hostname): |
| 116 super(_RemoteDrone, self).__init__() | 111 super(_RemoteDrone, self).__init__() |
| 117 self.hostname = hostname | 112 self.hostname = hostname |
| 118 self._host = drone_utility.create_host(hostname) | 113 self._host = drone_utility.create_host(hostname) |
| 119 if not self._host.is_up(): | |
| 120 logging.error('Drone %s is unpingable, kicking out', hostname) | |
| 121 raise DroneUnreachable | |
| 122 self._autotest_install_dir = AUTOTEST_INSTALL_DIR | 114 self._autotest_install_dir = AUTOTEST_INSTALL_DIR |
| 123 | 115 |
| 124 | 116 |
| 125 def set_autotest_install_dir(self, path): | 117 def set_autotest_install_dir(self, path): |
| 126 self._autotest_install_dir = path | 118 self._autotest_install_dir = path |
| 127 | 119 |
| 128 | 120 |
| 129 def shutdown(self): | 121 def shutdown(self): |
| 130 super(_RemoteDrone, self).shutdown() | 122 super(_RemoteDrone, self).shutdown() |
| 131 self._host.close() | 123 self._host.close() |
| (...skipping 25 matching lines...) Expand all Loading... |
| 157 self.queue_call('send_file_to', drone.hostname, source_path, | 149 self.queue_call('send_file_to', drone.hostname, source_path, |
| 158 destination_path, can_fail) | 150 destination_path, can_fail) |
| 159 | 151 |
| 160 | 152 |
| 161 def get_drone(hostname): | 153 def get_drone(hostname): |
| 162 """ | 154 """ |
| 163 Use this factory method to get drone objects. | 155 Use this factory method to get drone objects. |
| 164 """ | 156 """ |
| 165 if hostname == 'localhost': | 157 if hostname == 'localhost': |
| 166 return _LocalDrone() | 158 return _LocalDrone() |
| 167 try: | 159 return _RemoteDrone(hostname) |
| 168 return _RemoteDrone(hostname) | |
| 169 except DroneUnreachable: | |
| 170 return None | |
| OLD | NEW |