blob: 7eef156f82ed4e49c9ff556c1ef473f16c0e2c14 [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
Simran Basicced3092012-08-02 15:09:23 -07008
9HOSTS_JOB_SUBDIR = 'hosts/'
Simran Basi8f858d02012-08-03 15:28:55 -070010PARSE_LOG = '.parse.log'
Simran Basi882f15b2013-10-29 14:59:34 -070011ENABLE_ARCHIVING = global_config.global_config.get_config_value(
12 scheduler_config.CONFIG_SECTION, 'enable_archiving', type=bool)
Simran Basicced3092012-08-02 15:09:23 -070013
14
15class SiteDroneManager(object):
Prathmesh Prabhu36238622016-11-22 18:41:06 -080016 """
17 Site specific DroneManager extensions.
Simran Basicced3092012-08-02 15:09:23 -070018
Prathmesh Prabhu36238622016-11-22 18:41:06 -080019 When importing this class gains BaseDroneManager as a base class.
20 """
Simran Basicced3092012-08-02 15:09:23 -070021 def copy_to_results_repository(self, process, source_path,
22 destination_path=None):
23 """
24 Copy results from the given process at source_path to destination_path
25 in the results repository.
26
27 This site subclassed version will only copy the results back for Special
28 Agent Tasks (Cleanup, Verify, Repair) that reside in the hosts/
29 subdirectory of results if the copy_task_results_back flag has been set
30 to True inside global_config.ini
Simran Basi8f858d02012-08-03 15:28:55 -070031
32 It will also only copy .parse.log files back to the scheduler if the
33 copy_parse_log_back flag in global_config.ini has been set to True.
Simran Basicced3092012-08-02 15:09:23 -070034 """
Simran Basi882f15b2013-10-29 14:59:34 -070035 if not ENABLE_ARCHIVING:
36 return
Simran Basicced3092012-08-02 15:09:23 -070037 copy_task_results_back = global_config.global_config.get_config_value(
38 scheduler_config.CONFIG_SECTION, 'copy_task_results_back',
39 type=bool)
Simran Basi8f858d02012-08-03 15:28:55 -070040 copy_parse_log_back = global_config.global_config.get_config_value(
41 scheduler_config.CONFIG_SECTION, 'copy_parse_log_back',
42 type=bool)
Simran Basicced3092012-08-02 15:09:23 -070043 special_task = source_path.startswith(HOSTS_JOB_SUBDIR)
Simran Basi8f858d02012-08-03 15:28:55 -070044 parse_log = source_path.endswith(PARSE_LOG)
45 if (copy_task_results_back or not special_task) and (
46 copy_parse_log_back or not parse_log):
Simran Basicced3092012-08-02 15:09:23 -070047 super(SiteDroneManager, self).copy_to_results_repository(process,
Simran Basi8f858d02012-08-03 15:28:55 -070048 source_path, destination_path)
Simran Basiaf9b8e72012-10-12 15:02:36 -070049
50
51 def kill_process(self, process):
52 """
53 Kill the given process.
54 """
55 logging.info('killing %s', process)
56 drone = self._get_drone_for_process(process)
Simran Basi695e2d32013-01-04 14:59:19 -080057 drone.queue_kill_process(process)
58
59
60 def _add_drone(self, hostname):
61 """
62 Forked from drone_manager.py
63
64 Catches AutoservRunError if the drone fails initialization and does not
65 add it to the list of usable drones.
66
67 @param hostname: Hostname of the drone we are trying to add.
68 """
69 logging.info('Adding drone %s' % hostname)
70 drone = drones.get_drone(hostname)
71 if drone:
72 try:
73 drone.call('initialize', self.absolute_path(''))
74 except error.AutoservRunError as e:
75 logging.error('Failed to initialize drone %s with error: %s',
76 hostname, e)
77 return
Fang Deng1d6c2a02013-04-17 15:25:45 -070078 self._drones[drone.hostname] = drone