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