Commit b2b8bcce authored by Iustin Pop's avatar Iustin Pop
Browse files

Convert the file storage rpcs to new style result



This patch converts all three file-storage rpc (create, delete, rename)
to new style result. This is done in a single patch as they all use a
helper function which itself needs to/can be converted.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 38ea42a1
......@@ -2050,10 +2050,8 @@ def _TransformFileStorageDir(file_storage_dir):
base_file_storage_dir = cfg.GetFileStorageDir()
if (not os.path.commonprefix([file_storage_dir, base_file_storage_dir]) ==
base_file_storage_dir):
logging.error("file storage directory '%s' is not under base file"
" storage directory '%s'",
file_storage_dir, base_file_storage_dir)
return None
_Fail("File storage directory '%s' is not under base file"
" storage directory '%s'", file_storage_dir, base_file_storage_dir)
return file_storage_dir
......@@ -2069,22 +2067,17 @@ def CreateFileStorageDir(file_storage_dir):
"""
file_storage_dir = _TransformFileStorageDir(file_storage_dir)
result = True,
if not file_storage_dir:
result = False,
if os.path.exists(file_storage_dir):
if not os.path.isdir(file_storage_dir):
_Fail("Specified storage dir '%s' is not a directory",
file_storage_dir)
else:
if os.path.exists(file_storage_dir):
if not os.path.isdir(file_storage_dir):
logging.error("'%s' is not a directory", file_storage_dir)
result = False,
else:
try:
os.makedirs(file_storage_dir, 0750)
except OSError, err:
logging.error("Cannot create file storage directory '%s': %s",
file_storage_dir, err)
result = False,
return result
try:
os.makedirs(file_storage_dir, 0750)
except OSError, err:
_Fail("Cannot create file storage directory '%s': %s",
file_storage_dir, err, exc=True)
return True, None
def RemoveFileStorageDir(file_storage_dir):
......@@ -2100,22 +2093,18 @@ def RemoveFileStorageDir(file_storage_dir):
"""
file_storage_dir = _TransformFileStorageDir(file_storage_dir)
result = True,
if not file_storage_dir:
result = False,
else:
if os.path.exists(file_storage_dir):
if not os.path.isdir(file_storage_dir):
logging.error("'%s' is not a directory", file_storage_dir)
result = False,
# deletes dir only if empty, otherwise we want to return False
try:
os.rmdir(file_storage_dir)
except OSError, err:
logging.exception("Cannot remove file storage directory '%s'",
file_storage_dir)
result = False,
return result
if os.path.exists(file_storage_dir):
if not os.path.isdir(file_storage_dir):
_Fail("Specified Storage directory '%s' is not a directory",
file_storage_dir)
# deletes dir only if empty, otherwise we want to return False
try:
os.rmdir(file_storage_dir)
except OSError, err:
_Fail("Cannot remove file storage directory '%s': %s",
file_storage_dir, err)
return True, None
def RenameFileStorageDir(old_file_storage_dir, new_file_storage_dir):
......@@ -2132,27 +2121,21 @@ def RenameFileStorageDir(old_file_storage_dir, new_file_storage_dir):
"""
old_file_storage_dir = _TransformFileStorageDir(old_file_storage_dir)
new_file_storage_dir = _TransformFileStorageDir(new_file_storage_dir)
result = True,
if not old_file_storage_dir or not new_file_storage_dir:
result = False,
else:
if not os.path.exists(new_file_storage_dir):
if os.path.isdir(old_file_storage_dir):
try:
os.rename(old_file_storage_dir, new_file_storage_dir)
except OSError, err:
logging.exception("Cannot rename '%s' to '%s'",
old_file_storage_dir, new_file_storage_dir)
result = False,
else:
logging.error("'%s' is not a directory", old_file_storage_dir)
result = False,
if not os.path.exists(new_file_storage_dir):
if os.path.isdir(old_file_storage_dir):
try:
os.rename(old_file_storage_dir, new_file_storage_dir)
except OSError, err:
_Fail("Cannot rename '%s' to '%s': %s",
old_file_storage_dir, new_file_storage_dir, err)
else:
if os.path.exists(old_file_storage_dir):
logging.error("Cannot rename '%s' to '%s'. Both locations exist.",
old_file_storage_dir, new_file_storage_dir)
result = False,
return result
_Fail("Specified storage dir '%s' is not a directory",
old_file_storage_dir)
else:
if os.path.exists(old_file_storage_dir):
_Fail("Cannot rename '%s' to '%s': both locations exist",
old_file_storage_dir, new_file_storage_dir)
return True, None
def _IsJobQueueFile(file_name):
......
......@@ -3273,19 +3273,13 @@ class LURenameInstance(LogicalUnit):
result = self.rpc.call_file_storage_dir_rename(inst.primary_node,
old_file_storage_dir,
new_file_storage_dir)
result.Raise()
if not result.data:
raise errors.OpExecError("Could not connect to node '%s' to rename"
msg = result.RemoteFailMsg()
if msg:
raise errors.OpExecError("Could not rename on node %s"
" directory '%s' to '%s' (but the instance"
" has been renamed in Ganeti)" % (
inst.primary_node, old_file_storage_dir,
new_file_storage_dir))
if not result.data[0]:
raise errors.OpExecError("Could not rename directory '%s' to '%s'"
" (but the instance has been renamed in"
" Ganeti)" % (old_file_storage_dir,
new_file_storage_dir))
" has been renamed in Ganeti): %s" %
(inst.primary_node, old_file_storage_dir,
new_file_storage_dir, msg))
_StartInstanceDisks(self, inst, None)
try:
......@@ -4304,12 +4298,11 @@ def _CreateDisks(lu, instance):
file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1])
result = lu.rpc.call_file_storage_dir_create(pnode, file_storage_dir)
if result.failed or not result.data:
raise errors.OpExecError("Could not connect to node '%s'" % pnode)
msg = result.RemoteFailMsg()
if not result.data[0]:
raise errors.OpExecError("Failed to create directory '%s'" %
file_storage_dir)
if msg:
raise errors.OpExecError("Failed to create directory '%s' on"
" node %s: %s" % (file_storage_dir, msg))
# Note: this needs to be kept in sync with adding of disks in
# LUSetInstanceParams
......@@ -4354,8 +4347,10 @@ def _RemoveDisks(lu, instance):
file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1])
result = lu.rpc.call_file_storage_dir_remove(instance.primary_node,
file_storage_dir)
if result.failed or not result.data:
logging.error("Could not remove directory '%s'", file_storage_dir)
msg = result.RemoteFailMsg()
if msg:
lu.LogWarning("Could not remove directory '%s' on node %s: %s",
file_storage_dir, instance.primary_node, msg)
all_result = False
return all_result
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment