Commit 0959c824 authored by Iustin Pop's avatar Iustin Pop
Browse files

cmdlib: simplify some rpc error handling cases

By using the RemoteFailMsg() or the payload field of RpcResult, we can
simplify a few functions in cmdlib.

Reviewed-by: ultrotter
parent f2def43a
......@@ -2287,11 +2287,9 @@ class LUSetNodeParams(LogicalUnit):
result.append(("master_candidate", str(self.op.master_candidate)))
if self.op.master_candidate == False:
rrc = self.rpc.call_node_demote_from_mc(
if (rrc.failed or not isinstance(, (tuple, list))
or len( != 2):
self.LogWarning("Node rpc error: %s" % rrc.error)
elif not[0]:
self.LogWarning("Node failed to demote itself: %s" %[1])
msg = rrc.RemoteFailMsg()
if msg:
self.LogWarning("Node failed to demote itself: %s" % msg)
# this will trigger configuration file update, if needed
......@@ -3535,7 +3533,7 @@ class LUMigrateInstance(LogicalUnit):
if msg:
raise errors.OpExecError("Cannot resync disks on node %s: %s" %
(node, msg))
node_done, node_percent =[1]
node_done, node_percent = nres.payload
all_done = all_done and node_done
if node_percent is not None:
min_percent = min(min_percent, node_percent)
......@@ -3721,11 +3719,11 @@ class LUMigrateInstance(LogicalUnit):
msg = result.RemoteFailMsg()
if msg:
log_err = ("Failed fetching source migration information from %s: %s" %
(source_node, msg))
(source_node, msg))
raise errors.OpExecError(log_err)
self.migration_info = migration_info =[1]
self.migration_info = migration_info = result.payload
# Then switch the disks to master/master mode
......@@ -3877,7 +3875,7 @@ def _CreateSingleBlockDev(lu, node, instance, device, info, force_open):
" node %s for instance %s: %s" %
(device, node,, msg))
if device.physical_id is None:
device.physical_id =[1]
device.physical_id = result.payload
def _GenerateUniqueNames(lu, exts):
......@@ -4108,13 +4106,10 @@ def _CheckHVParams(lu, nodenames, hvname, hvparams):
info = hvinfo[node]
if info.offline:
if not or not isinstance(, (tuple, list)):
raise errors.OpPrereqError("Cannot get current information"
" from node '%s' (%s)" % (node,
if not[0]:
msg = info.RemoteFailMsg()
if msg:
raise errors.OpPrereqError("Hypervisor parameter validation failed:"
" %s" %[1])
" %s" % msg)
class LUCreateInstance(LogicalUnit):
......@@ -5346,13 +5341,10 @@ class LUGrowDisk(LogicalUnit):
for node in instance.all_nodes:
self.cfg.SetDiskID(disk, node)
result = self.rpc.call_blockdev_grow(node, disk, self.op.amount)
if (not or not isinstance(, (list, tuple)) or
len( != 2):
raise errors.OpExecError("Grow request failed to node %s" % node)
elif not[0]:
msg = result.RemoteFailMsg()
if msg:
raise errors.OpExecError("Grow request failed to node %s: %s" %
(node, msg))
if self.op.wait_for_sync:
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