Simran Basi | cced309 | 2012-08-02 15:09:23 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | import logging |
| 5 | |
| 6 | from autotest_lib.client.common_lib import global_config |
Simran Basi | 695e2d3 | 2013-01-04 14:59:19 -0800 | [diff] [blame^] | 7 | from autotest_lib.scheduler import drones, scheduler_config |
Simran Basi | cced309 | 2012-08-02 15:09:23 -0700 | [diff] [blame] | 8 | |
| 9 | HOSTS_JOB_SUBDIR = 'hosts/' |
Simran Basi | 8f858d0 | 2012-08-03 15:28:55 -0700 | [diff] [blame] | 10 | PARSE_LOG = '.parse.log' |
Simran Basi | cced309 | 2012-08-02 15:09:23 -0700 | [diff] [blame] | 11 | |
| 12 | |
| 13 | class SiteDroneManager(object): |
| 14 | |
| 15 | |
| 16 | def copy_to_results_repository(self, process, source_path, |
| 17 | destination_path=None): |
| 18 | """ |
| 19 | Copy results from the given process at source_path to destination_path |
| 20 | in the results repository. |
| 21 | |
| 22 | This site subclassed version will only copy the results back for Special |
| 23 | Agent Tasks (Cleanup, Verify, Repair) that reside in the hosts/ |
| 24 | subdirectory of results if the copy_task_results_back flag has been set |
| 25 | to True inside global_config.ini |
Simran Basi | 8f858d0 | 2012-08-03 15:28:55 -0700 | [diff] [blame] | 26 | |
| 27 | It will also only copy .parse.log files back to the scheduler if the |
| 28 | copy_parse_log_back flag in global_config.ini has been set to True. |
Simran Basi | cced309 | 2012-08-02 15:09:23 -0700 | [diff] [blame] | 29 | """ |
| 30 | copy_task_results_back = global_config.global_config.get_config_value( |
| 31 | scheduler_config.CONFIG_SECTION, 'copy_task_results_back', |
| 32 | type=bool) |
Simran Basi | 8f858d0 | 2012-08-03 15:28:55 -0700 | [diff] [blame] | 33 | copy_parse_log_back = global_config.global_config.get_config_value( |
| 34 | scheduler_config.CONFIG_SECTION, 'copy_parse_log_back', |
| 35 | type=bool) |
Simran Basi | cced309 | 2012-08-02 15:09:23 -0700 | [diff] [blame] | 36 | special_task = source_path.startswith(HOSTS_JOB_SUBDIR) |
Simran Basi | 8f858d0 | 2012-08-03 15:28:55 -0700 | [diff] [blame] | 37 | parse_log = source_path.endswith(PARSE_LOG) |
| 38 | if (copy_task_results_back or not special_task) and ( |
| 39 | copy_parse_log_back or not parse_log): |
Simran Basi | cced309 | 2012-08-02 15:09:23 -0700 | [diff] [blame] | 40 | super(SiteDroneManager, self).copy_to_results_repository(process, |
Simran Basi | 8f858d0 | 2012-08-03 15:28:55 -0700 | [diff] [blame] | 41 | source_path, destination_path) |
Simran Basi | af9b8e7 | 2012-10-12 15:02:36 -0700 | [diff] [blame] | 42 | |
| 43 | |
| 44 | def kill_process(self, process): |
| 45 | """ |
| 46 | Kill the given process. |
| 47 | """ |
| 48 | logging.info('killing %s', process) |
| 49 | drone = self._get_drone_for_process(process) |
Simran Basi | 695e2d3 | 2013-01-04 14:59:19 -0800 | [diff] [blame^] | 50 | drone.queue_kill_process(process) |
| 51 | |
| 52 | |
| 53 | def _add_drone(self, hostname): |
| 54 | """ |
| 55 | Forked from drone_manager.py |
| 56 | |
| 57 | Catches AutoservRunError if the drone fails initialization and does not |
| 58 | add it to the list of usable drones. |
| 59 | |
| 60 | @param hostname: Hostname of the drone we are trying to add. |
| 61 | """ |
| 62 | logging.info('Adding drone %s' % hostname) |
| 63 | drone = drones.get_drone(hostname) |
| 64 | if drone: |
| 65 | try: |
| 66 | drone.call('initialize', self.absolute_path('')) |
| 67 | except error.AutoservRunError as e: |
| 68 | logging.error('Failed to initialize drone %s with error: %s', |
| 69 | hostname, e) |
| 70 | return |
| 71 | self._drones[drone.hostname] = drone |