blob: 2db605254b93347030f24bae01cc86988a57c0cf [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
beeps5e2bb4a2013-10-28 11:26:45 -070011try:
12 # test that imports autoserv_utils for vm_tests
13 from autotest_lib.scheduler import drone_manager
14except ImportError as e:
15 drone_manager = None
16 pass
17
18AUTOTEST_INSTALL_DIR = global_config.global_config.get_config_value('SCHEDULER',
19 'drone_installation_directory')
20autoserv_directory = os.path.join(AUTOTEST_INSTALL_DIR, 'server')
21autoserv_path = os.path.join(autoserv_directory, 'autoserv')
22
Aviv Keshet308e7362013-05-21 14:43:16 -070023
24def autoserv_run_job_command(autoserv_directory, machines,
25 results_directory=None, extra_args=[], job=None,
26 queue_entry=None, verbose=True,
Aviv Keshetc14951a2013-08-12 18:17:35 -070027 write_pidfile=True, fast_mode=False,
Aviv Keshete43bccf2013-08-14 14:11:59 -070028 ssh_verbosity=0,
Aviv Keshetc5947fa2013-09-04 14:06:29 -070029 no_console_prefix=False,
30 ssh_options=None,):
Aviv Keshet308e7362013-05-21 14:43:16 -070031 """
32 Construct an autoserv command from a job or host queue entry.
33
34 @param autoserv_directory: Absolute path to directory containing the
35 autoserv executable.
36 @param machines: A machine or comma separated list of machines to run
37 job on. Leave as None or empty string for hostless job
38 (String).
39 @param results_directory: Absolute path to directory in which to deposit
40 results.
41 @param extra_args: Additional arguments to pass to autoserv
42 (List of Strings).
43 @param job: Job object. If supplied, -u owner, -l name, and --test-retry,
44 and -c or -s (client or server) parameters will be added.
45 @param queue_entry: HostQueueEntry object. If supplied and no job
46 was supplied, this will be used to lookup the job.
47 @param verbose: Boolean (default: True) for autoserv verbosity.
48 @param write_pidfile: Boolean (default: True) for whether autoserv should
49 write a pidfile.
Christopher Wileyf6b5aae2013-07-09 10:14:02 -070050 @param fast_mode: bool to use fast mode (disables slow autotest features).
Aviv Keshetc14951a2013-08-12 18:17:35 -070051 @param ssh_verbosity: integer between 0 and 3 (inclusive) which sents the
52 verbosity level of ssh. Default: 0.
Aviv Keshete43bccf2013-08-14 14:11:59 -070053 @param no_console_prefix: If true, supress timestamps and other prefix info
54 in autoserv console logs.
Aviv Keshetc5947fa2013-09-04 14:06:29 -070055 @param ssh_options: A string giving extra arguments to be tacked on to
56 ssh commands.
Aviv Keshet308e7362013-05-21 14:43:16 -070057 @returns The autoserv command line as a list of executable + parameters.
58 """
59 command = [os.path.join(autoserv_directory, 'autoserv')]
60
61 if write_pidfile:
62 command.append('-p')
63
64 if results_directory:
65 command += ['-r', results_directory]
66
67 if machines:
68 command += ['-m', machines]
69
Aviv Keshetc14951a2013-08-12 18:17:35 -070070 if ssh_verbosity:
71 command += ['--ssh_verbosity', str(ssh_verbosity)]
72
Aviv Keshetc5947fa2013-09-04 14:06:29 -070073 if ssh_options:
74 command += ['--ssh_options', ssh_options]
75
Aviv Keshete43bccf2013-08-14 14:11:59 -070076 if no_console_prefix:
77 command += ['--no_console_prefix']
78
Aviv Keshet308e7362013-05-21 14:43:16 -070079 if job or queue_entry:
80 if not job:
81 job = queue_entry.job
82
83 owner = getattr(job, 'owner', None)
84 name = getattr(job, 'name', None)
85 test_retry = getattr(job, 'test_retry', None)
86 control_type = getattr(job, 'control_type', None)
87
88
89 if owner:
90 command += ['-u', owner]
91 if name:
92 command += ['-l', name]
93 if test_retry:
94 command += ['--test-retry='+str(test_retry)]
95 if control_type is not None: # still want to enter if control_type==0
96 control_type_value = control_data.CONTROL_TYPE.get_value(
97 control_type)
98 if control_type_value == control_data.CONTROL_TYPE.CLIENT:
99 command.append('-c')
100 elif control_type_value == control_data.CONTROL_TYPE.SERVER:
101 command.append('-s')
102
103 if verbose:
104 command.append('--verbose')
105
Christopher Wileyf6b5aae2013-07-09 10:14:02 -0700106 if fast_mode:
107 command.append('--disable_sysinfo')
108 command.append('--no_collect_crashinfo')
109
Aviv Keshet308e7362013-05-21 14:43:16 -0700110 return command + extra_args
beeps5e2bb4a2013-10-28 11:26:45 -0700111
112
113def _autoserv_command_line(machines, extra_args, job=None, queue_entry=None,
114 verbose=True):
115 """
116 @returns The autoserv command line as a list of executable + parameters.
117
118 @param machines - string - A machine or comma separated list of machines
119 for the (-m) flag.
120 @param extra_args - list - Additional arguments to pass to autoserv.
121 @param job - Job object - If supplied, -u owner, -l name, --test-retry,
122 and client -c or server -s parameters will be added.
123 @param queue_entry - A HostQueueEntry object - If supplied and no Job
124 object was supplied, this will be used to lookup the Job object.
125 """
126 if drone_manager is None:
127 raise ImportError('Unable to import drone_manager in autoserv_utils')
128
129 return autoserv_run_job_command(autoserv_directory,
130 machines, results_directory=drone_manager.WORKING_DIRECTORY,
131 extra_args=extra_args, job=job, queue_entry=queue_entry,
132 verbose=verbose)