Revision 03e86e97
b/qa/qa_job_utils.py | ||
---|---|---|
280 | 280 |
raise self._exc_info[0], self._exc_info[1], self._exc_info[2] |
281 | 281 |
|
282 | 282 |
|
283 |
class QAThreadGroup(object): |
|
284 |
"""This class manages a list of QAThreads. |
|
285 |
|
|
286 |
""" |
|
287 |
def __init__(self): |
|
288 |
self._threads = [] |
|
289 |
|
|
290 |
def Start(self, thread): |
|
291 |
"""Starts the given thread and adds it to this group. |
|
292 |
|
|
293 |
@type thread: qa_job_utils.QAThread |
|
294 |
@param thread: the thread to start and to add to this group. |
|
295 |
|
|
296 |
""" |
|
297 |
thread.start() |
|
298 |
self._threads.append(thread) |
|
299 |
|
|
300 |
def JoinAndReraise(self): |
|
301 |
"""Joins all threads in this group and calls their C{reraise} method. |
|
302 |
|
|
303 |
""" |
|
304 |
for thread in self._threads: |
|
305 |
thread.join() |
|
306 |
thread.reraise() |
|
307 |
|
|
308 |
|
|
283 | 309 |
# TODO: Can this be done as a decorator? Implement as needed. |
284 | 310 |
def RunWithLocks(fn, locks, timeout, block, *args, **kwargs): |
285 | 311 |
""" Runs the given function, acquiring a set of locks beforehand. |
b/qa/qa_performance.py | ||
---|---|---|
429 | 429 |
job_driver.WaitForCompletion() |
430 | 430 |
|
431 | 431 |
|
432 |
# TODO(thomasth): move to qa_job_utils.py once stable-2.10 is merged to master |
|
433 |
class _QAThreadGroup(object): |
|
434 |
"""This class manages a list of QAThreads. |
|
435 |
|
|
436 |
""" |
|
437 |
def __init__(self): |
|
438 |
self._threads = [] |
|
439 |
|
|
440 |
def Start(self, thread): |
|
441 |
"""Starts the given thread and adds it to this group. |
|
442 |
|
|
443 |
@type thread: qa_job_utils.QAThread |
|
444 |
@param thread: the thread to start and to add to this group. |
|
445 |
|
|
446 |
""" |
|
447 |
thread.start() |
|
448 |
self._threads.append(thread) |
|
449 |
|
|
450 |
def JoinAndReraise(self): |
|
451 |
"""Joins all threads in this group and calls their C{reraise} method. |
|
452 |
|
|
453 |
""" |
|
454 |
for thread in self._threads: |
|
455 |
thread.join() |
|
456 |
thread.reraise() |
|
457 |
|
|
458 |
|
|
459 | 432 |
def TestParallelInstanceQueries(instances): |
460 | 433 |
"""PERFORMANCE: Parallel instance queries. |
461 | 434 |
|
... | ... | |
463 | 436 |
@param instances: list of instances to issue queries against |
464 | 437 |
|
465 | 438 |
""" |
466 |
threads = _QAThreadGroup()
|
|
439 |
threads = qa_job_utils.QAThreadGroup()
|
|
467 | 440 |
for instance in instances: |
468 | 441 |
cmd = ["gnt-instance", "info", instance.name] |
469 | 442 |
info_thread = qa_job_utils.QAThread(qa_utils.AssertCommand, [cmd], {}) |
... | ... | |
512 | 485 |
|
513 | 486 |
job_driver.AddJob(job_id) |
514 | 487 |
|
515 |
threads = _QAThreadGroup()
|
|
488 |
threads = qa_job_utils.QAThreadGroup()
|
|
516 | 489 |
for i in range(10): |
517 | 490 |
thread = qa_job_utils.QAThread(_SubmitDelayJob, [20], {}) |
518 | 491 |
threads.Start(thread) |
Also available in: Unified diff