Revision afdc3985

b/lib/backend.py
68 68
  """
69 69
  if args:
70 70
    msg = msg % args
71
  if "exc" in kwargs and kwargs["exc"]:
72
    logging.exception(msg)
73
  else:
74
    logging.error(msg)
71
  if "log" not in kwargs or kwargs["log"]: # if we should log this error
72
    if "exc" in kwargs and kwargs["exc"]:
73
      logging.exception(msg)
74
    else:
75
      logging.error(msg)
75 76
  raise RPCFail(msg)
76 77

  
77 78

  
......
224 225
        logging.error(msg)
225 226
        payload.append(msg)
226 227

  
227
  return not payload, "; ".join(payload)
228
  if payload:
229
    _Fail("; ".join(payload))
230

  
231
  return True, None
228 232

  
229 233

  
230 234
def StopMaster(stop_daemons):
......
585 589
      missing.append(bridge)
586 590

  
587 591
  if missing:
588
    return False, "Missing bridges %s" % (", ".join(missing),)
592
    _Fail("Missing bridges %s", ", ".join(missing))
589 593

  
590 594
  return True, None
591 595

  
......
653 657

  
654 658
  """
655 659
  hyper = hypervisor.GetHypervisor(instance.hypervisor)
656
  if instance.name not in hyper.ListInstances():
657
    return (False, 'not running')
660
  iname = instance.name
661
  if iname not in hyper.ListInstances():
662
    _Fail("Instance %s is not running", iname)
658 663

  
659 664
  for idx in range(len(instance.disks)):
660
    link_name = _GetBlockDevSymlinkPath(instance.name, idx)
665
    link_name = _GetBlockDevSymlinkPath(iname, idx)
661 666
    if not os.path.islink(link_name):
662
      return (False, 'not restarted since ganeti 1.2.5')
667
      _Fail("Instance %s was not restarted since ganeti 1.2.5", iname)
663 668

  
664
  return (True, '')
669
  return True, None
665 670

  
666 671

  
667 672
def GetAllInstancesInfo(hypervisor_list):
......
736 741
                  result.output)
737 742
    lines = [utils.SafeEncode(val)
738 743
             for val in utils.TailFile(logfile, lines=20)]
739
    return (False, "OS create script failed (%s), last lines in the"
740
            " log file:\n%s" % (result.fail_reason, "\n".join(lines)))
744
    _Fail("OS create script failed (%s), last lines in the"
745
          " log file:\n%s", result.fail_reason, "\n".join(lines), log=False)
741 746

  
742 747
  return (True, "Successfully installed")
743 748

  
......
770 775
                  result.cmd, result.fail_reason, result.output)
771 776
    lines = [utils.SafeEncode(val)
772 777
             for val in utils.TailFile(logfile, lines=20)]
773
    return (False, "OS rename script failed (%s), last lines in the"
774
            " log file:\n%s" % (result.fail_reason, "\n".join(lines)))
778
    _Fail("OS rename script failed (%s), last lines in the"
779
          " log file:\n%s", result.fail_reason, "\n".join(lines), log=False)
775 780

  
776 781
  return (True, "Rename successful")
777 782

  
......
1188 1193
      if c_msg: # not an empty message
1189 1194
        msgs.append(c_msg)
1190 1195

  
1191
  return (result, "; ".join(msgs))
1196
  if not result:
1197
    _Fail("; ".join(msgs))
1198

  
1199
  return True, None
1192 1200

  
1193 1201

  
1194 1202
def _RecursiveAssembleBD(disk, owner, as_primary):
......
1255 1263
      C{True} for secondary nodes
1256 1264

  
1257 1265
  """
1258
  status = True
1259
  result = "no error information"
1260 1266
  try:
1261 1267
    result = _RecursiveAssembleBD(disk, owner, as_primary)
1262 1268
    if isinstance(result, bdev.BlockDev):
1263 1269
      result = result.dev_path
1264 1270
  except errors.BlockDeviceError, err:
1265
    result = "Error while assembling disk: %s" % str(err)
1266
    status = False
1267
  return (status, result)
1271
    _Fail("Error while assembling disk: %s", err, exc=True)
1272

  
1273
  return True, result
1268 1274

  
1269 1275

  
1270 1276
def BlockdevShutdown(disk):
......
1304 1310
      if c_msg: # not an empty message
1305 1311
        msgs.append(c_msg)
1306 1312

  
1307
  return (result, "; ".join(msgs))
1313
  if not result:
1314
    _Fail("; ".join(msgs))
1315
  return (True, None)
1308 1316

  
1309 1317

  
1310 1318
def BlockdevAddchildren(parent_cdev, new_cdevs):
......
1740 1748
  """
1741 1749
  r_dev = _RecursiveFindBD(disk)
1742 1750
  if r_dev is None:
