Revision f99010b2 scripts/gnt-debug
b/scripts/gnt-debug | ||
---|---|---|
164 | 164 |
|
165 | 165 |
""" |
166 | 166 |
cli.StdioJobPollReportCb.__init__(self) |
167 |
self._testmsgs = [] |
|
167 |
self._expected_msgcount = 0 |
|
168 |
self._all_testmsgs = [] |
|
169 |
self._testmsgs = None |
|
168 | 170 |
self._job_id = None |
169 | 171 |
|
170 | 172 |
def GetTestMessages(self): |
171 | 173 |
"""Returns all test log messages received so far. |
172 | 174 |
|
173 | 175 |
""" |
174 |
return self._testmsgs |
|
176 |
return self._all_testmsgs
|
|
175 | 177 |
|
176 | 178 |
def GetJobId(self): |
177 | 179 |
"""Returns the job ID. |
... | ... | |
195 | 197 |
|
196 | 198 |
elif (log_type == constants.ELOG_MESSAGE and |
197 | 199 |
log_msg.startswith(constants.JQT_MSGPREFIX)): |
198 |
self._testmsgs.append(log_msg[len(constants.JQT_MSGPREFIX):]) |
|
200 |
if self._testmsgs is None: |
|
201 |
raise errors.OpExecError("Received test message without a preceding" |
|
202 |
" start message") |
|
203 |
testmsg = log_msg[len(constants.JQT_MSGPREFIX):] |
|
204 |
self._testmsgs.append(testmsg) |
|
205 |
self._all_testmsgs.append(testmsg) |
|
199 | 206 |
return |
200 | 207 |
|
201 | 208 |
return cli.StdioJobPollReportCb.ReportLogMessage(self, job_id, serial, |
... | ... | |
236 | 243 |
" not '%s' as expected" % |
237 | 244 |
(status, constants.JOB_STATUS_RUNNING)) |
238 | 245 |
|
239 |
if test == constants.JQT_LOGMSG: |
|
246 |
if test == constants.JQT_STARTMSG: |
|
247 |
logging.debug("Expecting %s test messages", arg) |
|
248 |
self._testmsgs = [] |
|
249 |
elif test == constants.JQT_LOGMSG: |
|
240 | 250 |
if len(self._testmsgs) != arg: |
241 | 251 |
raise errors.OpExecError("Received %s test messages when %s are" |
242 | 252 |
" expected" % (len(self._testmsgs), arg)) |
... | ... | |
249 | 259 |
"""Runs a few tests on the job queue. |
250 | 260 |
|
251 | 261 |
""" |
252 |
test_messages = [ |
|
253 |
"Hello World", |
|
254 |
"A", |
|
255 |
"", |
|
256 |
"B" |
|
257 |
"Foo|bar|baz", |
|
258 |
utils.TimestampForFilename(), |
|
259 |
] |
|
260 |
|
|
261 |
for fail in [False, True]: |
|
262 |
if fail: |
|
263 |
ToStdout("Testing job failure") |
|
262 |
(TM_SUCCESS, |
|
263 |
TM_MULTISUCCESS, |
|
264 |
TM_FAIL, |
|
265 |
TM_PARTFAIL) = range(4) |
|
266 |
TM_ALL = frozenset([TM_SUCCESS, TM_MULTISUCCESS, TM_FAIL, TM_PARTFAIL]) |
|
267 |
|
|
268 |
for mode in TM_ALL: |
|
269 |
test_messages = [ |
|
270 |
"Testing mode %s" % mode, |
|
271 |
"Hello World", |
|
272 |
"A", |
|
273 |
"", |
|
274 |
"B" |
|
275 |
"Foo|bar|baz", |
|
276 |
utils.TimestampForFilename(), |
|
277 |
] |
|
278 |
|
|
279 |
fail = mode in (TM_FAIL, TM_PARTFAIL) |
|
280 |
|
|
281 |
if mode == TM_PARTFAIL: |
|
282 |
ToStdout("Testing partial job failure") |
|
283 |
ops = [ |
|
284 |
opcodes.OpTestJobqueue(notify_waitlock=True, notify_exec=True, |
|
285 |
log_messages=test_messages, fail=False), |
|
286 |
opcodes.OpTestJobqueue(notify_waitlock=True, notify_exec=True, |
|
287 |
log_messages=test_messages, fail=False), |
|
288 |
opcodes.OpTestJobqueue(notify_waitlock=True, notify_exec=True, |
|
289 |
log_messages=test_messages, fail=True), |
|
290 |
opcodes.OpTestJobqueue(notify_waitlock=True, notify_exec=True, |
|
291 |
log_messages=test_messages, fail=False), |
|
292 |
] |
|
293 |
expect_messages = 3 * [test_messages] |
|
294 |
expect_opstatus = [ |
|
295 |
constants.OP_STATUS_SUCCESS, |
|
296 |
constants.OP_STATUS_SUCCESS, |
|
297 |
constants.OP_STATUS_ERROR, |
|
298 |
constants.OP_STATUS_ERROR, |
|
299 |
] |
|
300 |
expect_resultlen = 2 |
|
301 |
elif mode == TM_MULTISUCCESS: |
|
302 |
ToStdout("Testing multiple successful opcodes") |
|
303 |
ops = [ |
|
304 |
opcodes.OpTestJobqueue(notify_waitlock=True, notify_exec=True, |
|
305 |
log_messages=test_messages, fail=False), |
|
306 |
opcodes.OpTestJobqueue(notify_waitlock=True, notify_exec=True, |
|
307 |
log_messages=test_messages, fail=False), |
|
308 |
] |
|
309 |
expect_messages = 2 * [test_messages] |
|
310 |
expect_opstatus = [ |
|
311 |
constants.OP_STATUS_SUCCESS, |
|
312 |
constants.OP_STATUS_SUCCESS, |
|
313 |
] |
|
314 |
expect_resultlen = 2 |
|
264 | 315 |
else: |
265 |
ToStdout("Testing job success") |
|
266 |
|
|
267 |
op = opcodes.OpTestJobqueue(notify_waitlock=True, |
|
268 |
notify_exec=True, |
|
269 |
log_messages=test_messages, |
|
270 |
fail=fail) |
|
316 |
if mode == TM_SUCCESS: |
|
317 |
ToStdout("Testing job success") |
|
318 |
expect_opstatus = [constants.OP_STATUS_SUCCESS] |
|
319 |
elif mode == TM_FAIL: |
|
320 |
ToStdout("Testing job failure") |
|
321 |
expect_opstatus = [constants.OP_STATUS_ERROR] |
|
322 |
else: |
|
323 |
raise errors.ProgrammerError("Unknown test mode %s" % mode) |
|
324 |
|
|
325 |
ops = [ |
|
326 |
opcodes.OpTestJobqueue(notify_waitlock=True, |
|
327 |
notify_exec=True, |
|
328 |
log_messages=test_messages, |
|
329 |
fail=fail) |
|
330 |
] |
|
331 |
expect_messages = [test_messages] |
|
332 |
expect_resultlen = 1 |
|
333 |
|
|
334 |
cl = cli.GetClient() |
|
335 |
cli.SetGenericOpcodeOpts(ops, opts) |
|
336 |
|
|
337 |
# Send job to master daemon |
|
338 |
job_id = cli.SendJob(ops, cl=cl) |
|
271 | 339 |
|
272 | 340 |
reporter = _JobQueueTestReporter() |
341 |
results = None |
|
342 |
|
|
273 | 343 |
try: |
274 |
SubmitOpCode(op, reporter=reporter, opts=opts)
|
|
275 |
except errors.OpExecError: |
|
344 |
results = cli.PollJob(job_id, cl=cl, reporter=reporter)
|
|
345 |
except errors.OpExecError, err:
|
|
276 | 346 |
if not fail: |
277 | 347 |
raise |
278 |
# Ignore error
|
|
348 |
ToStdout("Ignoring error: %s", err)
|
|
279 | 349 |
else: |
280 | 350 |
if fail: |
281 | 351 |
raise errors.OpExecError("Job didn't fail when it should") |
282 | 352 |
|
353 |
# Check length of result |
|
354 |
if fail: |
|
355 |
if results is not None: |
|
356 |
raise errors.OpExecError("Received result from failed job") |
|
357 |
elif len(results) != expect_resultlen: |
|
358 |
raise errors.OpExecError("Received %s results (%s), expected %s" % |
|
359 |
(len(results), results, expect_resultlen)) |
|
360 |
|
|
283 | 361 |
# Check received log messages |
284 |
if reporter.GetTestMessages() != test_messages: |
|
362 |
all_messages = [i for j in expect_messages for i in j] |
|
363 |
if reporter.GetTestMessages() != all_messages: |
|
285 | 364 |
raise errors.OpExecError("Received test messages don't match input" |
286 | 365 |
" (input %r, received %r)" % |
287 |
(test_messages, reporter.GetTestMessages()))
|
|
366 |
(all_messages, reporter.GetTestMessages()))
|
|
288 | 367 |
|
289 | 368 |
# Check final status |
290 |
job_id = reporter.GetJobId() |
|
369 |
reported_job_id = reporter.GetJobId() |
|
370 |
if reported_job_id != job_id: |
|
371 |
raise errors.OpExecError("Reported job ID %s doesn't match" |
|
372 |
"submission job ID %s" % |
|
373 |
(reported_job_id, job_id)) |
|
291 | 374 |
|
292 |
jobdetails = cli.GetClient().QueryJobs([job_id], ["status"])[0] |
|
375 |
jobdetails = cli.GetClient().QueryJobs([job_id], ["status", "opstatus"])[0]
|
|
293 | 376 |
if not jobdetails: |
294 | 377 |
raise errors.OpExecError("Can't find job %s" % job_id) |
295 | 378 |
|
... | ... | |
298 | 381 |
else: |
299 | 382 |
exp_status = constants.JOB_STATUS_SUCCESS |
300 | 383 |
|
301 |
final_status = jobdetails[0]
|
|
384 |
(final_status, final_opstatus) = jobdetails
|
|
302 | 385 |
if final_status != exp_status: |
303 | 386 |
raise errors.OpExecError("Final job status is %s, not %s as expected" % |
304 | 387 |
(final_status, exp_status)) |
388 |
if len(final_opstatus) != len(ops): |
|
389 |
raise errors.OpExecError("Did not receive status for all opcodes (got %s," |
|
390 |
" expected %s)" % |
|
391 |
(len(final_opstatus), len(ops))) |
|
392 |
if final_opstatus != expect_opstatus: |
|
393 |
raise errors.OpExecError("Opcode status is %s, expected %s" % |
|
394 |
(final_opstatus, expect_opstatus)) |
|
395 |
|
|
396 |
ToStdout("Job queue test successful") |
|
305 | 397 |
|
306 | 398 |
return 0 |
307 | 399 |
|
Also available in: Unified diff