Commit 045dd6d9 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add ecode to rpc.py's RpcResult.Raise()



This patch adds a new ecode argument to RpcResult.Raise(). This allows
specifying the error code (for both OpExec and OpPrereq errors).

Note that this patch also makes the OpExecError exceptions raised from
_FindFaultInstanceDisks have the error code classification.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 5c983ee5
...@@ -716,7 +716,7 @@ def _CheckNicsBridgesExist(lu, target_nics, target_node, ...@@ -716,7 +716,7 @@ def _CheckNicsBridgesExist(lu, target_nics, target_node,
if brlist: if brlist:
result = lu.rpc.call_bridges_exist(target_node, brlist) result = lu.rpc.call_bridges_exist(target_node, brlist)
result.Raise("Error checking bridges on destination node '%s'" % result.Raise("Error checking bridges on destination node '%s'" %
target_node, prereq=True) target_node, prereq=True, ecode=errors.ECODE_ENVIRON)
def _CheckInstanceBridgesExist(lu, instance, node=None): def _CheckInstanceBridgesExist(lu, instance, node=None):
...@@ -797,7 +797,7 @@ def _FindFaultyInstanceDisks(cfg, rpc, instance, node_name, prereq): ...@@ -797,7 +797,7 @@ def _FindFaultyInstanceDisks(cfg, rpc, instance, node_name, prereq):
result = rpc.call_blockdev_getmirrorstatus(node_name, instance.disks) result = rpc.call_blockdev_getmirrorstatus(node_name, instance.disks)
result.Raise("Failed to get disk status from node %s" % node_name, result.Raise("Failed to get disk status from node %s" % node_name,
prereq=prereq) prereq=prereq, ecode=errors.ECODE_ENVIRON)
for idx, bdev_status in enumerate(result.payload): for idx, bdev_status in enumerate(result.payload):
if bdev_status and bdev_status.ldisk_status == constants.LDS_FAULTY: if bdev_status and bdev_status.ldisk_status == constants.LDS_FAULTY:
...@@ -2967,7 +2967,7 @@ class LUAddNode(LogicalUnit): ...@@ -2967,7 +2967,7 @@ class LUAddNode(LogicalUnit):
result = self.rpc.call_node_has_ip_address(new_node.name, result = self.rpc.call_node_has_ip_address(new_node.name,
new_node.secondary_ip) new_node.secondary_ip)
result.Raise("Failure checking secondary ip on node %s" % new_node.name, result.Raise("Failure checking secondary ip on node %s" % new_node.name,
prereq=True) prereq=True, ecode=errors.ECODE_ENVIRON)
if not result.payload: if not result.payload:
raise errors.OpExecError("Node claims it doesn't have the secondary ip" raise errors.OpExecError("Node claims it doesn't have the secondary ip"
" you gave (%s). Please fix and re-run this" " you gave (%s). Please fix and re-run this"
...@@ -3539,7 +3539,8 @@ def _CheckNodeFreeMemory(lu, node, reason, requested, hypervisor_name): ...@@ -3539,7 +3539,8 @@ def _CheckNodeFreeMemory(lu, node, reason, requested, hypervisor_name):
""" """
nodeinfo = lu.rpc.call_node_info([node], lu.cfg.GetVGName(), hypervisor_name) nodeinfo = lu.rpc.call_node_info([node], lu.cfg.GetVGName(), hypervisor_name)
nodeinfo[node].Raise("Can't get data from node %s" % node, prereq=True) nodeinfo[node].Raise("Can't get data from node %s" % node,
prereq=True, ecode=errors.ECODE_ENVIRON)
free_mem = nodeinfo[node].payload.get('memory_free', None) free_mem = nodeinfo[node].payload.get('memory_free', None)
if not isinstance(free_mem, int): if not isinstance(free_mem, int):
raise errors.OpPrereqError("Can't compute free memory on node %s, result" raise errors.OpPrereqError("Can't compute free memory on node %s, result"
...@@ -3627,7 +3628,7 @@ class LUStartupInstance(LogicalUnit): ...@@ -3627,7 +3628,7 @@ class LUStartupInstance(LogicalUnit):
instance.name, instance.name,
instance.hypervisor) instance.hypervisor)
remote_info.Raise("Error checking node %s" % instance.primary_node, remote_info.Raise("Error checking node %s" % instance.primary_node,
prereq=True) prereq=True, ecode=errors.ECODE_ENVIRON)
if not remote_info.payload: # not running already if not remote_info.payload: # not running already
_CheckNodeFreeMemory(self, instance.primary_node, _CheckNodeFreeMemory(self, instance.primary_node,
"starting instance %s" % instance.name, "starting instance %s" % instance.name,
...@@ -3846,7 +3847,7 @@ class LUReinstallInstance(LogicalUnit): ...@@ -3846,7 +3847,7 @@ class LUReinstallInstance(LogicalUnit):
instance.name, instance.name,
instance.hypervisor) instance.hypervisor)
remote_info.Raise("Error checking node %s" % instance.primary_node, remote_info.Raise("Error checking node %s" % instance.primary_node,
prereq=True) prereq=True, ecode=errors.ECODE_ENVIRON)
if remote_info.payload: if remote_info.payload:
raise errors.OpPrereqError("Instance '%s' is running on the node %s" % raise errors.OpPrereqError("Instance '%s' is running on the node %s" %
(self.op.instance_name, (self.op.instance_name,
...@@ -3864,7 +3865,8 @@ class LUReinstallInstance(LogicalUnit): ...@@ -3864,7 +3865,8 @@ class LUReinstallInstance(LogicalUnit):
self.op.pnode, errors.ECODE_NOENT) self.op.pnode, errors.ECODE_NOENT)
result = self.rpc.call_os_get(pnode.name, self.op.os_type) result = self.rpc.call_os_get(pnode.name, self.op.os_type)
result.Raise("OS '%s' not in supported OS list for primary node %s" % result.Raise("OS '%s' not in supported OS list for primary node %s" %
(self.op.os_type, pnode.name), prereq=True) (self.op.os_type, pnode.name),
prereq=True, ecode=errors.ECODE_INVAL)
if not self.op.force_variant: if not self.op.force_variant:
_CheckOSVariant(result.payload, self.op.os_type) _CheckOSVariant(result.payload, self.op.os_type)
...@@ -3946,7 +3948,7 @@ class LURecreateInstanceDisks(LogicalUnit): ...@@ -3946,7 +3948,7 @@ class LURecreateInstanceDisks(LogicalUnit):
instance.name, instance.name,
instance.hypervisor) instance.hypervisor)
remote_info.Raise("Error checking node %s" % instance.primary_node, remote_info.Raise("Error checking node %s" % instance.primary_node,
prereq=True) prereq=True, ecode=errors.ECODE_ENVIRON)
if remote_info.payload: if remote_info.payload:
raise errors.OpPrereqError("Instance '%s' is running on the node %s" % raise errors.OpPrereqError("Instance '%s' is running on the node %s" %
(self.op.instance_name, (self.op.instance_name,
...@@ -4014,7 +4016,7 @@ class LURenameInstance(LogicalUnit): ...@@ -4014,7 +4016,7 @@ class LURenameInstance(LogicalUnit):
instance.name, instance.name,
instance.hypervisor) instance.hypervisor)
remote_info.Raise("Error checking node %s" % instance.primary_node, remote_info.Raise("Error checking node %s" % instance.primary_node,
prereq=True) prereq=True, ecode=errors.ECODE_ENVIRON)
if remote_info.payload: if remote_info.payload:
raise errors.OpPrereqError("Instance '%s' is running on the node %s" % raise errors.OpPrereqError("Instance '%s' is running on the node %s" %
(self.op.instance_name, (self.op.instance_name,
...@@ -4910,7 +4912,8 @@ class TLMigrateInstance(Tasklet): ...@@ -4910,7 +4912,8 @@ class TLMigrateInstance(Tasklet):
_CheckNodeNotDrained(self, target_node) _CheckNodeNotDrained(self, target_node)
result = self.rpc.call_instance_migratable(instance.primary_node, result = self.rpc.call_instance_migratable(instance.primary_node,
instance) instance)
result.Raise("Can't migrate, please use failover", prereq=True) result.Raise("Can't migrate, please use failover",
prereq=True, ecode=errors.ECODE_STATE)
self.instance = instance self.instance = instance
...@@ -5979,7 +5982,8 @@ class LUCreateInstance(LogicalUnit): ...@@ -5979,7 +5982,8 @@ class LUCreateInstance(LogicalUnit):
# os verification # os verification
result = self.rpc.call_os_get(pnode.name, self.op.os_type) result = self.rpc.call_os_get(pnode.name, self.op.os_type)
result.Raise("OS '%s' not in supported os list for primary node %s" % result.Raise("OS '%s' not in supported os list for primary node %s" %
(self.op.os_type, pnode.name), prereq=True) (self.op.os_type, pnode.name),
prereq=True, ecode=errors.ECODE_INVAL)
if not self.op.force_variant: if not self.op.force_variant:
_CheckOSVariant(result.payload, self.op.os_type) _CheckOSVariant(result.payload, self.op.os_type)
......
...@@ -137,7 +137,7 @@ class RpcResult(object): ...@@ -137,7 +137,7 @@ class RpcResult(object):
else: else:
return "No error information" return "No error information"
def Raise(self, msg, prereq=False): def Raise(self, msg, prereq=False, ecode=None):
"""If the result has failed, raise an OpExecError. """If the result has failed, raise an OpExecError.
This is used so that LU code doesn't have to check for each This is used so that LU code doesn't have to check for each
...@@ -156,7 +156,11 @@ class RpcResult(object): ...@@ -156,7 +156,11 @@ class RpcResult(object):
ec = errors.OpPrereqError ec = errors.OpPrereqError
else: else:
ec = errors.OpExecError ec = errors.OpExecError
raise ec(msg) if ecode is not None:
args = (msg, prereq)
else:
args = (msg, )
raise ec(*args)
class Client: class Client:
......
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