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 | |
Chris Sosa | b838a0c | 2013-02-17 16:58:33 -0800 | [diff] [blame] | 6 | from autotest_lib.client.common_lib import global_config, error |
Simran Basi | 695e2d3 | 2013-01-04 14:59:19 -0800 | [diff] [blame] | 7 | from autotest_lib.scheduler import drones, scheduler_config |
Fang Deng | 1d6c2a0 | 2013-04-17 15:25:45 -0700 | [diff] [blame] | 8 | from autotest_lib.site_utils.graphite import stats |
Simran Basi | cced309 | 2012-08-02 15:09:23 -0700 | [diff] [blame] | 9 | |
| 10 | HOSTS_JOB_SUBDIR = 'hosts/' |
Simran Basi | 8f858d0 | 2012-08-03 15:28:55 -0700 | [diff] [blame] | 11 | PARSE_LOG = '.parse.log' |
Simran Basi | 882f15b | 2013-10-29 14:59:34 -0700 | [diff] [blame^] | 12 | ENABLE_ARCHIVING = global_config.global_config.get_config_value( |
| 13 | scheduler_config.CONFIG_SECTION, 'enable_archiving', type=bool) |
Simran Basi | cced309 | 2012-08-02 15:09:23 -0700 | [diff] [blame] | 14 | |
| 15 | |
| 16 | class SiteDroneManager(object): |
| 17 | |
| 18 | |
Fang Deng | 1d6c2a0 | 2013-04-17 15:25:45 -0700 | [diff] [blame] | 19 | _timer = stats.Timer('drone_manager') |
| 20 | |
| 21 | |
Simran Basi | cced309 | 2012-08-02 15:09:23 -0700 | [diff] [blame] | 22 | def copy_to_results_repository(self, process, source_path, |
| 23 | destination_path=None): |
| 24 | """ |
| 25 | Copy results from the given process at source_path to destination_path |
| 26 | in the results repository. |
| 27 | |
| 28 | This site subclassed version will only copy the results back for Special |
| 29 | Agent Tasks (Cleanup, Verify, Repair) that reside in the hosts/ |
| 30 | subdirectory of results if the copy_task_results_back flag has been set |
| 31 | to True inside global_config.ini |
Simran Basi | 8f858d0 | 2012-08-03 15:28:55 -0700 | [diff] [blame] | 32 | |
| 33 | It will also only copy .parse.log files back to the scheduler if the |
| 34 | 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] | 35 | """ |
Simran Basi | 882f15b | 2013-10-29 14:59:34 -0700 | [diff] [blame^] | 36 | if not ENABLE_ARCHIVING: |
| 37 | return |
Simran Basi | cced309 | 2012-08-02 15:09:23 -0700 | [diff] [blame] | 38 | copy_task_results_back = global_config.global_config.get_config_value( |
| 39 | scheduler_config.CONFIG_SECTION, 'copy_task_results_back', |
| 40 | type=bool) |
Simran Basi | 8f858d0 | 2012-08-03 15:28:55 -0700 | [diff] [blame] | 41 | copy_parse_log_back = global_config.global_config.get_config_value( |
| 42 | scheduler_config.CONFIG_SECTION, 'copy_parse_log_back', |
| 43 | type=bool) |
Simran Basi | cced309 | 2012-08-02 15:09:23 -0700 | [diff] [blame] | 44 | special_task = source_path.startswith(HOSTS_JOB_SUBDIR) |
Simran Basi | 8f858d0 | 2012-08-03 15:28:55 -0700 | [diff] [blame] | 45 | parse_log = source_path.endswith(PARSE_LOG) |
| 46 | if (copy_task_results_back or not special_task) and ( |
| 47 | copy_parse_log_back or not parse_log): |
Simran Basi | cced309 | 2012-08-02 15:09:23 -0700 | [diff] [blame] | 48 | super(SiteDroneManager, self).copy_to_results_repository(process, |
Simran Basi | 8f858d0 | 2012-08-03 15:28:55 -0700 | [diff] [blame] | 49 | source_path, destination_path) |
Simran Basi | af9b8e7 | 2012-10-12 15:02:36 -0700 | [diff] [blame] | 50 | |
| 51 | |
| 52 | def kill_process(self, process): |
| 53 | """ |
| 54 | Kill the given process. |
| 55 | """ |
| 56 | logging.info('killing %s', process) |
| 57 | drone = self._get_drone_for_process(process) |
Simran Basi | 695e2d3 | 2013-01-04 14:59:19 -0800 | [diff] [blame] | 58 | drone.queue_kill_process(process) |
| 59 | |
| 60 | |
| 61 | def _add_drone(self, hostname): |
| 62 | """ |
| 63 | Forked from drone_manager.py |
| 64 | |
| 65 | Catches AutoservRunError if the drone fails initialization and does not |
| 66 | add it to the list of usable drones. |
| 67 | |
| 68 | @param hostname: Hostname of the drone we are trying to add. |
| 69 | """ |
| 70 | logging.info('Adding drone %s' % hostname) |
| 71 | drone = drones.get_drone(hostname) |
| 72 | if drone: |
| 73 | try: |
| 74 | drone.call('initialize', self.absolute_path('')) |
| 75 | except error.AutoservRunError as e: |
| 76 | logging.error('Failed to initialize drone %s with error: %s', |
| 77 | hostname, e) |
| 78 | return |
Fang Deng | 1d6c2a0 | 2013-04-17 15:25:45 -0700 | [diff] [blame] | 79 | self._drones[drone.hostname] = drone |
| 80 | |
| 81 | |
| 82 | @_timer.decorate |
| 83 | def refresh(self): |
| 84 | super(SiteDroneManager, self).refresh() |
| 85 | |
| 86 | |
| 87 | @_timer.decorate |
| 88 | def execute_actions(self): |
| 89 | super(SiteDroneManager, self).execute_actions() |