Revision b2b8bcce

b/lib/backend.py
2050 2050
  base_file_storage_dir = cfg.GetFileStorageDir()
2051 2051
  if (not os.path.commonprefix([file_storage_dir, base_file_storage_dir]) ==
2052 2052
      base_file_storage_dir):
2053
    logging.error("file storage directory '%s' is not under base file"
2054
                  " storage directory '%s'",
2055
                  file_storage_dir, base_file_storage_dir)
2056
    return None
2053
    _Fail("File storage directory '%s' is not under base file"
2054
          " storage directory '%s'", file_storage_dir, base_file_storage_dir)
2057 2055
  return file_storage_dir
2058 2056

  
2059 2057

  
......
2069 2067

  
2070 2068
  """
2071 2069
  file_storage_dir = _TransformFileStorageDir(file_storage_dir)
2072
  result = True,
2073
  if not file_storage_dir:
2074
    result = False,
2070
  if os.path.exists(file_storage_dir):
2071
    if not os.path.isdir(file_storage_dir):
2072
      _Fail("Specified storage dir '%s' is not a directory",
2073
            file_storage_dir)
2075 2074
  else:
2076
    if os.path.exists(file_storage_dir):
2077
      if not os.path.isdir(file_storage_dir):
2078
        logging.error("'%s' is not a directory", file_storage_dir)
2079
        result = False,
2080
    else:
2081
      try:
2082
        os.makedirs(file_storage_dir, 0750)
2083
      except OSError, err:
2084
        logging.error("Cannot create file storage directory '%s': %s",
2085
                      file_storage_dir, err)
2086
        result = False,
2087
  return result
2075
    try:
2076
      os.makedirs(file_storage_dir, 0750)
2077
    except OSError, err:
2078
      _Fail("Cannot create file storage directory '%s': %s",
2079
            file_storage_dir, err, exc=True)
2080
  return True, None
2088 2081

  
2089 2082

  
2090 2083
def RemoveFileStorageDir(file_storage_dir):
......
2100 2093

  
2101 2094
  """
2102 2095
  file_storage_dir = _TransformFileStorageDir(file_storage_dir)
2103
  result = True,
2104
  if not file_storage_dir:
2105
    result = False,
2106
  else:
2107
    if os.path.exists(file_storage_dir):
2108
      if not os.path.isdir(file_storage_dir):
2109
        logging.error("'%s' is not a directory", file_storage_dir)
2110
        result = False,
2111
      # deletes dir only if empty, otherwise we want to return False
2112
      try:
2113
        os.rmdir(file_storage_dir)
2114
      except OSError, err:
2115
        logging.exception("Cannot remove file storage directory '%s'",
2116
                          file_storage_dir)
2117
        result = False,
2118
  return result
2096
  if os.path.exists(file_storage_dir):
2097
    if not os.path.isdir(file_storage_dir):
2098
      _Fail("Specified Storage directory '%s' is not a directory",
2099
            file_storage_dir)
2100
    # deletes dir only if empty, otherwise we want to return False
2101
    try:
2102
      os.rmdir(file_storage_dir)
2103
    except OSError, err:
2104
      _Fail("Cannot remove file storage directory '%s': %s",
2105
            file_storage_dir, err)
2106

  
2107
  return True, None
