blob: 8469bab57471667665f73e28fcc067ab8ab24d66 [file] [log] [blame]
Dan Shi07e09af2013-04-12 09:31:29 -07001# pylint: disable-msg=C0111
2
Scott Zawalski91493c82013-01-25 16:15:20 -05003import os, 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 Millercb79ba72013-05-29 14:43:00 -070079 self.parser.add_option("--provision", action="store",
80 help="Labels to provision the machine to.")
Dan Shi07e09af2013-04-12 09:31:29 -070081 self.parser.add_option("-T", "--reset", action="store_true",
82 default=False,
83 help="Reset (cleanup and verify) all machines"
84 "after the job")
jadmanski0afbb632008-06-06 21:10:57 +000085 self.parser.add_option("-n", action="store_true",
86 dest="no_tee", default=False,
showard10d84172009-06-18 23:16:50 +000087 help="no teeing the status to stdout/err")
mbligh80e1eba2008-11-19 00:26:18 +000088 self.parser.add_option("-N", action="store_true",
89 dest="no_logging", default=False,
showard10d84172009-06-18 23:16:50 +000090 help="no logging")
91 self.parser.add_option('--verbose', action='store_true',
92 help='Include DEBUG messages in console output')
93 self.parser.add_option('--no_console_prefix', action='store_true',
94 help='Disable the logging prefix on console '
95 'output')
jadmanskid5ab8c52008-12-03 16:27:07 +000096 self.parser.add_option("-p", "--write-pidfile", action="store_true",
jadmanski0afbb632008-06-06 21:10:57 +000097 dest="write_pidfile", default=False,
mbligh4608b002010-01-05 18:22:35 +000098 help="write pidfile (pidfile name is determined "
99 "by --pidfile-label")
100 self.parser.add_option("--pidfile-label", action="store",
101 default="autoserv",
102 help="Determines filename to use as pidfile (if "
103 "-p is specified). Pidfile will be "
104 ".<label>_execute. Default to autoserv.")
105 self.parser.add_option("--use-existing-results", action="store_true",
106 help="Indicates that autoserv is working with "
107 "an existing results directory")
mbligha85d4672009-05-13 20:43:54 +0000108 self.parser.add_option("-a", "--args", dest='args',
109 help="additional args to pass to control file")
jadmanskifbc1f0a2008-07-09 14:12:54 +0000110 protection_levels = [host_protections.Protection.get_attr_name(s)
111 for i, s in host_protections.choices]
112 self.parser.add_option("--host-protection", action="store",
113 type="choice", dest="host_protection",
114 default=host_protections.default,
115 choices=protection_levels,
116 help="level of host protection during repair")
jadmanski0afbb632008-06-06 21:10:57 +0000117 self.parser.add_option("--ssh-user", action="store",
118 type="string", dest="ssh_user",
119 default="root",
120 help=("specify the user for ssh"
121 "connections"))
122 self.parser.add_option("--ssh-port", action="store",
123 type="int", dest="ssh_port",
124 default=22,
125 help=("specify the port to use for "
126 "ssh connections"))
127 self.parser.add_option("--ssh-pass", action="store",
128 type="string", dest="ssh_pass",
129 default="",
130 help=("specify the password to use "
131 "for ssh connections"))
jadmanskif22fea82008-11-26 20:57:07 +0000132 self.parser.add_option("--install-in-tmpdir", action="store_true",
133 dest="install_in_tmpdir", default=False,
134 help=("by default install autotest clients in "
135 "a temporary directory"))
jadmanskidef0c3c2009-03-25 20:07:10 +0000136 self.parser.add_option("--collect-crashinfo", action="store_true",
137 dest="collect_crashinfo", default=False,
138 help="just run crashinfo collection")
mblighe0cbc912010-03-11 18:03:07 +0000139 self.parser.add_option("--control-filename", action="store",
140 type="string", default=None,
141 help=("filename to use for the server control "
142 "file in the results directory"))
Scott Zawalski91493c82013-01-25 16:15:20 -0500143 self.parser.add_option("--test-retry", action="store",
144 type="int", default=0,
145 help=("Num of times to retry a test that failed "
146 "[default: %default]"))
beepscb6f1e22013-06-28 19:14:10 -0700147 self.parser.add_option("--verify_job_repo_url", action="store_true",
148 dest="verify_job_repo_url", default=False,
149 help=("Verify that the job_repo_url of the host "
150 "has staged packages for the job."))
Christopher Wileyf594c5e2013-07-03 18:25:30 -0700151 self.parser.add_option("--no_collect_crashinfo", action="store_true",
152 dest="skip_crash_collection", default=False,
153 help=("Turns off crash collection to shave time "
154 "off test runs."))
jadmanski0afbb632008-06-06 21:10:57 +0000155
156
157 def parse_args(self):
mblighf82a1822009-02-26 00:47:14 +0000158 self.options, self.args = self.parser.parse_args()
mbligh012623f2009-05-13 20:44:26 +0000159 if self.options.args:
mbligh374f3412009-05-13 21:29:45 +0000160 self.args += self.options.args.split()
mblighb7dcc7f2008-06-02 19:34:25 +0000161
162
mbligha7007722009-01-13 00:37:11 +0000163site_autoserv_parser = utils.import_site_class(
164 __file__, "autotest_lib.server.site_autoserv_parser",
165 "site_autoserv_parser", base_autoserv_parser)
mblighb7dcc7f2008-06-02 19:34:25 +0000166
167class autoserv_parser(site_autoserv_parser):
jadmanski0afbb632008-06-06 21:10:57 +0000168 pass
mblighb7dcc7f2008-06-02 19:34:25 +0000169
170
171# create the one and only one instance of autoserv_parser
172autoserv_parser = autoserv_parser()