Revision 424f51ec

b/tools/move-instance
290 290
    self.dest_snode = dest_snode
291 291
    self.dest_iallocator = dest_iallocator
292 292

  
293
    self.success = None
294 293
    self.error_message = None
295 294

  
296 295

  
......
311 310
    self.source_to_dest = threading.Condition(self.lock)
312 311
    self.dest_to_source = threading.Condition(self.lock)
313 312

  
314
    # Set when threads should abort
315
    self.abort = None
316

  
317 313
    # Source information
318
    self.src_success = None
319 314
    self.src_error_message = None
320 315
    self.src_expinfo = None
321 316
    self.src_instinfo = None
322 317

  
323 318
    # Destination information
324
    self.dest_success = None
325 319
    self.dest_error_message = None
326 320
    self.dest_impinfo = None
327 321

  
......
340 334
      # Call inner function
341 335
      fn(*args)
342 336

  
343
      success = True
344 337
      errmsg = None
345 338
    except Abort:
346
      success = False
347 339
      errmsg = "Aborted"
348 340
    except Exception, err:
349 341
      logging.exception("Caught unhandled exception")
350
      success = False
351 342
      errmsg = str(err)
352 343

  
344
    setattr(self, "%s_error_message" % prefix, errmsg)
345

  
353 346
    self.lock.acquire()
354 347
    try:
355
      # Tell all threads to abort
356
      self.abort = True
357 348
      self.source_to_dest.notifyAll()
358 349
      self.dest_to_source.notifyAll()
359 350
    finally:
360 351
      self.lock.release()
361 352

  
362
    setattr(self, "%s_success" % prefix, success)
363
    setattr(self, "%s_error_message" % prefix, errmsg)
364

  
365 353
  def CheckAbort(self):
366 354
    """Check whether thread should be aborted.
367 355

  
368 356
    @raise Abort: When thread should be aborted
369 357

  
370 358
    """
371
    if self.abort:
359
    if not (self.src_error_message is None and
360
            self.dest_error_message is None):
372 361
      logging.info("Aborting")
373 362
      raise Abort()
374 363

  
......
652 641
      finally:
653 642
        dest_thread.join()
654 643

  
655
      move.success = (mrt.src_success and mrt.dest_success)
656 644
      if mrt.src_error_message or mrt.dest_error_message:
657 645
        move.error_message = ("Source error: %s, destination error: %s" %
658 646
                              (mrt.src_error_message, mrt.dest_error_message))
......
660 648
        move.error_message = None
661 649
    except Exception, err: # pylint: disable-msg=W0703
662 650
      logging.exception("Caught unhandled exception")
663
      move.success = False
664 651
      move.error_message = str(err)
665 652

  
666 653

  
......
850 837
    else:
851 838
      name = "%s as %s" % (move.src_instance_name, move.dest_instance_name)
852 839

  
853
    if move.success and not move.error_message:
854
      msg = "Success"
855
    else:
840
    if move.error_message:
856 841
      msg = "Failed (%s)" % move.error_message
842
    else:
843
      msg = "Success"
857 844

  
858 845
    logging.info("%s: %s", name, msg)
859 846

  
860
  if compat.all(move.success for move in moves):
861
    sys.exit(constants.EXIT_SUCCESS)
847
  if compat.any(move.error_message for move in moves):
848
    sys.exit(constants.EXIT_FAILURE)
862 849

  
863
  sys.exit(constants.EXIT_FAILURE)
850
  sys.exit(constants.EXIT_SUCCESS)
864 851

  
865 852

  
866 853
if __name__ == "__main__":

Also available in: Unified diff