2119 2108

  
2120 2109

  
2121 2110
def RenameFileStorageDir(old_file_storage_dir, new_file_storage_dir):
......
2132 2121
  """
2133 2122
  old_file_storage_dir = _TransformFileStorageDir(old_file_storage_dir)
2134 2123
  new_file_storage_dir = _TransformFileStorageDir(new_file_storage_dir)
2135
  result = True,
2136
  if not old_file_storage_dir or not new_file_storage_dir:
2137
    result = False,
2138
  else:
2139
    if not os.path.exists(new_file_storage_dir):
2140
      if os.path.isdir(old_file_storage_dir):
2141
        try:
2142
          os.rename(old_file_storage_dir, new_file_storage_dir)
2143
        except OSError, err:
2144
          logging.exception("Cannot rename '%s' to '%s'",
2145
                            old_file_storage_dir, new_file_storage_dir)
2146
          result =  False,
2147
      else:
2148
        logging.error("'%s' is not a directory", old_file_storage_dir)
2149
        result = False,
2124
  if not os.path.exists(new_file_storage_dir):
2125
    if os.path.isdir(old_file_storage_dir):
2126
      try:
2127
        os.rename(old_file_storage_dir, new_file_storage_dir)
2128
      except OSError, err:
2129
        _Fail("Cannot rename '%s' to '%s': %s",
2130
              old_file_storage_dir, new_file_storage_dir, err)
2150 2131
    else:
2151
      if os.path.exists(old_file_storage_dir):
2152
        logging.error("Cannot rename '%s' to '%s'. Both locations exist.",
2153
                      old_file_storage_dir, new_file_storage_dir)
2154
        result = False,
2155
  return result
2132
      _Fail("Specified storage dir '%s' is not a directory",
2133
            old_file_storage_dir)
2134
  else:
2135
    if os.path.exists(old_file_storage_dir):
2136
      _Fail("Cannot rename '%s' to '%s': both locations exist",
2137
            old_file_storage_dir, new_file_storage_dir)
2138
  return True, None
2156 2139

  
2157 2140

  
2158 2141
def _IsJobQueueFile(file_name):
b/lib/cmdlib.py
3273 3273
      result = self.rpc.call_file_storage_dir_rename(inst.primary_node,
3274 3274
                                                     old_file_storage_dir,
3275 3275
                                                     new_file_storage_dir)
3276
      result.Raise()
3277
      if not result.data:
3278
        raise errors.OpExecError("Could not connect to node '%s' to rename"
3276
      msg = result.RemoteFailMsg()
3277
      if msg:
3278
        raise errors.OpExecError("Could not rename on node %s"
3279 3279
                                 " directory '%s' to '%s' (but the instance"
3280
                                 " has been renamed in Ganeti)" % (
3281
                                 inst.primary_node, old_file_storage_dir,
3282
                                 new_file_storage_dir))
3283

  
3284
      if not result.data[0]:
3285
        raise errors.OpExecError("Could not rename directory '%s' to '%s'"
3286
                                 " (but the instance has been renamed in"
3287
                                 " Ganeti)" % (old_file_storage_dir,
3288
                                               new_file_storage_dir))
3280
                                 " has been renamed in Ganeti): %s" %
3281
                                 (inst.primary_node, old_file_storage_dir,
3282
                                  new_file_storage_dir, msg))
3289 3283

  
3290 3284
    _StartInstanceDisks(self, inst, None)
3291 3285
    try:
......
4304 4298
    file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1])
4305 4299
    result = lu.rpc.call_file_storage_dir_create(pnode, file_storage_dir)
4306 4300

  
4307
    if result.failed or not result.data:
4308
      raise errors.OpExecError("Could not connect to node '%s'" % pnode)
4301
    msg = result.RemoteFailMsg()
4309 4302

  
4310
    if not result.data[0]:
4311
      raise errors.OpExecError("Failed to create directory '%s'" %
4312
                               file_storage_dir)
4303
    if msg:
4304
      raise errors.OpExecError("Failed to create directory '%s' on"
4305
                               " node %s: %s" % (file_storage_dir, msg))
4313 4306

  
4314 4307
  # Note: this needs to be kept in sync with adding of disks in
4315 4308
  # LUSetInstanceParams
......
4354 4347
    file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1])
4355 4348
    result = lu.rpc.call_file_storage_dir_remove(instance.primary_node,
4356 4349
                                                 file_storage_dir)
4357
    if result.failed or not result.data:
4358
      logging.error("Could not remove directory '%s'", file_storage_dir)
4350
    msg = result.RemoteFailMsg()
4351
    if msg:
4352
      lu.LogWarning("Could not remove directory '%s' on node %s: %s",
4353
                    file_storage_dir, instance.primary_node, msg)
4359 4354
      all_result = False
4360 4355

  
4361 4356
  return all_result

Also available in: Unified diff