root / scripts / gnt-debug @ db5a8a2d
History | View | Annotate | Download (15.3 kB)
1 | fd3ee040 | Iustin Pop | #!/usr/bin/python |
---|---|---|---|
2 | fd3ee040 | Iustin Pop | # |
3 | fd3ee040 | Iustin Pop | |
4 | db5a8a2d | Iustin Pop | # Copyright (C) 2006, 2007, 2010 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 | 7260cfbe | Iustin Pop | # pylint: disable-msg=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 | fd3ee040 | Iustin Pop | import sys |
29 | f1c66d13 | Iustin Pop | import simplejson |
30 | f1c66d13 | Iustin Pop | import time |
31 | e58f87a9 | Michael Hanselmann | import socket |
32 | e58f87a9 | Michael Hanselmann | import logging |
33 | f1c66d13 | Iustin Pop | |
34 | fd3ee040 | Iustin Pop | from ganeti.cli import * |
35 | 9d5ba39a | Iustin Pop | from ganeti import cli |
36 | e58f87a9 | Michael Hanselmann | from ganeti import constants |
37 | fd3ee040 | Iustin Pop | from ganeti import opcodes |
38 | fd3ee040 | Iustin Pop | from ganeti import utils |
39 | fd3ee040 | Iustin Pop | from ganeti import errors |
40 | fd3ee040 | Iustin Pop | |
41 | fd3ee040 | Iustin Pop | |
42 | fd3ee040 | Iustin Pop | def Delay(opts, args): |
43 | fd3ee040 | Iustin Pop | """Sleeps for a while |
44 | fd3ee040 | Iustin Pop | |
45 | 6099bfcf | Iustin Pop | @param opts: the command line options selected by the user |
46 | 6099bfcf | Iustin Pop | @type args: list |
47 | 6099bfcf | Iustin Pop | @param args: should contain only one element, the duration |
48 | 6099bfcf | Iustin Pop | the sleep |
49 | 6099bfcf | Iustin Pop | @rtype: int |
50 | 6099bfcf | Iustin Pop | @return: the desired exit code |
51 | 6099bfcf | Iustin Pop | |
52 | fd3ee040 | Iustin Pop | """ |
53 | fd3ee040 | Iustin Pop | delay = float(args[0]) |
54 | fd3ee040 | Iustin Pop | op = opcodes.OpTestDelay(duration=delay, |
55 | fd3ee040 | Iustin Pop | on_master=opts.on_master, |
56 | 85a87e21 | Guido Trotter | on_nodes=opts.on_nodes, |
57 | 85a87e21 | Guido Trotter | repeat=opts.repeat) |
58 | 400ca2f7 | Iustin Pop | SubmitOpCode(op, opts=opts) |
59 | fd3ee040 | Iustin Pop | |
60 | fd3ee040 | Iustin Pop | return 0 |
61 | fd3ee040 | Iustin Pop | |
62 | fd3ee040 | Iustin Pop | |
63 | f1c66d13 | Iustin Pop | def GenericOpCodes(opts, args): |
64 | 6099bfcf | Iustin Pop | """Send any opcode to the master. |
65 | 6099bfcf | Iustin Pop | |
66 | 6099bfcf | Iustin Pop | @param opts: the command line options selected by the user |
67 | 6099bfcf | Iustin Pop | @type args: list |
68 | 6099bfcf | Iustin Pop | @param args: should contain only one element, the path of |
69 | 6099bfcf | Iustin Pop | the file with the opcode definition |
70 | 6099bfcf | Iustin Pop | @rtype: int |
71 | 6099bfcf | Iustin Pop | @return: the desired exit code |
72 | f1c66d13 | Iustin Pop | |
73 | f1c66d13 | Iustin Pop | """ |
74 | 9d5ba39a | Iustin Pop | cl = cli.GetClient() |
75 | cb573a31 | Iustin Pop | jex = cli.JobExecutor(cl=cl, verbose=opts.verbose, opts=opts) |
76 | 9d95c3af | Iustin Pop | |
77 | 9d95c3af | Iustin Pop | job_cnt = 0 |
78 | 9d95c3af | Iustin Pop | op_cnt = 0 |
79 | 9d95c3af | Iustin Pop | if opts.timing_stats: |
80 | 9d95c3af | Iustin Pop | ToStdout("Loading...") |
81 | 9d95c3af | Iustin Pop | for job_idx in range(opts.rep_job): |
82 | 9d95c3af | Iustin Pop | for fname in args: |
83 | 7260cfbe | Iustin Pop | # pylint: disable-msg=W0142 |
84 | 4d5fe81b | Michael Hanselmann | op_data = simplejson.loads(utils.ReadFile(fname)) |
85 | 9d95c3af | Iustin Pop | op_list = [opcodes.OpCode.LoadOpCode(val) for val in op_data] |
86 | 9d95c3af | Iustin Pop | op_list = op_list * opts.rep_op |
87 | 9d95c3af | Iustin Pop | jex.QueueJob("file %s/%d" % (fname, job_idx), *op_list) |
88 | 9d95c3af | Iustin Pop | op_cnt += len(op_list) |
89 | 9d95c3af | Iustin Pop | job_cnt += 1 |
90 | 9d95c3af | Iustin Pop | |
91 | 9d95c3af | Iustin Pop | if opts.timing_stats: |
92 | 9d95c3af | Iustin Pop | t1 = time.time() |
93 | 9d95c3af | Iustin Pop | ToStdout("Submitting...") |
94 | 4d5fe81b | Michael Hanselmann | |
95 | 66ecc479 | Guido Trotter | jex.SubmitPending(each=opts.each) |
96 | 9d95c3af | Iustin Pop | |
97 | 9d95c3af | Iustin Pop | if opts.timing_stats: |
98 | 9d95c3af | Iustin Pop | t2 = time.time() |
99 | 9d95c3af | Iustin Pop | ToStdout("Executing...") |
100 | b59252fe | Iustin Pop | |
101 | b59252fe | Iustin Pop | jex.GetResults() |
102 | 9d95c3af | Iustin Pop | if opts.timing_stats: |
103 | 9d95c3af | Iustin Pop | t3 = time.time() |
104 | 9d95c3af | Iustin Pop | ToStdout("C:op %4d" % op_cnt) |
105 | 9d95c3af | Iustin Pop | ToStdout("C:job %4d" % job_cnt) |
106 | 9d95c3af | Iustin Pop | ToStdout("T:submit %4.4f" % (t2-t1)) |
107 | 9d95c3af | Iustin Pop | ToStdout("T:exec %4.4f" % (t3-t2)) |
108 | 9d95c3af | Iustin Pop | ToStdout("T:total %4.4f" % (t3-t1)) |
109 | f1c66d13 | Iustin Pop | return 0 |
110 | f1c66d13 | Iustin Pop | |
111 | f1c66d13 | Iustin Pop | |
112 | d61df03e | Iustin Pop | def TestAllocator(opts, args): |
113 | 6099bfcf | Iustin Pop | """Runs the test allocator opcode. |
114 | d61df03e | Iustin Pop | |
115 | 6099bfcf | Iustin Pop | @param opts: the command line options selected by the user |
116 | 6099bfcf | Iustin Pop | @type args: list |
117 | 6099bfcf | Iustin Pop | @param args: should contain only one element, the iallocator name |
118 | 6099bfcf | Iustin Pop | @rtype: int |
119 | 6099bfcf | Iustin Pop | @return: the desired exit code |
120 | 6099bfcf | Iustin Pop | |
121 | 6099bfcf | Iustin Pop | """ |
122 | d61df03e | Iustin Pop | try: |
123 | d61df03e | Iustin Pop | disks = [{"size": utils.ParseUnit(val), "mode": 'w'} |
124 | d61df03e | Iustin Pop | for val in opts.disks.split(",")] |
125 | d61df03e | Iustin Pop | except errors.UnitParseError, err: |
126 | 3a24c527 | Iustin Pop | ToStderr("Invalid disks parameter '%s': %s", opts.disks, err) |
127 | d61df03e | Iustin Pop | return 1 |
128 | d61df03e | Iustin Pop | |
129 | d61df03e | Iustin Pop | nics = [val.split("/") for val in opts.nics.split(",")] |
130 | d61df03e | Iustin Pop | for row in nics: |
131 | d61df03e | Iustin Pop | while len(row) < 3: |
132 | d61df03e | Iustin Pop | row.append(None) |
133 | d61df03e | Iustin Pop | for i in range(3): |
134 | d61df03e | Iustin Pop | if row[i] == '': |
135 | d61df03e | Iustin Pop | row[i] = None |
136 | d61df03e | Iustin Pop | nic_dict = [{"mac": v[0], "ip": v[1], "bridge": v[2]} for v in nics] |
137 | d61df03e | Iustin Pop | |
138 | d61df03e | Iustin Pop | if opts.tags is None: |
139 | d61df03e | Iustin Pop | opts.tags = [] |
140 | d61df03e | Iustin Pop | else: |
141 | d61df03e | Iustin Pop | opts.tags = opts.tags.split(",") |
142 | d61df03e | Iustin Pop | |
143 | d61df03e | Iustin Pop | op = opcodes.OpTestAllocator(mode=opts.mode, |
144 | d61df03e | Iustin Pop | name=args[0], |
145 | 823a72bc | Iustin Pop | evac_nodes=args, |
146 | d61df03e | Iustin Pop | mem_size=opts.mem, |
147 | d61df03e | Iustin Pop | disks=disks, |
148 | d61df03e | Iustin Pop | disk_template=opts.disk_template, |
149 | d61df03e | Iustin Pop | nics=nic_dict, |
150 | 705dd60e | Iustin Pop | os=opts.os, |
151 | d61df03e | Iustin Pop | vcpus=opts.vcpus, |
152 | d61df03e | Iustin Pop | tags=opts.tags, |
153 | d61df03e | Iustin Pop | direction=opts.direction, |
154 | 705dd60e | Iustin Pop | allocator=opts.iallocator, |
155 | d61df03e | Iustin Pop | ) |
156 | 400ca2f7 | Iustin Pop | result = SubmitOpCode(op, opts=opts) |
157 | 3a24c527 | Iustin Pop | ToStdout("%s" % result) |
158 | d61df03e | Iustin Pop | return 0 |
159 | d61df03e | Iustin Pop | |
160 | d61df03e | Iustin Pop | |
161 | e58f87a9 | Michael Hanselmann | class _JobQueueTestReporter(cli.StdioJobPollReportCb): |
162 | e58f87a9 | Michael Hanselmann | def __init__(self): |
163 | e58f87a9 | Michael Hanselmann | """Initializes this class. |
164 | e58f87a9 | Michael Hanselmann | |
165 | e58f87a9 | Michael Hanselmann | """ |
166 | e58f87a9 | Michael Hanselmann | cli.StdioJobPollReportCb.__init__(self) |
167 | f99010b2 | Michael Hanselmann | self._expected_msgcount = 0 |
168 | f99010b2 | Michael Hanselmann | self._all_testmsgs = [] |
169 | f99010b2 | Michael Hanselmann | self._testmsgs = None |
170 | e58f87a9 | Michael Hanselmann | self._job_id = None |
171 | e58f87a9 | Michael Hanselmann | |
172 | e58f87a9 | Michael Hanselmann | def GetTestMessages(self): |
173 | e58f87a9 | Michael Hanselmann | """Returns all test log messages received so far. |
174 | e58f87a9 | Michael Hanselmann | |
175 | e58f87a9 | Michael Hanselmann | """ |
176 | f99010b2 | Michael Hanselmann | return self._all_testmsgs |
177 | e58f87a9 | Michael Hanselmann | |
178 | e58f87a9 | Michael Hanselmann | def GetJobId(self): |
179 | e58f87a9 | Michael Hanselmann | """Returns the job ID. |
180 | e58f87a9 | Michael Hanselmann | |
181 | e58f87a9 | Michael Hanselmann | """ |
182 | e58f87a9 | Michael Hanselmann | return self._job_id |
183 | e58f87a9 | Michael Hanselmann | |
184 | e58f87a9 | Michael Hanselmann | def ReportLogMessage(self, job_id, serial, timestamp, log_type, log_msg): |
185 | e58f87a9 | Michael Hanselmann | """Handles a log message. |
186 | e58f87a9 | Michael Hanselmann | |
187 | e58f87a9 | Michael Hanselmann | """ |
188 | e58f87a9 | Michael Hanselmann | if self._job_id is None: |
189 | e58f87a9 | Michael Hanselmann | self._job_id = job_id |
190 | e58f87a9 | Michael Hanselmann | elif self._job_id != job_id: |
191 | e58f87a9 | Michael Hanselmann | raise errors.ProgrammerError("The same reporter instance was used for" |
192 | e58f87a9 | Michael Hanselmann | " more than one job") |
193 | e58f87a9 | Michael Hanselmann | |
194 | e58f87a9 | Michael Hanselmann | if log_type == constants.ELOG_JQUEUE_TEST: |
195 | e58f87a9 | Michael Hanselmann | (sockname, test, arg) = log_msg |
196 | e58f87a9 | Michael Hanselmann | return self._ProcessTestMessage(job_id, sockname, test, arg) |
197 | e58f87a9 | Michael Hanselmann | |
198 | e58f87a9 | Michael Hanselmann | elif (log_type == constants.ELOG_MESSAGE and |
199 | e58f87a9 | Michael Hanselmann | log_msg.startswith(constants.JQT_MSGPREFIX)): |
200 | f99010b2 | Michael Hanselmann | if self._testmsgs is None: |
201 | f99010b2 | Michael Hanselmann | raise errors.OpExecError("Received test message without a preceding" |
202 | f99010b2 | Michael Hanselmann | " start message") |
203 | f99010b2 | Michael Hanselmann | testmsg = log_msg[len(constants.JQT_MSGPREFIX):] |
204 | f99010b2 | Michael Hanselmann | self._testmsgs.append(testmsg) |
205 | f99010b2 | Michael Hanselmann | self._all_testmsgs.append(testmsg) |
206 | e58f87a9 | Michael Hanselmann | return |
207 | e58f87a9 | Michael Hanselmann | |
208 | e58f87a9 | Michael Hanselmann | return cli.StdioJobPollReportCb.ReportLogMessage(self, job_id, serial, |
209 | e58f87a9 | Michael Hanselmann | timestamp, log_type, |
210 | e58f87a9 | Michael Hanselmann | log_msg) |
211 | e58f87a9 | Michael Hanselmann | |
212 | e58f87a9 | Michael Hanselmann | def _ProcessTestMessage(self, job_id, sockname, test, arg): |
213 | e58f87a9 | Michael Hanselmann | """Handles a job queue test message. |
214 | e58f87a9 | Michael Hanselmann | |
215 | e58f87a9 | Michael Hanselmann | """ |
216 | e58f87a9 | Michael Hanselmann | if test not in constants.JQT_ALL: |
217 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Received invalid test message %s" % test) |
218 | e58f87a9 | Michael Hanselmann | |
219 | e58f87a9 | Michael Hanselmann | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
220 | e58f87a9 | Michael Hanselmann | try: |
221 | e58f87a9 | Michael Hanselmann | sock.settimeout(30.0) |
222 | e58f87a9 | Michael Hanselmann | |
223 | e58f87a9 | Michael Hanselmann | logging.debug("Connecting to %s", sockname) |
224 | e58f87a9 | Michael Hanselmann | sock.connect(sockname) |
225 | e58f87a9 | Michael Hanselmann | |
226 | e58f87a9 | Michael Hanselmann | logging.debug("Checking status") |
227 | e58f87a9 | Michael Hanselmann | jobdetails = cli.GetClient().QueryJobs([job_id], ["status"])[0] |
228 | e58f87a9 | Michael Hanselmann | if not jobdetails: |
229 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Can't find job %s" % job_id) |
230 | e58f87a9 | Michael Hanselmann | |
231 | e58f87a9 | Michael Hanselmann | status = jobdetails[0] |
232 | e58f87a9 | Michael Hanselmann | |
233 | e58f87a9 | Michael Hanselmann | logging.debug("Status of job %s is %s", job_id, status) |
234 | e58f87a9 | Michael Hanselmann | |
235 | e58f87a9 | Michael Hanselmann | if test == constants.JQT_EXPANDNAMES: |
236 | e58f87a9 | Michael Hanselmann | if status != constants.JOB_STATUS_WAITLOCK: |
237 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Job status while expanding names is '%s'," |
238 | e58f87a9 | Michael Hanselmann | " not '%s' as expected" % |
239 | e58f87a9 | Michael Hanselmann | (status, constants.JOB_STATUS_WAITLOCK)) |
240 | e58f87a9 | Michael Hanselmann | elif test in (constants.JQT_EXEC, constants.JQT_LOGMSG): |
241 | e58f87a9 | Michael Hanselmann | if status != constants.JOB_STATUS_RUNNING: |
242 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Job status while executing opcode is '%s'," |
243 | e58f87a9 | Michael Hanselmann | " not '%s' as expected" % |
244 | e58f87a9 | Michael Hanselmann | (status, constants.JOB_STATUS_RUNNING)) |
245 | e58f87a9 | Michael Hanselmann | |
246 | f99010b2 | Michael Hanselmann | if test == constants.JQT_STARTMSG: |
247 | f99010b2 | Michael Hanselmann | logging.debug("Expecting %s test messages", arg) |
248 | f99010b2 | Michael Hanselmann | self._testmsgs = [] |
249 | f99010b2 | Michael Hanselmann | elif test == constants.JQT_LOGMSG: |
250 | e58f87a9 | Michael Hanselmann | if len(self._testmsgs) != arg: |
251 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Received %s test messages when %s are" |
252 | e58f87a9 | Michael Hanselmann | " expected" % (len(self._testmsgs), arg)) |
253 | e58f87a9 | Michael Hanselmann | finally: |
254 | e58f87a9 | Michael Hanselmann | logging.debug("Closing socket") |
255 | e58f87a9 | Michael Hanselmann | sock.close() |
256 | e58f87a9 | Michael Hanselmann | |
257 | e58f87a9 | Michael Hanselmann | |
258 | e58f87a9 | Michael Hanselmann | def TestJobqueue(opts, _): |
259 | e58f87a9 | Michael Hanselmann | """Runs a few tests on the job queue. |
260 | e58f87a9 | Michael Hanselmann | |
261 | e58f87a9 | Michael Hanselmann | """ |
262 | f99010b2 | Michael Hanselmann | (TM_SUCCESS, |
263 | f99010b2 | Michael Hanselmann | TM_MULTISUCCESS, |
264 | f99010b2 | Michael Hanselmann | TM_FAIL, |
265 | f99010b2 | Michael Hanselmann | TM_PARTFAIL) = range(4) |
266 | f99010b2 | Michael Hanselmann | TM_ALL = frozenset([TM_SUCCESS, TM_MULTISUCCESS, TM_FAIL, TM_PARTFAIL]) |
267 | f99010b2 | Michael Hanselmann | |
268 | f99010b2 | Michael Hanselmann | for mode in TM_ALL: |
269 | f99010b2 | Michael Hanselmann | test_messages = [ |
270 | f99010b2 | Michael Hanselmann | "Testing mode %s" % mode, |
271 | f99010b2 | Michael Hanselmann | "Hello World", |
272 | f99010b2 | Michael Hanselmann | "A", |
273 | f99010b2 | Michael Hanselmann | "", |
274 | f99010b2 | Michael Hanselmann | "B" |
275 | f99010b2 | Michael Hanselmann | "Foo|bar|baz", |
276 | f99010b2 | Michael Hanselmann | utils.TimestampForFilename(), |
277 | f99010b2 | Michael Hanselmann | ] |
278 | f99010b2 | Michael Hanselmann | |
279 | f99010b2 | Michael Hanselmann | fail = mode in (TM_FAIL, TM_PARTFAIL) |
280 | f99010b2 | Michael Hanselmann | |
281 | f99010b2 | Michael Hanselmann | if mode == TM_PARTFAIL: |
282 | f99010b2 | Michael Hanselmann | ToStdout("Testing partial job failure") |
283 | f99010b2 | Michael Hanselmann | ops = [ |
284 | f99010b2 | Michael Hanselmann | opcodes.OpTestJobqueue(notify_waitlock=True, notify_exec=True, |
285 | f99010b2 | Michael Hanselmann | log_messages=test_messages, fail=False), |
286 | f99010b2 | Michael Hanselmann | opcodes.OpTestJobqueue(notify_waitlock=True, notify_exec=True, |
287 | f99010b2 | Michael Hanselmann | log_messages=test_messages, fail=False), |
288 | f99010b2 | Michael Hanselmann | opcodes.OpTestJobqueue(notify_waitlock=True, notify_exec=True, |
289 | f99010b2 | Michael Hanselmann | log_messages=test_messages, fail=True), |
290 | f99010b2 | Michael Hanselmann | opcodes.OpTestJobqueue(notify_waitlock=True, notify_exec=True, |
291 | f99010b2 | Michael Hanselmann | log_messages=test_messages, fail=False), |
292 | f99010b2 | Michael Hanselmann | ] |
293 | f99010b2 | Michael Hanselmann | expect_messages = 3 * [test_messages] |
294 | f99010b2 | Michael Hanselmann | expect_opstatus = [ |
295 | f99010b2 | Michael Hanselmann | constants.OP_STATUS_SUCCESS, |
296 | f99010b2 | Michael Hanselmann | constants.OP_STATUS_SUCCESS, |
297 | f99010b2 | Michael Hanselmann | constants.OP_STATUS_ERROR, |
298 | f99010b2 | Michael Hanselmann | constants.OP_STATUS_ERROR, |
299 | f99010b2 | Michael Hanselmann | ] |
300 | f99010b2 | Michael Hanselmann | expect_resultlen = 2 |
301 | f99010b2 | Michael Hanselmann | elif mode == TM_MULTISUCCESS: |
302 | f99010b2 | Michael Hanselmann | ToStdout("Testing multiple successful opcodes") |
303 | f99010b2 | Michael Hanselmann | ops = [ |
304 | f99010b2 | Michael Hanselmann | opcodes.OpTestJobqueue(notify_waitlock=True, notify_exec=True, |
305 | f99010b2 | Michael Hanselmann | log_messages=test_messages, fail=False), |
306 | f99010b2 | Michael Hanselmann | opcodes.OpTestJobqueue(notify_waitlock=True, notify_exec=True, |
307 | f99010b2 | Michael Hanselmann | log_messages=test_messages, fail=False), |
308 | f99010b2 | Michael Hanselmann | ] |
309 | f99010b2 | Michael Hanselmann | expect_messages = 2 * [test_messages] |
310 | f99010b2 | Michael Hanselmann | expect_opstatus = [ |
311 | f99010b2 | Michael Hanselmann | constants.OP_STATUS_SUCCESS, |
312 | f99010b2 | Michael Hanselmann | constants.OP_STATUS_SUCCESS, |
313 | f99010b2 | Michael Hanselmann | ] |
314 | f99010b2 | Michael Hanselmann | expect_resultlen = 2 |
315 | e58f87a9 | Michael Hanselmann | else: |
316 | f99010b2 | Michael Hanselmann | if mode == TM_SUCCESS: |
317 | f99010b2 | Michael Hanselmann | ToStdout("Testing job success") |
318 | f99010b2 | Michael Hanselmann | expect_opstatus = [constants.OP_STATUS_SUCCESS] |
319 | f99010b2 | Michael Hanselmann | elif mode == TM_FAIL: |
320 | f99010b2 | Michael Hanselmann | ToStdout("Testing job failure") |
321 | f99010b2 | Michael Hanselmann | expect_opstatus = [constants.OP_STATUS_ERROR] |
322 | f99010b2 | Michael Hanselmann | else: |
323 | f99010b2 | Michael Hanselmann | raise errors.ProgrammerError("Unknown test mode %s" % mode) |
324 | f99010b2 | Michael Hanselmann | |
325 | f99010b2 | Michael Hanselmann | ops = [ |
326 | f99010b2 | Michael Hanselmann | opcodes.OpTestJobqueue(notify_waitlock=True, |
327 | f99010b2 | Michael Hanselmann | notify_exec=True, |
328 | f99010b2 | Michael Hanselmann | log_messages=test_messages, |
329 | f99010b2 | Michael Hanselmann | fail=fail) |
330 | f99010b2 | Michael Hanselmann | ] |
331 | f99010b2 | Michael Hanselmann | expect_messages = [test_messages] |
332 | f99010b2 | Michael Hanselmann | expect_resultlen = 1 |
333 | f99010b2 | Michael Hanselmann | |
334 | f99010b2 | Michael Hanselmann | cl = cli.GetClient() |
335 | f99010b2 | Michael Hanselmann | cli.SetGenericOpcodeOpts(ops, opts) |
336 | f99010b2 | Michael Hanselmann | |
337 | f99010b2 | Michael Hanselmann | # Send job to master daemon |
338 | f99010b2 | Michael Hanselmann | job_id = cli.SendJob(ops, cl=cl) |
339 | e58f87a9 | Michael Hanselmann | |
340 | e58f87a9 | Michael Hanselmann | reporter = _JobQueueTestReporter() |
341 | f99010b2 | Michael Hanselmann | results = None |
342 | f99010b2 | Michael Hanselmann | |
343 | e58f87a9 | Michael Hanselmann | try: |
344 | f99010b2 | Michael Hanselmann | results = cli.PollJob(job_id, cl=cl, reporter=reporter) |
345 | f99010b2 | Michael Hanselmann | except errors.OpExecError, err: |
346 | e58f87a9 | Michael Hanselmann | if not fail: |
347 | e58f87a9 | Michael Hanselmann | raise |
348 | f99010b2 | Michael Hanselmann | ToStdout("Ignoring error: %s", err) |
349 | e58f87a9 | Michael Hanselmann | else: |
350 | e58f87a9 | Michael Hanselmann | if fail: |
351 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Job didn't fail when it should") |
352 | e58f87a9 | Michael Hanselmann | |
353 | f99010b2 | Michael Hanselmann | # Check length of result |
354 | f99010b2 | Michael Hanselmann | if fail: |
355 | f99010b2 | Michael Hanselmann | if results is not None: |
356 | f99010b2 | Michael Hanselmann | raise errors.OpExecError("Received result from failed job") |
357 | f99010b2 | Michael Hanselmann | elif len(results) != expect_resultlen: |
358 | f99010b2 | Michael Hanselmann | raise errors.OpExecError("Received %s results (%s), expected %s" % |
359 | f99010b2 | Michael Hanselmann | (len(results), results, expect_resultlen)) |
360 | f99010b2 | Michael Hanselmann | |
361 | e58f87a9 | Michael Hanselmann | # Check received log messages |
362 | f99010b2 | Michael Hanselmann | all_messages = [i for j in expect_messages for i in j] |
363 | f99010b2 | Michael Hanselmann | if reporter.GetTestMessages() != all_messages: |
364 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Received test messages don't match input" |
365 | e58f87a9 | Michael Hanselmann | " (input %r, received %r)" % |
366 | f99010b2 | Michael Hanselmann | (all_messages, reporter.GetTestMessages())) |
367 | e58f87a9 | Michael Hanselmann | |
368 | e58f87a9 | Michael Hanselmann | # Check final status |
369 | f99010b2 | Michael Hanselmann | reported_job_id = reporter.GetJobId() |
370 | f99010b2 | Michael Hanselmann | if reported_job_id != job_id: |
371 | f99010b2 | Michael Hanselmann | raise errors.OpExecError("Reported job ID %s doesn't match" |
372 | f99010b2 | Michael Hanselmann | "submission job ID %s" % |
373 | f99010b2 | Michael Hanselmann | (reported_job_id, job_id)) |
374 | e58f87a9 | Michael Hanselmann | |
375 | f99010b2 | Michael Hanselmann | jobdetails = cli.GetClient().QueryJobs([job_id], ["status", "opstatus"])[0] |
376 | e58f87a9 | Michael Hanselmann | if not jobdetails: |
377 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Can't find job %s" % job_id) |
378 | e58f87a9 | Michael Hanselmann | |
379 | e58f87a9 | Michael Hanselmann | if fail: |
380 | e58f87a9 | Michael Hanselmann | exp_status = constants.JOB_STATUS_ERROR |
381 | e58f87a9 | Michael Hanselmann | else: |
382 | e58f87a9 | Michael Hanselmann | exp_status = constants.JOB_STATUS_SUCCESS |
383 | e58f87a9 | Michael Hanselmann | |
384 | f99010b2 | Michael Hanselmann | (final_status, final_opstatus) = jobdetails |
385 | e58f87a9 | Michael Hanselmann | if final_status != exp_status: |
386 | e58f87a9 | Michael Hanselmann | raise errors.OpExecError("Final job status is %s, not %s as expected" % |
387 | e58f87a9 | Michael Hanselmann | (final_status, exp_status)) |
388 | f99010b2 | Michael Hanselmann | if len(final_opstatus) != len(ops): |
389 | f99010b2 | Michael Hanselmann | raise errors.OpExecError("Did not receive status for all opcodes (got %s," |
390 | f99010b2 | Michael Hanselmann | " expected %s)" % |
391 | f99010b2 | Michael Hanselmann | (len(final_opstatus), len(ops))) |
392 | f99010b2 | Michael Hanselmann | if final_opstatus != expect_opstatus: |
393 | f99010b2 | Michael Hanselmann | raise errors.OpExecError("Opcode status is %s, expected %s" % |
394 | f99010b2 | Michael Hanselmann | (final_opstatus, expect_opstatus)) |
395 | f99010b2 | Michael Hanselmann | |
396 | f99010b2 | Michael Hanselmann | ToStdout("Job queue test successful") |
397 | e58f87a9 | Michael Hanselmann | |
398 | e58f87a9 | Michael Hanselmann | return 0 |
399 | e58f87a9 | Michael Hanselmann | |
400 | e58f87a9 | Michael Hanselmann | |
401 | fd3ee040 | Iustin Pop | commands = { |
402 | 6ea815cf | Iustin Pop | 'delay': ( |
403 | 6ea815cf | Iustin Pop | Delay, [ArgUnknown(min=1, max=1)], |
404 | 064c21f8 | Iustin Pop | [cli_option("--no-master", dest="on_master", default=True, |
405 | 6ea815cf | Iustin Pop | action="store_false", help="Do not sleep in the master code"), |
406 | 6ea815cf | Iustin Pop | cli_option("-n", dest="on_nodes", default=[], |
407 | 6ea815cf | Iustin Pop | action="append", help="Select nodes to sleep on"), |
408 | 85a87e21 | Guido Trotter | cli_option("-r", "--repeat", type="int", default="0", dest="repeat", |
409 | 85a87e21 | Guido Trotter | help="Number of times to repeat the sleep"), |
410 | db5a8a2d | Iustin Pop | DRY_RUN_OPT, |
411 | 6ea815cf | Iustin Pop | ], |
412 | 6ea815cf | Iustin Pop | "[opts...] <duration>", "Executes a TestDelay OpCode"), |
413 | 6ea815cf | Iustin Pop | 'submit-job': ( |
414 | 6ea815cf | Iustin Pop | GenericOpCodes, [ArgFile(min=1)], |
415 | 064c21f8 | Iustin Pop | [VERBOSE_OPT, |
416 | 6ea815cf | Iustin Pop | cli_option("--op-repeat", type="int", default="1", dest="rep_op", |
417 | 6ea815cf | Iustin Pop | help="Repeat the opcode sequence this number of times"), |
418 | 6ea815cf | Iustin Pop | cli_option("--job-repeat", type="int", default="1", dest="rep_job", |
419 | 6ea815cf | Iustin Pop | help="Repeat the job this number of times"), |
420 | 6ea815cf | Iustin Pop | cli_option("--timing-stats", default=False, |
421 | 6ea815cf | Iustin Pop | action="store_true", help="Show timing stats"), |
422 | 66ecc479 | Guido Trotter | cli_option("--each", default=False, action="store_true", |
423 | 66ecc479 | Guido Trotter | help="Submit each job separately"), |
424 | db5a8a2d | Iustin Pop | DRY_RUN_OPT, |
425 | 6ea815cf | Iustin Pop | ], |
426 | 6ea815cf | Iustin Pop | "<op_list_file...>", "Submits jobs built from json files" |
427 | 6ea815cf | Iustin Pop | " containing a list of serialized opcodes"), |
428 | 6ea815cf | Iustin Pop | 'allocator': ( |
429 | 823a72bc | Iustin Pop | TestAllocator, [ArgUnknown(min=1)], |
430 | 064c21f8 | Iustin Pop | [cli_option("--dir", dest="direction", |
431 | 6ea815cf | Iustin Pop | default="in", choices=["in", "out"], |
432 | 6ea815cf | Iustin Pop | help="Show allocator input (in) or allocator" |
433 | 6ea815cf | Iustin Pop | " results (out)"), |
434 | 6ea815cf | Iustin Pop | IALLOCATOR_OPT, |
435 | 6ea815cf | Iustin Pop | cli_option("-m", "--mode", default="relocate", |
436 | 823a72bc | Iustin Pop | choices=["relocate", "allocate", "multi-evacuate"], |
437 | 6ea815cf | Iustin Pop | help="Request mode, either allocate or relocate"), |
438 | 6ea815cf | Iustin Pop | cli_option("--mem", default=128, type="unit", |
439 | 6ea815cf | Iustin Pop | help="Memory size for the instance (MiB)"), |
440 | 6ea815cf | Iustin Pop | cli_option("--disks", default="4096,4096", |
441 | 6ea815cf | Iustin Pop | help="Comma separated list of disk sizes (MiB)"), |
442 | 6ea815cf | Iustin Pop | DISK_TEMPLATE_OPT, |
443 | 6ea815cf | Iustin Pop | cli_option("--nics", default="00:11:22:33:44:55", |
444 | 6ea815cf | Iustin Pop | help="Comma separated list of nics, each nic" |
445 | 6ea815cf | Iustin Pop | " definition is of form mac/ip/bridge, if" |
446 | 6ea815cf | Iustin Pop | " missing values are replace by None"), |
447 | 6ea815cf | Iustin Pop | OS_OPT, |
448 | 6ea815cf | Iustin Pop | cli_option("-p", "--vcpus", default=1, type="int", |
449 | 6ea815cf | Iustin Pop | help="Select number of VCPUs for the instance"), |
450 | 6ea815cf | Iustin Pop | cli_option("--tags", default=None, |
451 | 6ea815cf | Iustin Pop | help="Comma separated list of tags"), |
452 | db5a8a2d | Iustin Pop | DRY_RUN_OPT, |
453 | 6ea815cf | Iustin Pop | ], |
454 | 6ea815cf | Iustin Pop | "{opts...} <instance>", "Executes a TestAllocator OpCode"), |
455 | e58f87a9 | Michael Hanselmann | "test-jobqueue": ( |
456 | e58f87a9 | Michael Hanselmann | TestJobqueue, ARGS_NONE, [], |
457 | e58f87a9 | Michael Hanselmann | "", "Test a few aspects of the job queue") |
458 | fd3ee040 | Iustin Pop | } |
459 | fd3ee040 | Iustin Pop | |
460 | fd3ee040 | Iustin Pop | |
461 | fd3ee040 | Iustin Pop | if __name__ == '__main__': |
462 | fd3ee040 | Iustin Pop | sys.exit(GenericMain(commands)) |