Revision 9558c2a4 qa/qa_job_utils.py

b/qa/qa_job_utils.py
293 293
  # Find out the lock names prior to starting the delay function
294 294
  lock_name_map = _FindLockNames(locks)
295 295

  
296
  termination_socket = _StartDelayFunction(locks, timeout)
297

  
298
  qa_thread = threading.Thread(target=fn, args=args, kwargs=kwargs)
299
  qa_thread.start()
300

  
301 296
  blocking_owned_locks = []
302 297
  test_blocked = False
303 298

  
299
  termination_socket = _StartDelayFunction(locks, timeout)
300
  delay_fn_terminated = False
301

  
304 302
  try:
303
    qa_thread = QAThread(fn, args, kwargs)
304
    qa_thread.start()
305

  
305 306
    while qa_thread.isAlive():
306 307
      blocking_locks = _GetBlockingLocks()
307 308
      blocking_owned_locks = \
308 309
        set(blocking_locks).intersection(set(lock_name_map))
309 310

  
310 311
      if blocking_owned_locks:
311
        test_blocked = True
312
        # Set the flag first - if the termination attempt fails, we do not want
313
        # to redo it in the finally block
314
        delay_fn_terminated = True
312 315
        _TerminateDelayFunction(termination_socket)
316
        test_blocked = True
313 317
        break
314 318

  
315
      # The sleeping time has been set arbitrarily
316
      time.sleep(5)
317
  except:
318
    # If anything goes wrong here, we should be responsible and terminate the
319
    # delay job
320
    _TerminateDelayFunction(termination_socket)
321
    raise
319
      time.sleep(5) # Set arbitrarily
320

  
321
    # The thread should be either finished or unblocked at this point
322
    qa_thread.join()
323

  
324
    # Raise any errors that might have occured in the thread
325
    qa_thread.reraise()
322 326

  
323
  qa_thread.join()
327
  finally:
328
    if not delay_fn_terminated:
329
      _TerminateDelayFunction(termination_socket)
324 330

  
325 331
  blocking_lock_names = ", ".join(map(lock_name_map.get, blocking_owned_locks))
326 332
  if not block and test_blocked:
......
330 336
    raise qa_error.Error("QA test succeded, but was not blocked as it was "
331 337
                         "expected to by locks: %s" % blocking_lock_names)
332 338
  else:
333
    _TerminateDelayFunction(termination_socket)
339
    pass
334 340

  
335 341
  # Revive the watcher
336 342
  AssertCommand(["gnt-cluster", "watcher", "continue"])

Also available in: Unified diff