1743
    return False, "Cannot find block device %s" % (disk,)
1751
    _Fail("Cannot find block device %s", disk)
1744 1752

  
1745 1753
  try:
1746 1754
    r_dev.Grow(amount)
......
1983 1991
                            (idx, result.fail_reason, result.output[-100]))
1984 1992

  
1985 1993
  if final_result:
1986
    return False, "; ".join(final_result)
1994
    _Fail("; ".join(final_result), log=False)
1987 1995
  return True, None
1988 1996

  
1989 1997

  
......
1997 2005
  if os.path.isdir(constants.EXPORT_DIR):
1998 2006
    return True, utils.ListVisibleFiles(constants.EXPORT_DIR)
1999 2007
  else:
2000
    return False, "No exports directory"
2008
    _Fail("No exports directory")
2001 2009

  
2002 2010

  
2003 2011
def RemoveExport(export):
......
2056 2064
                  (dev, unique_id, err))
2057 2065
      logging.exception("Can't rename device '%s' to '%s'", dev, unique_id)
2058 2066
      result = False
2059
  return (result, "; ".join(msgs))
2067
  if not result:
2068
    _Fail("; ".join(msgs))
2069
  return True, None
2060 2070

  
2061 2071

  
2062 2072
def _TransformFileStorageDir(file_storage_dir):
......
2124 2134
    if not os.path.isdir(file_storage_dir):
2125 2135
      _Fail("Specified Storage directory '%s' is not a directory",
2126 2136
            file_storage_dir)
2127
    # deletes dir only if empty, otherwise we want to return False
2137
    # deletes dir only if empty, otherwise we want to fail the rpc call
2128 2138
    try:
2129 2139
      os.rmdir(file_storage_dir)
2130 2140
    except OSError, err:
......
2276 2286
    except errors.BlockDeviceError, err:
2277 2287
      msg.append(str(err))
2278 2288
  if msg:
2279
    return (False, "Can't make devices secondary: %s" % ",".join(msg))
2289
    _Fail("Can't make devices secondary: %s", ",".join(msg))
2280 2290
  else:
2281 2291
    if instance_name:
2282 2292
      _RemoveBlockDevLinks(instance_name, disks)
......
2302 2312
    hv_type.ValidateParameters(hvparams)
2303 2313
    return (True, "Validation passed")
2304 2314
  except errors.HypervisorError, err:
2305
    return (False, str(err))
2315
    _Fail(str(err), log=False)
2306 2316

  
2307 2317

  
2308 2318
def DemoteFromMC():
......
2312 2322
  # try to ensure we're not the master by mistake
2313 2323
  master, myself = ssconf.GetMasterAndMyself()
2314 2324
  if master == myself:
2315
    return (False, "ssconf status shows I'm the master node, will not demote")
2325
    _Fail("ssconf status shows I'm the master node, will not demote")
2316 2326
  pid_file = utils.DaemonPidFileName(constants.MASTERD_PID)
2317 2327
  if utils.IsProcessAlive(utils.ReadPidFile(pid_file)):
2318
    return (False, "The master daemon is running, will not demote")
2328
    _Fail("The master daemon is running, will not demote")
2319 2329
  try:
2320 2330
    utils.CreateBackup(constants.CLUSTER_CONF_FILE)
2321 2331
  except EnvironmentError, err:
2322 2332
    if err.errno != errno.ENOENT:
2323
      return (False, "Error while backing up cluster file: %s" % str(err))
2333
      _Fail("Error while backing up cluster file: %s", err, exc=True)
2324 2334
  utils.RemoveFile(constants.CLUSTER_CONF_FILE)
2325 2335
  return (True, "Done")
2326 2336

  
......
2406 2416
    time.sleep(sleep_time)
2407 2417
    sleep_time = min(5, sleep_time * 1.5)
2408 2418
  if not all_connected:
2409
    return (False, "Timeout in disk reconnecting")
2419
    _Fail("Timeout in disk reconnecting")
2410 2420
  if multimaster:
2411 2421
    # change to primary mode
2412 2422
    for rd in bdevs:
......
2433 2443
  for rd in bdevs:
2434 2444
    stats = rd.GetProcStatus()
2435 2445
    if not (stats.is_connected or stats.is_in_resync):
2436
      failure = True
2437
      break
2446
      _Fail("DRBD device %s is not in sync: stats=%s", rd, stats)
2438 2447
    alldone = alldone and (not stats.is_in_resync)
2439 2448
    if stats.sync_percent is not None:
2440 2449
      min_resync = min(min_resync, stats.sync_percent)
2441
  return (not failure, (alldone, min_resync))
2450

  
2451
  return (True, (alldone, min_resync))
2442 2452

  
2443 2453

  
2444 2454
def PowercycleNode(hypervisor_type):

Also available in: Unified diff