blob: 5633bfb06664ccb4b9bd36e7359dba7b893ade3c [file] [log] [blame]
Dan Shi07e09af2013-04-12 09:31:29 -07001# pylint: disable-msg=C0111
2
Aviv Keshet8c1bb422013-09-13 17:13:36 -07003import os, shlex, sys, optparse
mblighb7dcc7f2008-06-02 19:34:25 +00004
mbligha7007722009-01-13 00:37:11 +00005from autotest_lib.client.common_lib import host_protections, utils
jadmanskifbc1f0a2008-07-09 14:12:54 +00006
mblighb7dcc7f2008-06-02 19:34:25 +00007
8class base_autoserv_parser(object):
jadmanski0afbb632008-06-06 21:10:57 +00009 """Custom command-line options parser for autoserv.
mblighb7dcc7f2008-06-02 19:34:25 +000010
jadmanski0afbb632008-06-06 21:10:57 +000011 We can't use the general getopt methods here, as there will be unknown
12 extra arguments that we pass down into the control file instead.
13 Thus we process the arguments by hand, for which we are duly repentant.
14 Making a single function here just makes it harder to read. Suck it up.
15 """
16 def __init__(self):
17 self.args = sys.argv[1:]
Eric Li861b2d52011-02-04 14:50:35 -080018 self.parser = optparse.OptionParser(usage="%prog [options] [control-file]")
jadmanski0afbb632008-06-06 21:10:57 +000019 self.setup_options()
mblighb7dcc7f2008-06-02 19:34:25 +000020
mblighf82a1822009-02-26 00:47:14 +000021 # parse an empty list of arguments in order to set self.options
22 # to default values so that codepaths that assume they are always
23 # reached from an autoserv process (when they actually are not)
24 # will still work
25 self.options, self.args = self.parser.parse_args(args=[])
26
mblighb7dcc7f2008-06-02 19:34:25 +000027
jadmanski0afbb632008-06-06 21:10:57 +000028 def setup_options(self):
29 self.parser.add_option("-m", action="store", type="string",
30 dest="machines",
31 help="list of machines")
32 self.parser.add_option("-M", action="store", type="string",
33 dest="machines_file",
34 help="list of machines from file")
35 self.parser.add_option("-c", action="store_true",
36 dest="client", default=False,
37 help="control file is client side")
mblighb2bea302008-07-24 20:25:57 +000038 self.parser.add_option("-s", action="store_true",
39 dest="server", default=False,
40 help="control file is server side")
jadmanski0afbb632008-06-06 21:10:57 +000041 self.parser.add_option("-r", action="store", type="string",
mbligh80e1eba2008-11-19 00:26:18 +000042 dest="results", default=None,
43 help="specify results directory")
jadmanski0afbb632008-06-06 21:10:57 +000044 self.parser.add_option("-l", action="store", type="string",
45 dest="label", default='',
46 help="label for the job")
mbligh374f3412009-05-13 21:29:45 +000047 self.parser.add_option("-G", action="store", type="string",
48 dest="group_name", default='',
49 help="The host_group_name to store in keyvals")
jadmanski0afbb632008-06-06 21:10:57 +000050 self.parser.add_option("-u", action="store", type="string",
51 dest="user",
52 default=os.environ.get('USER'),
53 help="username for the job")
54 self.parser.add_option("-P", action="store", type="string",
55 dest="parse_job",
56 default='',
mblighe7d9c602009-07-02 19:02:33 +000057 help="Parse the results of the job using this "
58 "execution tag. Accessable in control "
59 "files as job.tag.")
60 self.parser.add_option("--execution-tag", action="store", type="string",
61 dest="execution_tag", default='',
62 help="Accessable in control files as job.tag; "
63 "Defaults to the value passed to -P.")
jadmanski0afbb632008-06-06 21:10:57 +000064 self.parser.add_option("-i", action="store_true",
65 dest="install_before", default=False,
66 help="reinstall machines before running the job")
67 self.parser.add_option("-I", action="store_true",
68 dest="install_after", default=False,
69 help="reinstall machines after running the job")
jadmanski0afbb632008-06-06 21:10:57 +000070 self.parser.add_option("-v", action="store_true",
71 dest="verify", default=False,
72 help="verify the machines only")
73 self.parser.add_option("-R", action="store_true",
74 dest="repair", default=False,
75 help="repair the machines")
showard45ae8192008-11-05 19:32:53 +000076 self.parser.add_option("-C", "--cleanup", action="store_true",
77 default=False,
78 help="cleanup all machines after the job")
Alex Millerdf15ec52014-02-28 18:18:48 -080079 self.parser.add_option("--provision", action="store_true",
80 default=False,
Alex Miller667b5f22014-02-28 15:33:39 -080081 help="Provision the machine.")
82 self.parser.add_option("--job-labels", action="store",
83 help="Comma seperated job labels.")
Dan Shi07e09af2013-04-12 09:31:29 -070084 self.parser.add_option("-T", "--reset", action="store_true",
85 default=False,
86 help="Reset (cleanup and verify) all machines"
87 "after the job")
jadmanski0afbb632008-06-06 21:10:57 +000088 self.parser.add_option("-n", action="store_true",
89 dest="no_tee", default=False,
showard10d84172009-06-18 23:16:50 +000090 help="no teeing the status to stdout/err")
mbligh80e1eba2008-11-19 00:26:18 +000091 self.parser.add_option("-N", action="store_true",
92 dest="no_logging", default=False,
showard10d84172009-06-18 23:16:50 +000093 help="no logging")
94 self.parser.add_option('--verbose', action='store_true',
95 help='Include DEBUG messages in console output')
96 self.parser.add_option('--no_console_prefix', action='store_true',
97 help='Disable the logging prefix on console '
98 'output')
jadmanskid5ab8c52008-12-03 16:27:07 +000099 self.parser.add_option("-p", "--write-pidfile", action="store_true",
jadmanski0afbb632008-06-06 21:10:57 +0000100 dest="write_pidfile", default=False,
mbligh4608b002010-01-05 18:22:35 +0000101 help="write pidfile (pidfile name is determined "
102 "by --pidfile-label")
103 self.parser.add_option("--pidfile-label", action="store",
104 default="autoserv",
105 help="Determines filename to use as pidfile (if "
106 "-p is specified). Pidfile will be "
107 ".<label>_execute. Default to autoserv.")
108 self.parser.add_option("--use-existing-results", action="store_true",
109 help="Indicates that autoserv is working with "
110 "an existing results directory")
mbligha85d4672009-05-13 20:43:54 +0000111 self.parser.add_option("-a", "--args", dest='args',
112 help="additional args to pass to control file")
jadmanskifbc1f0a2008-07-09 14:12:54 +0000113 protection_levels = [host_protections.Protection.get_attr_name(s)
114 for i, s in host_protections.choices]
115 self.parser.add_option("--host-protection", action="store",
116 type="choice", dest="host_protection",
117 default=host_protections.default,
118 choices=protection_levels,
119 help="level of host protection during repair")
jadmanski0afbb632008-06-06 21:10:57 +0000120 self.parser.add_option("--ssh-user", action="store",
121 type="string", dest="ssh_user",
122 default="root",
123 help=("specify the user for ssh"
124 "connections"))
125 self.parser.add_option("--ssh-port", action="store",
126 type="int", dest="ssh_port",
127 default=22,
128 help=("specify the port to use for "
129 "ssh connections"))
130 self.parser.add_option("--ssh-pass", action="store",
131 type="string", dest="ssh_pass",
132 default="",
133 help=("specify the password to use "
134 "for ssh connections"))
jadmanskif22fea82008-11-26 20:57:07 +0000135 self.parser.add_option("--install-in-tmpdir", action="store_true",
136 dest="install_in_tmpdir", default=False,
137 help=("by default install autotest clients in "
138 "a temporary directory"))
jadmanskidef0c3c2009-03-25 20:07:10 +0000139 self.parser.add_option("--collect-crashinfo", action="store_true",
140 dest="collect_crashinfo", default=False,
141 help="just run crashinfo collection")
mblighe0cbc912010-03-11 18:03:07 +0000142 self.parser.add_option("--control-filename", action="store",
143 type="string", default=None,
144 help=("filename to use for the server control "
145 "file in the results directory"))
Scott Zawalski91493c82013-01-25 16:15:20 -0500146 self.parser.add_option("--test-retry", action="store",
147 type="int", default=0,
148 help=("Num of times to retry a test that failed "
149 "[default: %default]"))
beepscb6f1e22013-06-28 19:14:10 -0700150 self.parser.add_option("--verify_job_repo_url", action="store_true",
151 dest="verify_job_repo_url", default=False,
152 help=("Verify that the job_repo_url of the host "
153 "has staged packages for the job."))
Christopher Wileyf594c5e2013-07-03 18:25:30 -0700154 self.parser.add_option("--no_collect_crashinfo", action="store_true",
155 dest="skip_crash_collection", default=False,
156 help=("Turns off crash collection to shave time "
157 "off test runs."))
Christopher Wiley8a91f232013-07-09 11:02:27 -0700158 self.parser.add_option("--disable_sysinfo", action="store_true",
159 dest="disable_sysinfo", default=False,
160 help="Turns off sysinfo collection to shave "
161 "time off test runs.")
Aviv Keshet18ee3142013-08-12 15:01:51 -0700162 self.parser.add_option("--ssh_verbosity", action="store",
163 dest="ssh_verbosity", default=0,
164 type="choice", choices=["0", "1", "2", "3"],
165 help=("Verbosity level for ssh, between 0 "
166 "and 3 inclusive. [default: 0]"))
Aviv Keshetc5947fa2013-09-04 14:06:29 -0700167 self.parser.add_option("--ssh_options", action="store",
Fang Deng6cc20de2013-09-06 15:47:32 -0700168 dest="ssh_options", default='',
Aviv Keshetc5947fa2013-09-04 14:06:29 -0700169 help=("A string giving command line flags "
170 "that will be included in ssh commands"))
jadmanski0afbb632008-06-06 21:10:57 +0000171
172
173 def parse_args(self):
mblighf82a1822009-02-26 00:47:14 +0000174 self.options, self.args = self.parser.parse_args()
mbligh012623f2009-05-13 20:44:26 +0000175 if self.options.args:
Aviv Keshet8c1bb422013-09-13 17:13:36 -0700176 self.args += shlex.split(self.options.args)
mblighb7dcc7f2008-06-02 19:34:25 +0000177
178
mbligha7007722009-01-13 00:37:11 +0000179site_autoserv_parser = utils.import_site_class(
180 __file__, "autotest_lib.server.site_autoserv_parser",
181 "site_autoserv_parser", base_autoserv_parser)
mblighb7dcc7f2008-06-02 19:34:25 +0000182
183class autoserv_parser(site_autoserv_parser):
jadmanski0afbb632008-06-06 21:10:57 +0000184 pass
mblighb7dcc7f2008-06-02 19:34:25 +0000185
186
187# create the one and only one instance of autoserv_parser
188autoserv_parser = autoserv_parser()