blob: cbb7f6c21daf6e859b472eb9cd01c3af64cf67df [file] [log] [blame]
mbligha6f13082008-06-05 23:53:46 +00001import os, sys, getopt, optparse
mblighb7dcc7f2008-06-02 19:34:25 +00002
mbligha7007722009-01-13 00:37:11 +00003from autotest_lib.client.common_lib import host_protections, utils
jadmanskifbc1f0a2008-07-09 14:12:54 +00004
mblighb7dcc7f2008-06-02 19:34:25 +00005
6class base_autoserv_parser(object):
jadmanski0afbb632008-06-06 21:10:57 +00007 """Custom command-line options parser for autoserv.
mblighb7dcc7f2008-06-02 19:34:25 +00008
jadmanski0afbb632008-06-06 21:10:57 +00009 We can't use the general getopt methods here, as there will be unknown
10 extra arguments that we pass down into the control file instead.
11 Thus we process the arguments by hand, for which we are duly repentant.
12 Making a single function here just makes it harder to read. Suck it up.
13 """
14 def __init__(self):
15 self.args = sys.argv[1:]
16 self.parser = optparse.OptionParser()
17 self.setup_options()
mblighb7dcc7f2008-06-02 19:34:25 +000018
mblighf82a1822009-02-26 00:47:14 +000019 # parse an empty list of arguments in order to set self.options
20 # to default values so that codepaths that assume they are always
21 # reached from an autoserv process (when they actually are not)
22 # will still work
23 self.options, self.args = self.parser.parse_args(args=[])
24
mblighb7dcc7f2008-06-02 19:34:25 +000025
jadmanski0afbb632008-06-06 21:10:57 +000026 def setup_options(self):
27 self.parser.add_option("-m", action="store", type="string",
28 dest="machines",
29 help="list of machines")
30 self.parser.add_option("-M", action="store", type="string",
31 dest="machines_file",
32 help="list of machines from file")
33 self.parser.add_option("-c", action="store_true",
34 dest="client", default=False,
35 help="control file is client side")
mblighb2bea302008-07-24 20:25:57 +000036 self.parser.add_option("-s", action="store_true",
37 dest="server", default=False,
38 help="control file is server side")
jadmanski0afbb632008-06-06 21:10:57 +000039 self.parser.add_option("-r", action="store", type="string",
mbligh80e1eba2008-11-19 00:26:18 +000040 dest="results", default=None,
41 help="specify results directory")
jadmanski0afbb632008-06-06 21:10:57 +000042 self.parser.add_option("-l", action="store", type="string",
43 dest="label", default='',
44 help="label for the job")
mbligh374f3412009-05-13 21:29:45 +000045 self.parser.add_option("-G", action="store", type="string",
46 dest="group_name", default='',
47 help="The host_group_name to store in keyvals")
jadmanski0afbb632008-06-06 21:10:57 +000048 self.parser.add_option("-u", action="store", type="string",
49 dest="user",
50 default=os.environ.get('USER'),
51 help="username for the job")
52 self.parser.add_option("-P", action="store", type="string",
53 dest="parse_job",
54 default='',
mblighe7d9c602009-07-02 19:02:33 +000055 help="Parse the results of the job using this "
56 "execution tag. Accessable in control "
57 "files as job.tag.")
58 self.parser.add_option("--execution-tag", action="store", type="string",
59 dest="execution_tag", default='',
60 help="Accessable in control files as job.tag; "
61 "Defaults to the value passed to -P.")
jadmanski0afbb632008-06-06 21:10:57 +000062 self.parser.add_option("-i", action="store_true",
63 dest="install_before", default=False,
64 help="reinstall machines before running the job")
65 self.parser.add_option("-I", action="store_true",
66 dest="install_after", default=False,
67 help="reinstall machines after running the job")
jadmanski0afbb632008-06-06 21:10:57 +000068 self.parser.add_option("-v", action="store_true",
69 dest="verify", default=False,
70 help="verify the machines only")
71 self.parser.add_option("-R", action="store_true",
72 dest="repair", default=False,
73 help="repair the machines")
showard45ae8192008-11-05 19:32:53 +000074 self.parser.add_option("-C", "--cleanup", action="store_true",
75 default=False,
76 help="cleanup all machines after the job")
jadmanski0afbb632008-06-06 21:10:57 +000077 self.parser.add_option("-n", action="store_true",
78 dest="no_tee", default=False,
showard10d84172009-06-18 23:16:50 +000079 help="no teeing the status to stdout/err")
mbligh80e1eba2008-11-19 00:26:18 +000080 self.parser.add_option("-N", action="store_true",
81 dest="no_logging", default=False,
showard10d84172009-06-18 23:16:50 +000082 help="no logging")
83 self.parser.add_option('--verbose', action='store_true',
84 help='Include DEBUG messages in console output')
85 self.parser.add_option('--no_console_prefix', action='store_true',
86 help='Disable the logging prefix on console '
87 'output')
jadmanskid5ab8c52008-12-03 16:27:07 +000088 self.parser.add_option("-p", "--write-pidfile", action="store_true",
jadmanski0afbb632008-06-06 21:10:57 +000089 dest="write_pidfile", default=False,
mbligh4608b002010-01-05 18:22:35 +000090 help="write pidfile (pidfile name is determined "
91 "by --pidfile-label")
92 self.parser.add_option("--pidfile-label", action="store",
93 default="autoserv",
94 help="Determines filename to use as pidfile (if "
95 "-p is specified). Pidfile will be "
96 ".<label>_execute. Default to autoserv.")
97 self.parser.add_option("--use-existing-results", action="store_true",
98 help="Indicates that autoserv is working with "
99 "an existing results directory")
mbligha85d4672009-05-13 20:43:54 +0000100 self.parser.add_option("-a", "--args", dest='args',
101 help="additional args to pass to control file")
jadmanskifbc1f0a2008-07-09 14:12:54 +0000102 protection_levels = [host_protections.Protection.get_attr_name(s)
103 for i, s in host_protections.choices]
104 self.parser.add_option("--host-protection", action="store",
105 type="choice", dest="host_protection",
106 default=host_protections.default,
107 choices=protection_levels,
108 help="level of host protection during repair")
jadmanski0afbb632008-06-06 21:10:57 +0000109 self.parser.add_option("--ssh-user", action="store",
110 type="string", dest="ssh_user",
111 default="root",
112 help=("specify the user for ssh"
113 "connections"))
114 self.parser.add_option("--ssh-port", action="store",
115 type="int", dest="ssh_port",
116 default=22,
117 help=("specify the port to use for "
118 "ssh connections"))
119 self.parser.add_option("--ssh-pass", action="store",
120 type="string", dest="ssh_pass",
121 default="",
122 help=("specify the password to use "
123 "for ssh connections"))
jadmanskif22fea82008-11-26 20:57:07 +0000124 self.parser.add_option("--install-in-tmpdir", action="store_true",
125 dest="install_in_tmpdir", default=False,
126 help=("by default install autotest clients in "
127 "a temporary directory"))
jadmanskidef0c3c2009-03-25 20:07:10 +0000128 self.parser.add_option("--collect-crashinfo", action="store_true",
129 dest="collect_crashinfo", default=False,
130 help="just run crashinfo collection")
mblighe0cbc912010-03-11 18:03:07 +0000131 self.parser.add_option("--control-filename", action="store",
132 type="string", default=None,
133 help=("filename to use for the server control "
134 "file in the results directory"))
jadmanski0afbb632008-06-06 21:10:57 +0000135
136
137 def parse_args(self):
mblighf82a1822009-02-26 00:47:14 +0000138 self.options, self.args = self.parser.parse_args()
mbligh012623f2009-05-13 20:44:26 +0000139 if self.options.args:
mbligh374f3412009-05-13 21:29:45 +0000140 self.args += self.options.args.split()
mblighb7dcc7f2008-06-02 19:34:25 +0000141
142
mbligha7007722009-01-13 00:37:11 +0000143site_autoserv_parser = utils.import_site_class(
144 __file__, "autotest_lib.server.site_autoserv_parser",
145 "site_autoserv_parser", base_autoserv_parser)
mblighb7dcc7f2008-06-02 19:34:25 +0000146
147class autoserv_parser(site_autoserv_parser):
jadmanski0afbb632008-06-06 21:10:57 +0000148 pass
mblighb7dcc7f2008-06-02 19:34:25 +0000149
150
151# create the one and only one instance of autoserv_parser
152autoserv_parser = autoserv_parser()