blob: 7d30dc30c6c625430811ee4ac6635d286a4001f5 [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
10
11
12def autoserv_run_job_command(autoserv_directory, machines,
13 results_directory=None, extra_args=[], job=None,
14 queue_entry=None, verbose=True,
15 write_pidfile=True):
16 """
17 Construct an autoserv command from a job or host queue entry.
18
19 @param autoserv_directory: Absolute path to directory containing the
20 autoserv executable.
21 @param machines: A machine or comma separated list of machines to run
22 job on. Leave as None or empty string for hostless job
23 (String).
24 @param results_directory: Absolute path to directory in which to deposit
25 results.
26 @param extra_args: Additional arguments to pass to autoserv
27 (List of Strings).
28 @param job: Job object. If supplied, -u owner, -l name, and --test-retry,
29 and -c or -s (client or server) parameters will be added.
30 @param queue_entry: HostQueueEntry object. If supplied and no job
31 was supplied, this will be used to lookup the job.
32 @param verbose: Boolean (default: True) for autoserv verbosity.
33 @param write_pidfile: Boolean (default: True) for whether autoserv should
34 write a pidfile.
35 @returns The autoserv command line as a list of executable + parameters.
36 """
37 command = [os.path.join(autoserv_directory, 'autoserv')]
38
39 if write_pidfile:
40 command.append('-p')
41
42 if results_directory:
43 command += ['-r', results_directory]
44
45 if machines:
46 command += ['-m', machines]
47
48 if job or queue_entry:
49 if not job:
50 job = queue_entry.job
51
52 owner = getattr(job, 'owner', None)
53 name = getattr(job, 'name', None)
54 test_retry = getattr(job, 'test_retry', None)
55 control_type = getattr(job, 'control_type', None)
56
57
58 if owner:
59 command += ['-u', owner]
60 if name:
61 command += ['-l', name]
62 if test_retry:
63 command += ['--test-retry='+str(test_retry)]
64 if control_type is not None: # still want to enter if control_type==0
65 control_type_value = control_data.CONTROL_TYPE.get_value(
66 control_type)
67 if control_type_value == control_data.CONTROL_TYPE.CLIENT:
68 command.append('-c')
69 elif control_type_value == control_data.CONTROL_TYPE.SERVER:
70 command.append('-s')
71
72 if verbose:
73 command.append('--verbose')
74
75 return command + extra_args