root / lib / client / gnt_debug.py @ 8f096849
History | View | Annotate | Download (22.9 kB)
1 | c2855a12 | Michael Hanselmann | #
|
---|---|---|---|
2 | fd3ee040 | Iustin Pop | #
|
3 | fd3ee040 | Iustin Pop | |
4 | 9b12c120 | Iustin Pop | # Copyright (C) 2006, 2007, 2010, 2011, 2012 Google Inc.
|
5 | fd3ee040 | Iustin Pop | #
|
6 | fd3ee040 | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | fd3ee040 | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | fd3ee040 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | fd3ee040 | Iustin Pop | # (at your option) any later version.
|
10 | fd3ee040 | Iustin Pop | #
|
11 | fd3ee040 | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | fd3ee040 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | fd3ee040 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | fd3ee040 | Iustin Pop | # General Public License for more details.
|
15 | fd3ee040 | Iustin Pop | #
|
16 | fd3ee040 | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | fd3ee040 | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | fd3ee040 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | fd3ee040 | Iustin Pop | # 02110-1301, USA.
|
20 | fd3ee040 | Iustin Pop | |
21 | 7260cfbe | Iustin Pop | """Debugging commands"""
|
22 | fd3ee040 | Iustin Pop | |
23 | b459a848 | Andrea Spadaccini | # pylint: disable=W0401,W0614,C0103
|
24 | 2f79bd34 | Iustin Pop | # W0401: Wildcard import ganeti.cli
|
25 | 2f79bd34 | Iustin Pop | # W0614: Unused import %s from wildcard import (since we need cli)
|
26 | 7260cfbe | Iustin Pop | # C0103: Invalid name gnt-backup
|
27 | 2f79bd34 | Iustin Pop | |
28 | f1c66d13 | Iustin Pop | import simplejson |
29 | f1c66d13 | Iustin Pop | import time |
30 | e58f87a9 | Michael Hanselmann | import socket |
31 | e58f87a9 | Michael Hanselmann | import logging |
32 | f1c66d13 | Iustin Pop | |
33 | fd3ee040 | Iustin Pop | from ganeti.cli import * |
34 | 9d5ba39a | Iustin Pop | from ganeti import cli |
35 | e58f87a9 | Michael Hanselmann | from ganeti import constants |
36 | fd3ee040 | Iustin Pop | from ganeti import opcodes |
37 | fd3ee040 | Iustin Pop | from ganeti import utils |
38 | fd3ee040 | Iustin Pop | from ganeti import errors |
39 | 92ae7daf | Michael Hanselmann | from ganeti import compat |
40 | c2d22fed | Michael Hanselmann | from ganeti import ht |
41 | fd3ee040 | Iustin Pop | |
42 | fd3ee040 | Iustin Pop | |
43 | 19b9ba9a | Michael Hanselmann | #: Default fields for L{ListLocks}
|
44 | 19b9ba9a | Michael Hanselmann | _LIST_LOCKS_DEF_FIELDS = [ |
45 | 19b9ba9a | Michael Hanselmann | "name",
|
46 | 19b9ba9a | Michael Hanselmann | "mode",
|
47 | 19b9ba9a | Michael Hanselmann | "owner",
|
48 | c31825f7 | Michael Hanselmann | "pending",
|
49 | 19b9ba9a | Michael Hanselmann | ] |
50 | 19b9ba9a | Michael Hanselmann | |
51 | 19b9ba9a | Michael Hanselmann | |
52 | fd3ee040 | Iustin Pop | def Delay(opts, args): |
53 | fd3ee040 | Iustin Pop | """Sleeps for a while
|
54 | fd3ee040 | Iustin Pop |
|
55 | 6099bfcf | Iustin Pop | @param opts: the command line options selected by the user
|
56 | 6099bfcf | Iustin Pop | @type args: list
|
57 | 6099bfcf | Iustin Pop | @param args: should contain only one element, the duration
|
58 | 6099bfcf | Iustin Pop | the sleep
|
59 | 6099bfcf | Iustin Pop | @rtype: int
|
60 | 6099bfcf | Iustin Pop | @return: the desired exit code
|
61 | 6099bfcf | Iustin Pop |
|
62 | fd3ee040 | Iustin Pop | """
|
63 | fd3ee040 | Iustin Pop | delay = float(args[0]) |
64 | fd3ee040 | Iustin Pop | op = opcodes.OpTestDelay(duration=delay, |
65 | fd3ee040 | Iustin Pop | on_master=opts.on_master, |
66 | 85a87e21 | Guido Trotter | on_nodes=opts.on_nodes, |
67 | 85a87e21 | Guido Trotter | repeat=opts.repeat) |
68 | bb600388 | Michael Hanselmann | SubmitOrSend(op, opts) |
69 | fd3ee040 | Iustin Pop | |
70 | fd3ee040 | Iustin Pop | return 0 |
71 | fd3ee040 | Iustin Pop | |
72 | fd3ee040 | Iustin Pop | |
73 | f1c66d13 | Iustin Pop | def GenericOpCodes(opts, args): |
74 | 6099bfcf | Iustin Pop | """Send any opcode to the master.
|
75 | 6099bfcf | Iustin Pop |
|
76 | 6099bfcf | Iustin Pop | @param opts: the command line options selected by the user
|
77 | 6099bfcf | Iustin Pop | @type args: list
|
78 | 6099bfcf | Iustin Pop | @param args: should contain only one element, the path of
|
79 | 6099bfcf | Iustin Pop | the file with the opcode definition
|
80 | 6099bfcf | Iustin Pop | @rtype: int
|
81 | 6099bfcf | Iustin Pop | @return: the desired exit code
|
82 | f1c66d13 | Iustin Pop |
|
83 | f1c66d13 | Iustin Pop | """
|
84 | 9d5ba39a | Iustin Pop | cl = cli.GetClient() |
85 | cb573a31 | Iustin Pop | jex = cli.JobExecutor(cl=cl, verbose=opts.verbose, opts=opts) |
86 | 9d95c3af | Iustin Pop | |
87 | 9d95c3af | Iustin Pop | job_cnt = 0
|
88 | 9d95c3af | Iustin Pop | op_cnt = 0
|
89 | 9d95c3af | Iustin Pop | if opts.timing_stats:
|
90 | 9d95c3af | Iustin Pop | ToStdout("Loading...")
|
91 | 9d95c3af | Iustin Pop | for job_idx in range(opts.rep_job): |
92 | 9d95c3af | Iustin Pop | for fname in args: |
93 | b459a848 | Andrea Spadaccini | # pylint: disable=W0142
|
94 | 4d5fe81b | Michael Hanselmann | op_data = simplejson.loads(utils.ReadFile(fname)) |
95 | 9d95c3af | Iustin Pop | op_list = [opcodes.OpCode.LoadOpCode(val) for val in op_data] |
96 | 9d95c3af | Iustin Pop | op_list = op_list * opts.rep_op |
97 | 9d95c3af | Iustin Pop | jex.QueueJob("file %s/%d" % (fname, job_idx), *op_list)
|
98 | 9d95c3af | Iustin Pop | op_cnt += len(op_list)
|
99 | 9d95c3af | Iustin Pop | job_cnt += 1
|
100 | 9d95c3af | Iustin Pop | |
101 | 9d95c3af | Iustin Pop | if opts.timing_stats:
|
102 | 9d95c3af | Iustin Pop | t1 = time.time() |
103 | 9d95c3af | Iustin Pop | ToStdout("Submitting...")
|
104 | 4d5fe81b | Michael Hanselmann | |
105 | 66ecc479 | Guido Trotter | jex.SubmitPending(each=opts.each) |
106 | 9d95c3af | Iustin Pop | |
107 | 9d95c3af | Iustin Pop | if opts.timing_stats:
|
108 | 9d95c3af | Iustin Pop | t2 = time.time() |
109 | 9d95c3af | Iustin Pop | ToStdout("Executing...")
|
110 | b59252fe | Iustin Pop | |
111 | b59252fe | Iustin Pop | jex.GetResults() |
112 | 9d95c3af | Iustin Pop | if opts.timing_stats:
|
113 | 9d95c3af | Iustin Pop | t3 = time.time() |
114 | 9d95c3af | Iustin Pop | ToStdout("C:op %4d" % op_cnt)
|
115 | 9d95c3af | Iustin Pop | ToStdout("C:job %4d" % job_cnt)
|
116 | e687ec01 | Michael Hanselmann | ToStdout("T:submit %4.4f" % (t2 - t1))
|
117 | e687ec01 | Michael Hanselmann | ToStdout("T:exec %4.4f" % (t3 - t2))
|
118 | e687ec01 | Michael Hanselmann | ToStdout("T:total %4.4f" % (t3 - t1))
|
119 | f1c66d13 | Iustin Pop | return 0 |
120 | f1c66d13 | Iustin Pop | |
121 | f1c66d13 | Iustin Pop | |
122 | d61df03e | Iustin Pop | def TestAllocator(opts, args): |
123 | 6099bfcf | Iustin Pop | """Runs the test allocator opcode.
|
124 | d61df03e | Iustin Pop |
|
125 | 6099bfcf | Iustin Pop | @param opts: the command line options selected by the user
|
126 | 6099bfcf | Iustin Pop | @type args: list
|
127 | 6099bfcf | Iustin Pop | @param args: should contain only one element, the iallocator name
|
128 | 6099bfcf | Iustin Pop | @rtype: int
|
129 | 6099bfcf | Iustin Pop | @return: the desired exit code
|
130 | 6099bfcf | Iustin Pop |
|
131 | 6099bfcf | Iustin Pop | """
|
132 | d61df03e | Iustin Pop | try:
|
133 | fdbe29ee | Michael Hanselmann | disks = [{ |
134 | fdbe29ee | Michael Hanselmann | constants.IDISK_SIZE: utils.ParseUnit(val), |
135 | fdbe29ee | Michael Hanselmann | constants.IDISK_MODE: constants.DISK_RDWR, |
136 | fdbe29ee | Michael Hanselmann | } for val in opts.disks.split(",")] |
137 | d61df03e | Iustin Pop | except errors.UnitParseError, err:
|
138 | 3a24c527 | Iustin Pop | ToStderr("Invalid disks parameter '%s': %s", opts.disks, err)
|
139 | d61df03e | Iustin Pop | return 1 |
140 | d61df03e | Iustin Pop | |
141 | d61df03e | Iustin Pop | nics = [val.split("/") for val in opts.nics.split(",")] |
142 | d61df03e | Iustin Pop | for row in nics: |
143 | d61df03e | Iustin Pop | while len(row) < 3: |
144 | d61df03e | Iustin Pop | row.append(None)
|
145 | d61df03e | Iustin Pop | for i in range(3): |
146 | d0c8c01d | Iustin Pop | if row[i] == "": |
147 | d61df03e | Iustin Pop | row[i] = None
|
148 | fdbe29ee | Michael Hanselmann | nic_dict = [{ |
149 | fdbe29ee | Michael Hanselmann | constants.INIC_MAC: v[0],
|
150 | fdbe29ee | Michael Hanselmann | constants.INIC_IP: v[1],
|
151 | fdbe29ee | Michael Hanselmann | # The iallocator interface defines a "bridge" item
|
152 | fdbe29ee | Michael Hanselmann | "bridge": v[2], |
153 | fdbe29ee | Michael Hanselmann | } for v in nics] |
154 | d61df03e | Iustin Pop | |
155 | d61df03e | Iustin Pop | if opts.tags is None: |
156 | d61df03e | Iustin Pop | opts.tags = [] |
157 | d61df03e | Iustin Pop | else:
|
158 | d61df03e | Iustin Pop | opts.tags = opts.tags.split(",")
|
159 | 36bbf5b0 | Iustin Pop | if opts.target_groups is None: |
160 | 36bbf5b0 | Iustin Pop | target_groups = [] |
161 | 36bbf5b0 | Iustin Pop | else:
|
162 | 36bbf5b0 | Iustin Pop | target_groups = opts.target_groups |
163 | d61df03e | Iustin Pop | |
164 | d61df03e | Iustin Pop | op = opcodes.OpTestAllocator(mode=opts.mode, |
165 | d61df03e | Iustin Pop | name=args[0],
|
166 | 42c161cf | Michael Hanselmann | instances=args, |
167 | dd47a0f0 | Iustin Pop | memory=opts.memory, |
168 | d61df03e | Iustin Pop | disks=disks, |
169 | d61df03e | Iustin Pop | disk_template=opts.disk_template, |
170 | d61df03e | Iustin Pop | nics=nic_dict, |
171 | 705dd60e | Iustin Pop | os=opts.os, |
172 | d61df03e | Iustin Pop | vcpus=opts.vcpus, |
173 | d61df03e | Iustin Pop | tags=opts.tags, |
174 | d61df03e | Iustin Pop | direction=opts.direction, |
175 | 55b7e783 | Iustin Pop | iallocator=opts.iallocator, |
176 | 60152bbe | Michael Hanselmann | evac_mode=opts.evac_mode, |
177 | 09123222 | René Nussbaumer | target_groups=target_groups, |
178 | 3c049cd3 | René Nussbaumer | spindle_use=opts.spindle_use, |
179 | 3c049cd3 | René Nussbaumer | count=opts.count) |
180 | 400ca2f7 | Iustin Pop | result = SubmitOpCode(op, opts=opts) |
181 | 3a24c527 | Iustin Pop | ToStdout("%s" % result)
|
182 | d61df03e | Iustin Pop | return 0 |
183 | d61df03e | Iustin Pop | |
184 | d61df03e | Iustin Pop | |
185 | c2d22fed | Michael Hanselmann | def _TestJobDependency(opts): |
186 | c2d22fed | Michael Hanselmann | """Tests job dependencies.
|
187 | c2d22fed | Michael Hanselmann |
|
188 | c2d22fed | Michael Hanselmann | """
|
189 | c2d22fed | Michael Hanselmann | ToStdout("Testing job dependencies")
|
190 | c2d22fed | Michael Hanselmann | |
191 | c2d22fed | Michael Hanselmann | cl = cli.GetClient() |
192 | c2d22fed | Michael Hanselmann | |
193 | c2d22fed | Michael Hanselmann | try:
|
194 | c2d22fed | Michael Hanselmann | SubmitOpCode(opcodes.OpTestDelay(duration=0, depends=[(-1, None)]), cl=cl) |
195 | c2d22fed | Michael Hanselmann | except errors.GenericError, err:
|
196 | c2d22fed | Michael Hanselmann | if opts.debug:
|
197 | 9b12c120 | Iustin Pop | ToStdout("Ignoring error for 'wrong dependencies' test: %s", err)
|
198 | c2d22fed | Michael Hanselmann | else:
|
199 | c2d22fed | Michael Hanselmann | raise errors.OpExecError("Submitting plain opcode with relative job ID" |
200 | c2d22fed | Michael Hanselmann | " did not fail as expected")
|
201 | c2d22fed | Michael Hanselmann | |
202 | c2d22fed | Michael Hanselmann | # TODO: Test dependencies on errors
|
203 | c2d22fed | Michael Hanselmann | jobs = [ |
204 | c2d22fed | Michael Hanselmann | [opcodes.OpTestDelay(duration=1)],
|
205 | c2d22fed | Michael Hanselmann | [opcodes.OpTestDelay(duration=1,
|
206 | c2d22fed | Michael Hanselmann | depends=[(-1, [])])],
|
207 | c2d22fed | Michael Hanselmann | [opcodes.OpTestDelay(duration=1,
|
208 | c2d22fed | Michael Hanselmann | depends=[(-2, [constants.JOB_STATUS_SUCCESS])])],
|
209 | c2d22fed | Michael Hanselmann | [opcodes.OpTestDelay(duration=1,
|
210 | c2d22fed | Michael Hanselmann | depends=[])], |
211 | c2d22fed | Michael Hanselmann | [opcodes.OpTestDelay(duration=1,
|
212 | c2d22fed | Michael Hanselmann | depends=[(-2, [constants.JOB_STATUS_SUCCESS])])],
|
213 | c2d22fed | Michael Hanselmann | ] |
214 | c2d22fed | Michael Hanselmann | |
215 | c2d22fed | Michael Hanselmann | # Function for checking result
|
216 | c2d22fed | Michael Hanselmann | check_fn = ht.TListOf(ht.TAnd(ht.TIsLength(2),
|
217 | c2d22fed | Michael Hanselmann | ht.TItems([ht.TBool, |
218 | c2d22fed | Michael Hanselmann | ht.TOr(ht.TNonEmptyString, |
219 | c2d22fed | Michael Hanselmann | ht.TJobId)]))) |
220 | c2d22fed | Michael Hanselmann | |
221 | c2d22fed | Michael Hanselmann | result = cl.SubmitManyJobs(jobs) |
222 | c2d22fed | Michael Hanselmann | if not check_fn(result): |
223 | c2d22fed | Michael Hanselmann | raise errors.OpExecError("Job submission doesn't match %s: %s" % |
224 | c2d22fed | Michael Hanselmann | (check_fn, result)) |
225 | c2d22fed | Michael Hanselmann | |
226 | c2d22fed | Michael Hanselmann | # Wait for jobs to finish
|
227 | c2d22fed | Michael Hanselmann | jex = JobExecutor(cl=cl, opts=opts) |
228 | c2d22fed | Michael Hanselmann | |
229 | c2d22fed | Michael Hanselmann | for (status, job_id) in result: |
230 | c2d22fed | Michael Hanselmann | jex.AddJobId(None, status, job_id)
|
231 | c2d22fed | Michael Hanselmann | |
232 | c2d22fed | Michael Hanselmann | job_results = jex.GetResults() |
233 | c2d22fed | Michael Hanselmann | if not compat.all(row[0] for row in job_results): |
234 | c2d22fed | Michael Hanselmann | raise errors.OpExecError("At least one of the submitted jobs failed: %s" % |
235 | c2d22fed | Michael Hanselmann | job_results) |
236 | c2d22fed | Michael Hanselmann | |
237 | c2d22fed | Michael Hanselmann | # Get details about jobs
|
238 | c2d22fed | Michael Hanselmann | data = cl.QueryJobs([job_id for (_, job_id) in result], |
239 | c2d22fed | Michael Hanselmann | ["id", "opexec", "ops"]) |
240 | c2d22fed | Michael Hanselmann | data_job_id = [job_id for (job_id, _, _) in data] |
241 | c2d22fed | Michael Hanselmann | data_opexec = [opexec for (_, opexec, _) in data] |
242 | c2d22fed | Michael Hanselmann | data_op = [[opcodes.OpCode.LoadOpCode(op) for op in ops] |
243 | c2d22fed | Michael Hanselmann | for (_, _, ops) in data] |
244 | c2d22fed | Michael Hanselmann | |
245 | c2d22fed | Michael Hanselmann | assert compat.all(not op.depends or len(op.depends) == 1 |
246 | c2d22fed | Michael Hanselmann | for ops in data_op |
247 | c2d22fed | Michael Hanselmann | for op in ops) |
248 | c2d22fed | Michael Hanselmann | |
249 | c2d22fed | Michael Hanselmann | # Check resolved job IDs in dependencies
|
250 | c2d22fed | Michael Hanselmann | for (job_idx, res_jobdep) in [(1, data_job_id[0]), |
251 | c2d22fed | Michael Hanselmann | (2, data_job_id[0]), |
252 | c2d22fed | Michael Hanselmann | (4, data_job_id[2])]: |
253 | c2d22fed | Michael Hanselmann | if data_op[job_idx][0].depends[0][0] != res_jobdep: |
254 | c2d22fed | Michael Hanselmann | raise errors.OpExecError("Job %s's opcode doesn't depend on correct job" |
255 | c2d22fed | Michael Hanselmann | " ID (%s)" % (job_idx, res_jobdep))
|
256 | c2d22fed | Michael Hanselmann | |
257 | c2d22fed | Michael Hanselmann | # Check execution order
|
258 | c2d22fed | Michael Hanselmann | if not (data_opexec[0] <= data_opexec[1] and |
259 | c2d22fed | Michael Hanselmann | data_opexec[0] <= data_opexec[2] and |
260 | c2d22fed | Michael Hanselmann | data_opexec[2] <= data_opexec[4]): |
261 | c2d22fed | Michael Hanselmann | raise errors.OpExecError("Jobs did not run in correct order: %s" % data) |
262 | c2d22fed | Michael Hanselmann | |
263 | c2d22fed | Michael Hanselmann | assert len(jobs) == 5 and compat.all(len(ops) == 1 for ops in jobs) |
264 | c2d22fed | Michael Hanselmann | |
265 | c2d22fed | Michael Hanselmann | ToStdout("Job dependency tests were successful")
|
266 | c2d22fed | Michael Hanselmann | |
267 | c2d22fed | Michael Hanselmann | |
268 | 92ae7daf | Michael Hanselmann | def _TestJobSubmission(opts): |
269 | 92ae7daf | Michael Hanselmann | """Tests submitting jobs.
|
270 | 92ae7daf | Michael Hanselmann |
|
271 | 92ae7daf | Michael Hanselmann | """
|
272 | 92ae7daf | Michael Hanselmann | ToStdout("Testing job submission")
|
273 | 92ae7daf | Michael Hanselmann | |
274 | 92ae7daf | Michael Hanselmann | testdata = [ |
275 | 92ae7daf | Michael Hanselmann | (0, 0, constants.OP_PRIO_LOWEST), |
276 | 92ae7daf | Michael Hanselmann | (0, 0, constants.OP_PRIO_HIGHEST), |
277 | 92ae7daf | Michael Hanselmann | ] |
278 | 92ae7daf | Michael Hanselmann | |
279 | 92ae7daf | Michael Hanselmann | for priority in (constants.OP_PRIO_SUBMIT_VALID | |
280 | 92ae7daf | Michael Hanselmann | frozenset([constants.OP_PRIO_LOWEST,
|
281 | 92ae7daf | Michael Hanselmann | constants.OP_PRIO_HIGHEST])): |
282 | 92ae7daf | Michael Hanselmann | for offset in [-1, +1]: |
283 | 92ae7daf | Michael Hanselmann | testdata.extend([ |
284 | 92ae7daf | Michael Hanselmann | (0, 0, priority + offset), |
285 | 92ae7daf | Michael Hanselmann | (3, 0, priority + offset), |
286 | 92ae7daf | Michael Hanselmann | (0, 3, priority + offset), |
287 | 92ae7daf | Michael Hanselmann | (4, 2, priority + offset), |
288 | 92ae7daf | Michael Hanselmann | ]) |
289 | 92ae7daf | Michael Hanselmann | |
290 | 92ae7daf | Michael Hanselmann | cl = cli.GetClient() |
291 | 92ae7daf | Michael Hanselmann | |
292 | 92ae7daf | Michael Hanselmann | for before, after, failpriority in testdata: |
293 | 92ae7daf | Michael Hanselmann | ops = [] |
294 | 92ae7daf | Michael Hanselmann | ops.extend([opcodes.OpTestDelay(duration=0) for _ in range(before)]) |
295 | 92ae7daf | Michael Hanselmann | ops.append(opcodes.OpTestDelay(duration=0, priority=failpriority))
|
296 | 92ae7daf | Michael Hanselmann | ops.extend([opcodes.OpTestDelay(duration=0) for _ in range(after)]) |
297 | 92ae7daf | Michael Hanselmann | |
298 | 92ae7daf | Michael Hanselmann | try:
|
299 | 92ae7daf | Michael Hanselmann | cl.SubmitJob(ops) |
300 | 92ae7daf | Michael Hanselmann | except errors.GenericError, err:
|
301 | 92ae7daf | Michael Hanselmann | if opts.debug:
|
302 | 9b12c120 | Iustin Pop | ToStdout("Ignoring error for 'wrong priority' test: %s", err)
|
303 | 92ae7daf | Michael Hanselmann | else:
|
304 | 92ae7daf | Michael Hanselmann | raise errors.OpExecError("Submitting opcode with priority %s did not" |
305 | 92ae7daf | Michael Hanselmann | " fail when it should (allowed are %s)" %
|
306 | 92ae7daf | Michael Hanselmann | (failpriority, constants.OP_PRIO_SUBMIT_VALID)) |
307 | 92ae7daf | Michael Hanselmann | |
308 | 92ae7daf | Michael Hanselmann | jobs = [ |
309 | 92ae7daf | Michael Hanselmann | [opcodes.OpTestDelay(duration=0),
|
310 | 92ae7daf | Michael Hanselmann | opcodes.OpTestDelay(duration=0, dry_run=False), |
311 | 92ae7daf | Michael Hanselmann | opcodes.OpTestDelay(duration=0, dry_run=True)], |
312 | 92ae7daf | Michael Hanselmann | ops, |
313 | 92ae7daf | Michael Hanselmann | ] |
314 | 92ae7daf | Michael Hanselmann | result = cl.SubmitManyJobs(jobs) |
315 | 92ae7daf | Michael Hanselmann | if not (len(result) == 2 and |
316 | 92ae7daf | Michael Hanselmann | compat.all(len(i) == 2 for i in result) and |
317 | 76b62028 | Iustin Pop | isinstance(result[0][1], int) and |
318 | 76b62028 | Iustin Pop | isinstance(result[1][1], basestring) and |
319 | 92ae7daf | Michael Hanselmann | result[0][0] and not result[1][0]): |
320 | 92ae7daf | Michael Hanselmann | raise errors.OpExecError("Submitting multiple jobs did not work as" |
321 | 92ae7daf | Michael Hanselmann | " expected, result %s" % result)
|
322 | 92ae7daf | Michael Hanselmann | assert len(result) == 2 |
323 | 92ae7daf | Michael Hanselmann | |
324 | 92ae7daf | Michael Hanselmann | ToStdout("Job submission tests were successful")
|
325 | 92ae7daf | Michael Hanselmann | |
326 | 92ae7daf | Michael Hanselmann | |
327 | e58f87a9 | Michael Hanselmann | class _JobQueueTestReporter(cli.StdioJobPollReportCb): |
328 | e58f87a9 | Michael Hanselmann | def __init__(self): |
329 | e58f87a9 | Michael Hanselmann | """Initializes this class.
|
330 | e58f87a9 | Michael Hanselmann |
|
331 | e58f87a9 | Michael Hanselmann | """
|
332 | e58f87a9 | Michael Hanselmann | cli.StdioJobPollReportCb.__init__(self)
|
333 | f99010b2 | Michael Hanselmann | self._expected_msgcount = 0 |
334 | f99010b2 | Michael Hanselmann | self._all_testmsgs = []
|
335 | f99010b2 | Michael Hanselmann | self._testmsgs = None |
336 | e58f87a9 | Michael Hanselmann | self._job_id = None |
337 | e58f87a9 | Michael Hanselmann | |
338 | e58f87a9 | Michael Hanselmann | def GetTestMessages(self): |
339 | e58f87a9 | Michael Hanselmann | """Returns all test log messages received so far.
|
340 | e58f87a9 | Michael Hanselmann |
|
341 | e58f87a9 | Michael Hanselmann | """
|
342 | f99010b2 | Michael Hanselmann | return self._all_testmsgs |
343 | e58f87a9 | Michael Hanselmann | |
344 | e58f87a9 | Michael Hanselmann | def GetJobId(self): |
345 | e58f87a9 | Michael Hanselmann | """Returns the job ID.
|
346 | e58f87a9 | Michael Hanselmann |
|
347 | e58f87a9 | Michael Hanselmann | """
|
348 | e58f87a9 | Michael Hanselmann | return self._job_id |
349 | e58f87a9 | Michael Hanselmann | |
350 | e58f87a9 | Michael Hanselmann | def ReportLogMessage(self, job_id, serial, timestamp, log_type, log_msg): |
351 | e58f87a9 | Michael Hanselmann | """Handles a log message.
|
352 | e58f87a9 | Michael Hanselmann |
|
353 | e58f87a9 | Michael Hanselmann | """
|
354 | e58f87a9 | Michael Hanselmann | if self._job_id is None: |
355 | e58f87a9 | Michael Hanselmann | self._job_id = job_id
|
356 | e58f87a9 | Michael Hanselmann | elif self._job_id != job_id: |
357 | e58f87a9 | Michael Hanselmann | raise errors.ProgrammerError("The same reporter instance was used for" |
358 | e58f87a9 | Michael Hanselmann | " more than one job")
|
359 | e58f87a9 | Michael Hanselmann | |
360 | e58f87a9 | Michael Hanselmann | if log_type == constants.ELOG_JQUEUE_TEST:
|
361 | e58f87a9 | Michael Hanselmann | (sockname, test, arg) = log_msg |
362 | e58f87a9 | Michael Hanselmann | return self._ProcessTestMessage(job_id, sockname, test, arg) |
363 | e58f87a9 | Michael Hanselmann | |
364 | e58f87a9 | Michael Hanselmann | elif (log_type == constants.ELOG_MESSAGE and |
365 | e58f87a9 | Michael Hanselmann | log_msg.startswith(constants.JQT_MSGPREFIX)): |
366 | f99010b2 | Michael Hanselmann | if self._testmsgs is None: |
367 | f99010b2 | Michael Hanselmann | raise errors.OpExecError("Received test message without a preceding" |
368 | f99010b2 | Michael Hanselmann | " start message")
|
369 | f99010b2 | Michael Hanselmann | testmsg = log_msg[len(constants.JQT_MSGPREFIX):]
|
370 | f99010b2 | Michael Hanselmann | self._testmsgs.append(testmsg)
|
371 | f99010b2 | Michael Hanselmann | self._all_testmsgs.append(testmsg)
|
372 | e58f87a9 | Michael Hanselmann | return
|
373 | e58f87a9 | Michael Hanselmann | |
374 | e58f87a9 | Michael Hanselmann | return cli.StdioJobPollReportCb.ReportLogMessage(self, job_id, serial, |
375 | e58f87a9 | Michael Hanselmann | timestamp, log_type, |
376 | e58f87a9 | Michael Hanselmann | log_msg) |
377 | e58f87a9 | Michael Hanselmann | |
378 | e58f87a9 | Michael Hanselmann | def _ProcessTestMessage(self, job_id, sockname, test, arg): |
379 | e58f87a9 | Michael Hanselmann | """Handles a job queue test message.
|
380 | e58f87a9 | Michael Hanselmann |
|
381 | e58f87a9 | Michael Hanselmann | """
|
382 | e58f87a9 | Michael Hanselmann | if test not in constants.JQT_ALL: |
383 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Received invalid test message %s" % test) |
384 | e58f87a9 | Michael Hanselmann | |
385 | e58f87a9 | Michael Hanselmann | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
386 | e58f87a9 | Michael Hanselmann | try:
|
387 | e58f87a9 | Michael Hanselmann | sock.settimeout(30.0)
|
388 | e58f87a9 | Michael Hanselmann | |
389 | e58f87a9 | Michael Hanselmann | logging.debug("Connecting to %s", sockname)
|
390 | e58f87a9 | Michael Hanselmann | sock.connect(sockname) |
391 | e58f87a9 | Michael Hanselmann | |
392 | e58f87a9 | Michael Hanselmann | logging.debug("Checking status")
|
393 | e58f87a9 | Michael Hanselmann | jobdetails = cli.GetClient().QueryJobs([job_id], ["status"])[0] |
394 | e58f87a9 | Michael Hanselmann | if not jobdetails: |
395 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Can't find job %s" % job_id) |
396 | e58f87a9 | Michael Hanselmann | |
397 | e58f87a9 | Michael Hanselmann | status = jobdetails[0]
|
398 | e58f87a9 | Michael Hanselmann | |
399 | e58f87a9 | Michael Hanselmann | logging.debug("Status of job %s is %s", job_id, status)
|
400 | e58f87a9 | Michael Hanselmann | |
401 | e58f87a9 | Michael Hanselmann | if test == constants.JQT_EXPANDNAMES:
|
402 | 47099cd1 | Michael Hanselmann | if status != constants.JOB_STATUS_WAITING:
|
403 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Job status while expanding names is '%s'," |
404 | e58f87a9 | Michael Hanselmann | " not '%s' as expected" %
|
405 | 47099cd1 | Michael Hanselmann | (status, constants.JOB_STATUS_WAITING)) |
406 | e58f87a9 | Michael Hanselmann | elif test in (constants.JQT_EXEC, constants.JQT_LOGMSG): |
407 | e58f87a9 | Michael Hanselmann | if status != constants.JOB_STATUS_RUNNING:
|
408 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Job status while executing opcode is '%s'," |
409 | e58f87a9 | Michael Hanselmann | " not '%s' as expected" %
|
410 | e58f87a9 | Michael Hanselmann | (status, constants.JOB_STATUS_RUNNING)) |
411 | e58f87a9 | Michael Hanselmann | |
412 | f99010b2 | Michael Hanselmann | if test == constants.JQT_STARTMSG:
|
413 | f99010b2 | Michael Hanselmann | logging.debug("Expecting %s test messages", arg)
|
414 | f99010b2 | Michael Hanselmann | self._testmsgs = []
|
415 | f99010b2 | Michael Hanselmann | elif test == constants.JQT_LOGMSG:
|
416 | e58f87a9 | Michael Hanselmann | if len(self._testmsgs) != arg: |
417 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Received %s test messages when %s are" |
418 | e58f87a9 | Michael Hanselmann | " expected" % (len(self._testmsgs), arg)) |
419 | e58f87a9 | Michael Hanselmann | finally:
|
420 | e58f87a9 | Michael Hanselmann | logging.debug("Closing socket")
|
421 | e58f87a9 | Michael Hanselmann | sock.close() |
422 | e58f87a9 | Michael Hanselmann | |
423 | e58f87a9 | Michael Hanselmann | |
424 | e58f87a9 | Michael Hanselmann | def TestJobqueue(opts, _): |
425 | e58f87a9 | Michael Hanselmann | """Runs a few tests on the job queue.
|
426 | e58f87a9 | Michael Hanselmann |
|
427 | e58f87a9 | Michael Hanselmann | """
|
428 | 92ae7daf | Michael Hanselmann | _TestJobSubmission(opts) |
429 | c2d22fed | Michael Hanselmann | _TestJobDependency(opts) |
430 | 92ae7daf | Michael Hanselmann | |
431 | f99010b2 | Michael Hanselmann | (TM_SUCCESS, |
432 | f99010b2 | Michael Hanselmann | TM_MULTISUCCESS, |
433 | f99010b2 | Michael Hanselmann | TM_FAIL, |
434 | f99010b2 | Michael Hanselmann | TM_PARTFAIL) = range(4) |
435 | b8028dcf | Michael Hanselmann | TM_ALL = compat.UniqueFrozenset([ |
436 | b8028dcf | Michael Hanselmann | TM_SUCCESS, |
437 | b8028dcf | Michael Hanselmann | TM_MULTISUCCESS, |
438 | b8028dcf | Michael Hanselmann | TM_FAIL, |
439 | b8028dcf | Michael Hanselmann | TM_PARTFAIL, |
440 | b8028dcf | Michael Hanselmann | ]) |
441 | f99010b2 | Michael Hanselmann | |
442 | f99010b2 | Michael Hanselmann | for mode in TM_ALL: |
443 | f99010b2 | Michael Hanselmann | test_messages = [ |
444 | f99010b2 | Michael Hanselmann | "Testing mode %s" % mode,
|
445 | f99010b2 | Michael Hanselmann | "Hello World",
|
446 | f99010b2 | Michael Hanselmann | "A",
|
447 | f99010b2 | Michael Hanselmann | "",
|
448 | f99010b2 | Michael Hanselmann | "B"
|
449 | f99010b2 | Michael Hanselmann | "Foo|bar|baz",
|
450 | f99010b2 | Michael Hanselmann | utils.TimestampForFilename(), |
451 | f99010b2 | Michael Hanselmann | ] |
452 | f99010b2 | Michael Hanselmann | |
453 | f99010b2 | Michael Hanselmann | fail = mode in (TM_FAIL, TM_PARTFAIL)
|
454 | f99010b2 | Michael Hanselmann | |
455 | f99010b2 | Michael Hanselmann | if mode == TM_PARTFAIL:
|
456 | f99010b2 | Michael Hanselmann | ToStdout("Testing partial job failure")
|
457 | f99010b2 | Michael Hanselmann | ops = [ |
458 | b469eb4d | Iustin Pop | opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True, |
459 | b469eb4d | Iustin Pop | log_messages=test_messages, fail=False),
|
460 | b469eb4d | Iustin Pop | opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True, |
461 | b469eb4d | Iustin Pop | log_messages=test_messages, fail=False),
|
462 | b469eb4d | Iustin Pop | opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True, |
463 | b469eb4d | Iustin Pop | log_messages=test_messages, fail=True),
|
464 | b469eb4d | Iustin Pop | opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True, |
465 | b469eb4d | Iustin Pop | log_messages=test_messages, fail=False),
|
466 | f99010b2 | Michael Hanselmann | ] |
467 | f99010b2 | Michael Hanselmann | expect_messages = 3 * [test_messages]
|
468 | f99010b2 | Michael Hanselmann | expect_opstatus = [ |
469 | f99010b2 | Michael Hanselmann | constants.OP_STATUS_SUCCESS, |
470 | f99010b2 | Michael Hanselmann | constants.OP_STATUS_SUCCESS, |
471 | f99010b2 | Michael Hanselmann | constants.OP_STATUS_ERROR, |
472 | f99010b2 | Michael Hanselmann | constants.OP_STATUS_ERROR, |
473 | f99010b2 | Michael Hanselmann | ] |
474 | f99010b2 | Michael Hanselmann | expect_resultlen = 2
|
475 | f99010b2 | Michael Hanselmann | elif mode == TM_MULTISUCCESS:
|
476 | f99010b2 | Michael Hanselmann | ToStdout("Testing multiple successful opcodes")
|
477 | f99010b2 | Michael Hanselmann | ops = [ |
478 | b469eb4d | Iustin Pop | opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True, |
479 | b469eb4d | Iustin Pop | log_messages=test_messages, fail=False),
|
480 | b469eb4d | Iustin Pop | opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True, |
481 | b469eb4d | Iustin Pop | log_messages=test_messages, fail=False),
|
482 | f99010b2 | Michael Hanselmann | ] |
483 | f99010b2 | Michael Hanselmann | expect_messages = 2 * [test_messages]
|
484 | f99010b2 | Michael Hanselmann | expect_opstatus = [ |
485 | f99010b2 | Michael Hanselmann | constants.OP_STATUS_SUCCESS, |
486 | f99010b2 | Michael Hanselmann | constants.OP_STATUS_SUCCESS, |
487 | f99010b2 | Michael Hanselmann | ] |
488 | f99010b2 | Michael Hanselmann | expect_resultlen = 2
|
489 | e58f87a9 | Michael Hanselmann | else:
|
490 | f99010b2 | Michael Hanselmann | if mode == TM_SUCCESS:
|
491 | f99010b2 | Michael Hanselmann | ToStdout("Testing job success")
|
492 | f99010b2 | Michael Hanselmann | expect_opstatus = [constants.OP_STATUS_SUCCESS] |
493 | f99010b2 | Michael Hanselmann | elif mode == TM_FAIL:
|
494 | f99010b2 | Michael Hanselmann | ToStdout("Testing job failure")
|
495 | f99010b2 | Michael Hanselmann | expect_opstatus = [constants.OP_STATUS_ERROR] |
496 | f99010b2 | Michael Hanselmann | else:
|
497 | f99010b2 | Michael Hanselmann | raise errors.ProgrammerError("Unknown test mode %s" % mode) |
498 | f99010b2 | Michael Hanselmann | |
499 | f99010b2 | Michael Hanselmann | ops = [ |
500 | b469eb4d | Iustin Pop | opcodes.OpTestJqueue(notify_waitlock=True,
|
501 | b469eb4d | Iustin Pop | notify_exec=True,
|
502 | b469eb4d | Iustin Pop | log_messages=test_messages, |
503 | 3c286190 | Dimitris Aragiorgis | fail=fail), |
504 | f99010b2 | Michael Hanselmann | ] |
505 | f99010b2 | Michael Hanselmann | expect_messages = [test_messages] |
506 | f99010b2 | Michael Hanselmann | expect_resultlen = 1
|
507 | f99010b2 | Michael Hanselmann | |
508 | f99010b2 | Michael Hanselmann | cl = cli.GetClient() |
509 | f99010b2 | Michael Hanselmann | cli.SetGenericOpcodeOpts(ops, opts) |
510 | f99010b2 | Michael Hanselmann | |
511 | f99010b2 | Michael Hanselmann | # Send job to master daemon
|
512 | f99010b2 | Michael Hanselmann | job_id = cli.SendJob(ops, cl=cl) |
513 | e58f87a9 | Michael Hanselmann | |
514 | e58f87a9 | Michael Hanselmann | reporter = _JobQueueTestReporter() |
515 | f99010b2 | Michael Hanselmann | results = None
|
516 | f99010b2 | Michael Hanselmann | |
517 | e58f87a9 | Michael Hanselmann | try:
|
518 | f99010b2 | Michael Hanselmann | results = cli.PollJob(job_id, cl=cl, reporter=reporter) |
519 | f99010b2 | Michael Hanselmann | except errors.OpExecError, err:
|
520 | e58f87a9 | Michael Hanselmann | if not fail: |
521 | e58f87a9 | Michael Hanselmann | raise
|
522 | 9b12c120 | Iustin Pop | ToStdout("Ignoring error for 'job fail' test: %s", err)
|
523 | e58f87a9 | Michael Hanselmann | else:
|
524 | e58f87a9 | Michael Hanselmann | if fail:
|
525 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Job didn't fail when it should") |
526 | e58f87a9 | Michael Hanselmann | |
527 | f99010b2 | Michael Hanselmann | # Check length of result
|
528 | f99010b2 | Michael Hanselmann | if fail:
|
529 | f99010b2 | Michael Hanselmann | if results is not None: |
530 | f99010b2 | Michael Hanselmann | raise errors.OpExecError("Received result from failed job") |
531 | f99010b2 | Michael Hanselmann | elif len(results) != expect_resultlen: |
532 | f99010b2 | Michael Hanselmann | raise errors.OpExecError("Received %s results (%s), expected %s" % |
533 | f99010b2 | Michael Hanselmann | (len(results), results, expect_resultlen))
|
534 | f99010b2 | Michael Hanselmann | |
535 | e58f87a9 | Michael Hanselmann | # Check received log messages
|
536 | f99010b2 | Michael Hanselmann | all_messages = [i for j in expect_messages for i in j] |
537 | f99010b2 | Michael Hanselmann | if reporter.GetTestMessages() != all_messages:
|
538 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Received test messages don't match input" |
539 | e58f87a9 | Michael Hanselmann | " (input %r, received %r)" %
|
540 | f99010b2 | Michael Hanselmann | (all_messages, reporter.GetTestMessages())) |
541 | e58f87a9 | Michael Hanselmann | |
542 | e58f87a9 | Michael Hanselmann | # Check final status
|
543 | f99010b2 | Michael Hanselmann | reported_job_id = reporter.GetJobId() |
544 | f99010b2 | Michael Hanselmann | if reported_job_id != job_id:
|
545 | f99010b2 | Michael Hanselmann | raise errors.OpExecError("Reported job ID %s doesn't match" |
546 | f99010b2 | Michael Hanselmann | "submission job ID %s" %
|
547 | f99010b2 | Michael Hanselmann | (reported_job_id, job_id)) |
548 | e58f87a9 | Michael Hanselmann | |
549 | f99010b2 | Michael Hanselmann | jobdetails = cli.GetClient().QueryJobs([job_id], ["status", "opstatus"])[0] |
550 | e58f87a9 | Michael Hanselmann | if not jobdetails: |
551 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Can't find job %s" % job_id) |
552 | e58f87a9 | Michael Hanselmann | |
553 | e58f87a9 | Michael Hanselmann | if fail:
|
554 | e58f87a9 | Michael Hanselmann | exp_status = constants.JOB_STATUS_ERROR |
555 | e58f87a9 | Michael Hanselmann | else:
|
556 | e58f87a9 | Michael Hanselmann | exp_status = constants.JOB_STATUS_SUCCESS |
557 | e58f87a9 | Michael Hanselmann | |
558 | f99010b2 | Michael Hanselmann | (final_status, final_opstatus) = jobdetails |
559 | e58f87a9 | Michael Hanselmann | if final_status != exp_status:
|
560 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Final job status is %s, not %s as expected" % |
561 | e58f87a9 | Michael Hanselmann | (final_status, exp_status)) |
562 | f99010b2 | Michael Hanselmann | if len(final_opstatus) != len(ops): |
563 | f99010b2 | Michael Hanselmann | raise errors.OpExecError("Did not receive status for all opcodes (got %s," |
564 | f99010b2 | Michael Hanselmann | " expected %s)" %
|
565 | f99010b2 | Michael Hanselmann | (len(final_opstatus), len(ops))) |
566 | f99010b2 | Michael Hanselmann | if final_opstatus != expect_opstatus:
|
567 | f99010b2 | Michael Hanselmann | raise errors.OpExecError("Opcode status is %s, expected %s" % |
568 | f99010b2 | Michael Hanselmann | (final_opstatus, expect_opstatus)) |
569 | f99010b2 | Michael Hanselmann | |
570 | f99010b2 | Michael Hanselmann | ToStdout("Job queue test successful")
|
571 | e58f87a9 | Michael Hanselmann | |
572 | e58f87a9 | Michael Hanselmann | return 0 |
573 | e58f87a9 | Michael Hanselmann | |
574 | e58f87a9 | Michael Hanselmann | |
575 | b459a848 | Andrea Spadaccini | def ListLocks(opts, args): # pylint: disable=W0613 |
576 | 19b9ba9a | Michael Hanselmann | """List all locks.
|
577 | 19b9ba9a | Michael Hanselmann |
|
578 | 19b9ba9a | Michael Hanselmann | @param opts: the command line options selected by the user
|
579 | 19b9ba9a | Michael Hanselmann | @type args: list
|
580 | 19b9ba9a | Michael Hanselmann | @param args: should be an empty list
|
581 | 19b9ba9a | Michael Hanselmann | @rtype: int
|
582 | 19b9ba9a | Michael Hanselmann | @return: the desired exit code
|
583 | 19b9ba9a | Michael Hanselmann |
|
584 | 19b9ba9a | Michael Hanselmann | """
|
585 | 19b9ba9a | Michael Hanselmann | selected_fields = ParseFields(opts.output, _LIST_LOCKS_DEF_FIELDS) |
586 | 19b9ba9a | Michael Hanselmann | |
587 | 24d16f76 | Michael Hanselmann | def _DashIfNone(fn): |
588 | 24d16f76 | Michael Hanselmann | def wrapper(value): |
589 | 24d16f76 | Michael Hanselmann | if not value: |
590 | 24d16f76 | Michael Hanselmann | return "-" |
591 | 24d16f76 | Michael Hanselmann | return fn(value)
|
592 | 24d16f76 | Michael Hanselmann | return wrapper
|
593 | 24d16f76 | Michael Hanselmann | |
594 | 24d16f76 | Michael Hanselmann | def _FormatPending(value): |
595 | 24d16f76 | Michael Hanselmann | """Format pending acquires.
|
596 | 24d16f76 | Michael Hanselmann |
|
597 | 24d16f76 | Michael Hanselmann | """
|
598 | 24d16f76 | Michael Hanselmann | return utils.CommaJoin("%s:%s" % (mode, ",".join(threads)) |
599 | 24d16f76 | Michael Hanselmann | for mode, threads in value) |
600 | 24d16f76 | Michael Hanselmann | |
601 | 24d16f76 | Michael Hanselmann | # Format raw values
|
602 | 24d16f76 | Michael Hanselmann | fmtoverride = { |
603 | 24d16f76 | Michael Hanselmann | "mode": (_DashIfNone(str), False), |
604 | 24d16f76 | Michael Hanselmann | "owner": (_DashIfNone(",".join), False), |
605 | 24d16f76 | Michael Hanselmann | "pending": (_DashIfNone(_FormatPending), False), |
606 | 24d16f76 | Michael Hanselmann | } |
607 | 19b9ba9a | Michael Hanselmann | |
608 | 19b9ba9a | Michael Hanselmann | while True: |
609 | 24d16f76 | Michael Hanselmann | ret = GenericList(constants.QR_LOCK, selected_fields, None, None, |
610 | 24d16f76 | Michael Hanselmann | opts.separator, not opts.no_headers,
|
611 | f0b1bafe | Iustin Pop | format_override=fmtoverride, verbose=opts.verbose) |
612 | 24d16f76 | Michael Hanselmann | |
613 | 24d16f76 | Michael Hanselmann | if ret != constants.EXIT_SUCCESS:
|
614 | 24d16f76 | Michael Hanselmann | return ret
|
615 | 19b9ba9a | Michael Hanselmann | |
616 | 19b9ba9a | Michael Hanselmann | if not opts.interval: |
617 | 19b9ba9a | Michael Hanselmann | break
|
618 | 19b9ba9a | Michael Hanselmann | |
619 | 19b9ba9a | Michael Hanselmann | ToStdout("")
|
620 | 19b9ba9a | Michael Hanselmann | time.sleep(opts.interval) |
621 | 19b9ba9a | Michael Hanselmann | |
622 | 19b9ba9a | Michael Hanselmann | return 0 |
623 | 19b9ba9a | Michael Hanselmann | |
624 | 19b9ba9a | Michael Hanselmann | |
625 | fd3ee040 | Iustin Pop | commands = { |
626 | d0c8c01d | Iustin Pop | "delay": (
|
627 | 6ea815cf | Iustin Pop | Delay, [ArgUnknown(min=1, max=1)], |
628 | 064c21f8 | Iustin Pop | [cli_option("--no-master", dest="on_master", default=True, |
629 | 6ea815cf | Iustin Pop | action="store_false", help="Do not sleep in the master code"), |
630 | 6ea815cf | Iustin Pop | cli_option("-n", dest="on_nodes", default=[], |
631 | 6ea815cf | Iustin Pop | action="append", help="Select nodes to sleep on"), |
632 | 85a87e21 | Guido Trotter | cli_option("-r", "--repeat", type="int", default="0", dest="repeat", |
633 | 85a87e21 | Guido Trotter | help="Number of times to repeat the sleep"),
|
634 | bb600388 | Michael Hanselmann | DRY_RUN_OPT, PRIORITY_OPT, SUBMIT_OPT, |
635 | 6ea815cf | Iustin Pop | ], |
636 | 6ea815cf | Iustin Pop | "[opts...] <duration>", "Executes a TestDelay OpCode"), |
637 | d0c8c01d | Iustin Pop | "submit-job": (
|
638 | 6ea815cf | Iustin Pop | GenericOpCodes, [ArgFile(min=1)],
|
639 | 064c21f8 | Iustin Pop | [VERBOSE_OPT, |
640 | 6ea815cf | Iustin Pop | cli_option("--op-repeat", type="int", default="1", dest="rep_op", |
641 | 6ea815cf | Iustin Pop | help="Repeat the opcode sequence this number of times"),
|
642 | 6ea815cf | Iustin Pop | cli_option("--job-repeat", type="int", default="1", dest="rep_job", |
643 | 6ea815cf | Iustin Pop | help="Repeat the job this number of times"),
|
644 | 6ea815cf | Iustin Pop | cli_option("--timing-stats", default=False, |
645 | 6ea815cf | Iustin Pop | action="store_true", help="Show timing stats"), |
646 | 66ecc479 | Guido Trotter | cli_option("--each", default=False, action="store_true", |
647 | 66ecc479 | Guido Trotter | help="Submit each job separately"),
|
648 | aa06f8c6 | Michael Hanselmann | DRY_RUN_OPT, PRIORITY_OPT, |
649 | 6ea815cf | Iustin Pop | ], |
650 | 6ea815cf | Iustin Pop | "<op_list_file...>", "Submits jobs built from json files" |
651 | 6ea815cf | Iustin Pop | " containing a list of serialized opcodes"),
|
652 | d0c8c01d | Iustin Pop | "iallocator": (
|
653 | 823a72bc | Iustin Pop | TestAllocator, [ArgUnknown(min=1)],
|
654 | 9133387e | Michael Hanselmann | [cli_option("--dir", dest="direction", default=constants.IALLOCATOR_DIR_IN, |
655 | 9133387e | Michael Hanselmann | choices=list(constants.VALID_IALLOCATOR_DIRECTIONS),
|
656 | 6ea815cf | Iustin Pop | help="Show allocator input (in) or allocator"
|
657 | 6ea815cf | Iustin Pop | " results (out)"),
|
658 | 6ea815cf | Iustin Pop | IALLOCATOR_OPT, |
659 | 6ea815cf | Iustin Pop | cli_option("-m", "--mode", default="relocate", |
660 | 42c161cf | Michael Hanselmann | choices=list(constants.VALID_IALLOCATOR_MODES),
|
661 | 42c161cf | Michael Hanselmann | help=("Request mode (one of %s)" %
|
662 | 42c161cf | Michael Hanselmann | utils.CommaJoin(constants.VALID_IALLOCATOR_MODES))), |
663 | dd47a0f0 | Iustin Pop | cli_option("--memory", default=128, type="unit", |
664 | 6ea815cf | Iustin Pop | help="Memory size for the instance (MiB)"),
|
665 | 6ea815cf | Iustin Pop | cli_option("--disks", default="4096,4096", |
666 | 6ea815cf | Iustin Pop | help="Comma separated list of disk sizes (MiB)"),
|
667 | 6ea815cf | Iustin Pop | DISK_TEMPLATE_OPT, |
668 | 6ea815cf | Iustin Pop | cli_option("--nics", default="00:11:22:33:44:55", |
669 | 6ea815cf | Iustin Pop | help="Comma separated list of nics, each nic"
|
670 | 6ea815cf | Iustin Pop | " definition is of form mac/ip/bridge, if"
|
671 | 6ea815cf | Iustin Pop | " missing values are replace by None"),
|
672 | 6ea815cf | Iustin Pop | OS_OPT, |
673 | 6ea815cf | Iustin Pop | cli_option("-p", "--vcpus", default=1, type="int", |
674 | 6ea815cf | Iustin Pop | help="Select number of VCPUs for the instance"),
|
675 | 6ea815cf | Iustin Pop | cli_option("--tags", default=None, |
676 | 6ea815cf | Iustin Pop | help="Comma separated list of tags"),
|
677 | 60152bbe | Michael Hanselmann | cli_option("--evac-mode", default=constants.IALLOCATOR_NEVAC_ALL,
|
678 | 60152bbe | Michael Hanselmann | choices=list(constants.IALLOCATOR_NEVAC_MODES),
|
679 | 60152bbe | Michael Hanselmann | help=("Node evacuation mode (one of %s)" %
|
680 | 60152bbe | Michael Hanselmann | utils.CommaJoin(constants.IALLOCATOR_NEVAC_MODES))), |
681 | 60152bbe | Michael Hanselmann | cli_option("--target-groups", help="Target groups for relocation", |
682 | 60152bbe | Michael Hanselmann | default=[], action="append"),
|
683 | 09123222 | René Nussbaumer | cli_option("--spindle-use", help="How many spindles to use", |
684 | 09123222 | René Nussbaumer | default=1, type="int"), |
685 | 3c049cd3 | René Nussbaumer | cli_option("--count", help="How many instances to allocate", |
686 | 3c049cd3 | René Nussbaumer | default=2, type="int"), |
687 | aa06f8c6 | Michael Hanselmann | DRY_RUN_OPT, PRIORITY_OPT, |
688 | 6ea815cf | Iustin Pop | ], |
689 | 6ea815cf | Iustin Pop | "{opts...} <instance>", "Executes a TestAllocator OpCode"), |
690 | e58f87a9 | Michael Hanselmann | "test-jobqueue": (
|
691 | aa06f8c6 | Michael Hanselmann | TestJobqueue, ARGS_NONE, [PRIORITY_OPT], |
692 | 19b9ba9a | Michael Hanselmann | "", "Test a few aspects of the job queue"), |
693 | 19b9ba9a | Michael Hanselmann | "locks": (
|
694 | f0b1bafe | Iustin Pop | ListLocks, ARGS_NONE, |
695 | f0b1bafe | Iustin Pop | [NOHDR_OPT, SEP_OPT, FIELDS_OPT, INTERVAL_OPT, VERBOSE_OPT], |
696 | 19b9ba9a | Michael Hanselmann | "[--interval N]", "Show a list of locks in the master daemon"), |
697 | fd3ee040 | Iustin Pop | } |
698 | fd3ee040 | Iustin Pop | |
699 | 3f1e065d | Iustin Pop | #: dictionary with aliases for commands
|
700 | 3f1e065d | Iustin Pop | aliases = { |
701 | 3f1e065d | Iustin Pop | "allocator": "iallocator", |
702 | 3f1e065d | Iustin Pop | } |
703 | fd3ee040 | Iustin Pop | |
704 | e687ec01 | Michael Hanselmann | |
705 | c2855a12 | Michael Hanselmann | def Main(): |
706 | 3f1e065d | Iustin Pop | return GenericMain(commands, aliases=aliases) |