blob: d7bc1b32efa5575f8044d481aca4143294ac1d48 [file] [log] [blame]
Aviv Keshet308e7362013-05-21 14:43:16 -07001#!/usr/bin/python
2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import os
7
8import common
9from autotest_lib.client.common_lib import control_data
beeps5e2bb4a2013-10-28 11:26:45 -070010from autotest_lib.client.common_lib import global_config
11from autotest_lib.client.common_lib import utils
12try:
13 # test that imports autoserv_utils for vm_tests
14 from autotest_lib.scheduler import drone_manager
15except ImportError as e:
16 drone_manager = None
17 pass
18
19AUTOTEST_INSTALL_DIR = global_config.global_config.get_config_value('SCHEDULER',
20 'drone_installation_directory')
21autoserv_directory = os.path.join(AUTOTEST_INSTALL_DIR, 'server')
22autoserv_path = os.path.join(autoserv_directory, 'autoserv')
23
24def _parser_path_default(install_dir):
25 return os.path.join(install_dir, 'tko', 'parse')
26
27_parser_path_func = utils.import_site_function(
28 __file__, 'autotest_lib.scheduler.site_monitor_db',
29 'parser_path', _parser_path_default)
Aviv Keshet308e7362013-05-21 14:43:16 -070030
31
32def autoserv_run_job_command(autoserv_directory, machines,
33 results_directory=None, extra_args=[], job=None,
34 queue_entry=None, verbose=True,
Aviv Keshetc14951a2013-08-12 18:17:35 -070035 write_pidfile=True, fast_mode=False,
Aviv Keshete43bccf2013-08-14 14:11:59 -070036 ssh_verbosity=0,
Aviv Keshetc5947fa2013-09-04 14:06:29 -070037 no_console_prefix=False,
38 ssh_options=None,):
Aviv Keshet308e7362013-05-21 14:43:16 -070039 """
40 Construct an autoserv command from a job or host queue entry.
41
42 @param autoserv_directory: Absolute path to directory containing the
43 autoserv executable.
44 @param machines: A machine or comma separated list of machines to run
45 job on. Leave as None or empty string for hostless job
46 (String).
47 @param results_directory: Absolute path to directory in which to deposit
48 results.
49 @param extra_args: Additional arguments to pass to autoserv
50 (List of Strings).
51 @param job: Job object. If supplied, -u owner, -l name, and --test-retry,
52 and -c or -s (client or server) parameters will be added.
53 @param queue_entry: HostQueueEntry object. If supplied and no job
54 was supplied, this will be used to lookup the job.
55 @param verbose: Boolean (default: True) for autoserv verbosity.
56 @param write_pidfile: Boolean (default: True) for whether autoserv should
57 write a pidfile.
Christopher Wileyf6b5aae2013-07-09 10:14:02 -070058 @param fast_mode: bool to use fast mode (disables slow autotest features).
Aviv Keshetc14951a2013-08-12 18:17:35 -070059 @param ssh_verbosity: integer between 0 and 3 (inclusive) which sents the
60 verbosity level of ssh. Default: 0.
Aviv Keshete43bccf2013-08-14 14:11:59 -070061 @param no_console_prefix: If true, supress timestamps and other prefix info
62 in autoserv console logs.
Aviv Keshetc5947fa2013-09-04 14:06:29 -070063 @param ssh_options: A string giving extra arguments to be tacked on to
64 ssh commands.
Aviv Keshet308e7362013-05-21 14:43:16 -070065 @returns The autoserv command line as a list of executable + parameters.
66 """
67 command = [os.path.join(autoserv_directory, 'autoserv')]
68
69 if write_pidfile:
70 command.append('-p')
71
72 if results_directory:
73 command += ['-r', results_directory]
74
75 if machines:
76 command += ['-m', machines]
77
Aviv Keshetc14951a2013-08-12 18:17:35 -070078 if ssh_verbosity:
79 command += ['--ssh_verbosity', str(ssh_verbosity)]
80
Aviv Keshetc5947fa2013-09-04 14:06:29 -070081 if ssh_options:
82 command += ['--ssh_options', ssh_options]
83
Aviv Keshete43bccf2013-08-14 14:11:59 -070084 if no_console_prefix:
85 command += ['--no_console_prefix']
86
Aviv Keshet308e7362013-05-21 14:43:16 -070087 if job or queue_entry:
88 if not job:
89 job = queue_entry.job
90
91 owner = getattr(job, 'owner', None)
92 name = getattr(job, 'name', None)
93 test_retry = getattr(job, 'test_retry', None)
94 control_type = getattr(job, 'control_type', None)
95
96
97 if owner:
98 command += ['-u', owner]
99 if name:
100 command += ['-l', name]
101 if test_retry:
102 command += ['--test-retry='+str(test_retry)]
103 if control_type is not None: # still want to enter if control_type==0
104 control_type_value = control_data.CONTROL_TYPE.get_value(
105 control_type)
106 if control_type_value == control_data.CONTROL_TYPE.CLIENT:
107 command.append('-c')
108 elif control_type_value == control_data.CONTROL_TYPE.SERVER:
109 command.append('-s')
110
111 if verbose:
112 command.append('--verbose')
113
Christopher Wileyf6b5aae2013-07-09 10:14:02 -0700114 if fast_mode:
115 command.append('--disable_sysinfo')
116 command.append('--no_collect_crashinfo')
117
Aviv Keshet308e7362013-05-21 14:43:16 -0700118 return command + extra_args
beeps5e2bb4a2013-10-28 11:26:45 -0700119
120
121def _autoserv_command_line(machines, extra_args, job=None, queue_entry=None,
122 verbose=True):
123 """
124 @returns The autoserv command line as a list of executable + parameters.
125
126 @param machines - string - A machine or comma separated list of machines
127 for the (-m) flag.
128 @param extra_args - list - Additional arguments to pass to autoserv.
129 @param job - Job object - If supplied, -u owner, -l name, --test-retry,
130 and client -c or server -s parameters will be added.
131 @param queue_entry - A HostQueueEntry object - If supplied and no Job
132 object was supplied, this will be used to lookup the Job object.
133 """
134 if drone_manager is None:
135 raise ImportError('Unable to import drone_manager in autoserv_utils')
136
137 return autoserv_run_job_command(autoserv_directory,
138 machines, results_directory=drone_manager.WORKING_DIRECTORY,
139 extra_args=extra_args, job=job, queue_entry=queue_entry,
140 verbose=verbose)