blob: 9f54854486c9b013e7265b663e221d628e5fae97 [file] [log] [blame]
Simran Basicced3092012-08-02 15:09:23 -07001# 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.
4import logging
5
Chris Sosab838a0c2013-02-17 16:58:33 -08006from autotest_lib.client.common_lib import global_config, error
Simran Basi695e2d32013-01-04 14:59:19 -08007from autotest_lib.scheduler import drones, scheduler_config
Fang Deng1d6c2a02013-04-17 15:25:45 -07008from autotest_lib.site_utils.graphite import stats
Simran Basicced3092012-08-02 15:09:23 -07009
10HOSTS_JOB_SUBDIR = 'hosts/'
Simran Basi8f858d02012-08-03 15:28:55 -070011PARSE_LOG = '.parse.log'
Simran Basicced3092012-08-02 15:09:23 -070012
13
14class SiteDroneManager(object):
15
16
Fang Deng1d6c2a02013-04-17 15:25:45 -070017 _timer = stats.Timer('drone_manager')
18
19
Simran Basicced3092012-08-02 15:09:23 -070020 def copy_to_results_repository(self, process, source_path,
21 destination_path=None):
22 """
23 Copy results from the given process at source_path to destination_path
24 in the results repository.
25
26 This site subclassed version will only copy the results back for Special
27 Agent Tasks (Cleanup, Verify, Repair) that reside in the hosts/
28 subdirectory of results if the copy_task_results_back flag has been set
29 to True inside global_config.ini
Simran Basi8f858d02012-08-03 15:28:55 -070030
31 It will also only copy .parse.log files back to the scheduler if the
32 copy_parse_log_back flag in global_config.ini has been set to True.
Simran Basicced3092012-08-02 15:09:23 -070033 """
34 copy_task_results_back = global_config.global_config.get_config_value(
35 scheduler_config.CONFIG_SECTION, 'copy_task_results_back',
36 type=bool)
Simran Basi8f858d02012-08-03 15:28:55 -070037 copy_parse_log_back = global_config.global_config.get_config_value(
38 scheduler_config.CONFIG_SECTION, 'copy_parse_log_back',
39 type=bool)
Simran Basicced3092012-08-02 15:09:23 -070040 special_task = source_path.startswith(HOSTS_JOB_SUBDIR)
Simran Basi8f858d02012-08-03 15:28:55 -070041 parse_log = source_path.endswith(PARSE_LOG)
42 if (copy_task_results_back or not special_task) and (
43 copy_parse_log_back or not parse_log):
Simran Basicced3092012-08-02 15:09:23 -070044 super(SiteDroneManager, self).copy_to_results_repository(process,
Simran Basi8f858d02012-08-03 15:28:55 -070045 source_path, destination_path)
Simran Basiaf9b8e72012-10-12 15:02:36 -070046
47
48 def kill_process(self, process):
49 """
50 Kill the given process.
51 """
52 logging.info('killing %s', process)
53 drone = self._get_drone_for_process(process)
Simran Basi695e2d32013-01-04 14:59:19 -080054 drone.queue_kill_process(process)
55
56
57 def _add_drone(self, hostname):
58 """
59 Forked from drone_manager.py
60
61 Catches AutoservRunError if the drone fails initialization and does not
62 add it to the list of usable drones.
63
64 @param hostname: Hostname of the drone we are trying to add.
65 """
66 logging.info('Adding drone %s' % hostname)
67 drone = drones.get_drone(hostname)
68 if drone:
69 try:
70 drone.call('initialize', self.absolute_path(''))
71 except error.AutoservRunError as e:
72 logging.error('Failed to initialize drone %s with error: %s',
73 hostname, e)
74 return
Fang Deng1d6c2a02013-04-17 15:25:45 -070075 self._drones[drone.hostname] = drone
76
77
78 @_timer.decorate
79 def refresh(self):
80 super(SiteDroneManager, self).refresh()
81
82
83 @_timer.decorate
84 def execute_actions(self):
85 super(SiteDroneManager, self).execute_actions()