Commit 5c983ee5 authored by Iustin Pop's avatar Iustin Pop
Browse files

Introduce two-argument style for OpPrereqError



This patch introduces a two-argument style for OpPrereqError. Only the
direct raise calls in cmdlib.py are converted, other users will follow.

cli.py is modified to handle both two-argument style and the current
format. RAPI doesn't need modification as the way we encode errors is
already using a list for the error arguments, so RAPI users only need to
start checking the list length and the second argument.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 159d4ec6
......@@ -1266,8 +1266,13 @@ def FormatError(err):
msg = "Failure: can't resolve hostname '%s'"
obuf.write(msg % err.args[0])
elif isinstance(err, errors.OpPrereqError):
obuf.write("Failure: prerequisites not met for this"
" operation:\n%s" % msg)
if len(err.args) == 2:
obuf.write("Failure: prerequisites not met for this"
" operation:\nerror type: %s, error details:\n%s" %
(err.args[1], err.args[0]))
else:
obuf.write("Failure: prerequisites not met for this"
" operation:\n%s" % msg)
elif isinstance(err, errors.OpExecError):
obuf.write("Failure: command execution error:\n%s" % msg)
elif isinstance(err, errors.TagError):
......
......@@ -100,7 +100,7 @@ class LogicalUnit(object):
attr_val = getattr(op, attr_name, None)
if attr_val is None:
raise errors.OpPrereqError("Required parameter '%s' missing" %
attr_name)
attr_name, errors.ECODE_INVAL)
self.CheckArguments()
......@@ -297,7 +297,7 @@ class LogicalUnit(object):
expanded_name = self.cfg.ExpandInstanceName(self.op.instance_name)
if expanded_name is None:
raise errors.OpPrereqError("Instance '%s' not known" %
self.op.instance_name)
self.op.instance_name, errors.ECODE_NOENT)
self.needed_locks[locking.LEVEL_INSTANCE] = expanded_name
self.op.instance_name = expanded_name
......@@ -417,7 +417,8 @@ def _GetWantedNodes(lu, nodes):
"""
if not isinstance(nodes, list):
raise errors.OpPrereqError("Invalid argument type 'nodes'")
raise errors.OpPrereqError("Invalid argument type 'nodes'",
errors.ECODE_INVAL)
if not nodes:
raise errors.ProgrammerError("_GetWantedNodes should only be called with a"
......@@ -427,7 +428,8 @@ def _GetWantedNodes(lu, nodes):
for name in nodes:
node = lu.cfg.ExpandNodeName(name)
if node is None:
raise errors.OpPrereqError("No such node name '%s'" % name)
raise errors.OpPrereqError("No such node name '%s'" % name,
errors.ECODE_NOENT)
wanted.append(node)
return utils.NiceSort(wanted)
......@@ -447,7 +449,8 @@ def _GetWantedInstances(lu, instances):
"""
if not isinstance(instances, list):
raise errors.OpPrereqError("Invalid argument type 'instances'")
raise errors.OpPrereqError("Invalid argument type 'instances'",
errors.ECODE_INVAL)
if instances:
wanted = []
......@@ -455,7 +458,8 @@ def _GetWantedInstances(lu, instances):
for name in instances:
instance = lu.cfg.ExpandInstanceName(name)
if instance is None:
raise errors.OpPrereqError("No such instance name '%s'" % name)
raise errors.OpPrereqError("No such instance name '%s'" % name,
errors.ECODE_NOENT)
wanted.append(instance)
else:
......@@ -479,7 +483,7 @@ def _CheckOutputFields(static, dynamic, selected):
delta = f.NonMatching(selected)
if delta:
raise errors.OpPrereqError("Unknown output fields selected: %s"
% ",".join(delta))
% ",".join(delta), errors.ECODE_INVAL)
def _CheckBooleanOpField(op, name):
......@@ -492,7 +496,7 @@ def _CheckBooleanOpField(op, name):
val = getattr(op, name, None)
if not (val is None or isinstance(val, bool)):
raise errors.OpPrereqError("Invalid boolean parameter '%s' (%s)" %
(name, str(val)))
(name, str(val)), errors.ECODE_INVAL)
setattr(op, name, val)
......@@ -505,7 +509,8 @@ def _CheckNodeOnline(lu, node):
"""
if lu.cfg.GetNodeInfo(node).offline:
raise errors.OpPrereqError("Can't use offline node %s" % node)
raise errors.OpPrereqError("Can't use offline node %s" % node,
errors.ECODE_INVAL)
def _CheckNodeNotDrained(lu, node):
......@@ -517,7 +522,8 @@ def _CheckNodeNotDrained(lu, node):
"""
if lu.cfg.GetNodeInfo(node).drained:
raise errors.OpPrereqError("Can't use drained node %s" % node)
raise errors.OpPrereqError("Can't use drained node %s" % node,
errors.ECODE_INVAL)
def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status,
......@@ -736,10 +742,11 @@ def _CheckOSVariant(os_obj, name):
try:
variant = name.split("+", 1)[1]
except IndexError:
raise errors.OpPrereqError("OS name must include a variant")
raise errors.OpPrereqError("OS name must include a variant",
errors.ECODE_INVAL)
if variant not in os_obj.supported_variants:
raise errors.OpPrereqError("Unsupported OS variant")
raise errors.OpPrereqError("Unsupported OS variant", errors.ECODE_INVAL)
def _GetNodeInstancesInner(cfg, fn):
......@@ -856,11 +863,13 @@ class LUDestroyCluster(LogicalUnit):
nodelist = self.cfg.GetNodeList()
if len(nodelist) != 1 or nodelist[0] != master:
raise errors.OpPrereqError("There are still %d node(s) in"
" this cluster." % (len(nodelist) - 1))
" this cluster." % (len(nodelist) - 1),
errors.ECODE_INVAL)
instancelist = self.cfg.GetInstanceList()
if instancelist:
raise errors.OpPrereqError("There are still %d instance(s) in"
" this cluster." % len(instancelist))
" this cluster." % len(instancelist),
errors.ECODE_INVAL)
def Exec(self, feedback_fn):
"""Destroys the cluster.
......@@ -1217,7 +1226,8 @@ class LUVerifyCluster(LogicalUnit):
"""
self.skip_set = frozenset(self.op.skip_checks)
if not constants.VERIFY_OPTIONAL_CHECKS.issuperset(self.skip_set):
raise errors.OpPrereqError("Invalid checks to be skipped specified")
raise errors.OpPrereqError("Invalid checks to be skipped specified",
errors.ECODE_INVAL)
def BuildHooksEnv(self):
"""Build hooks env.
......@@ -1626,14 +1636,16 @@ class LURepairDiskSizes(NoHooksLU):
def ExpandNames(self):
if not isinstance(self.op.instances, list):
raise errors.OpPrereqError("Invalid argument type 'instances'")
raise errors.OpPrereqError("Invalid argument type 'instances'",
errors.ECODE_INVAL)
if self.op.instances:
self.wanted_names = []
for name in self.op.instances:
full_name = self.cfg.ExpandInstanceName(name)
if full_name is None:
raise errors.OpPrereqError("Instance '%s' not known" % name)
raise errors.OpPrereqError("Instance '%s' not known" % name,
errors.ECODE_NOENT)
self.wanted_names.append(full_name)
self.needed_locks = {
locking.LEVEL_NODE: [],
......@@ -1769,12 +1781,13 @@ class LURenameCluster(LogicalUnit):
old_ip = self.cfg.GetMasterIP()
if new_name == old_name and new_ip == old_ip:
raise errors.OpPrereqError("Neither the name nor the IP address of the"
" cluster has changed")
" cluster has changed",
errors.ECODE_INVAL)
if new_ip != old_ip:
if utils.TcpPing(new_ip, constants.DEFAULT_NODED_PORT):
raise errors.OpPrereqError("The given cluster IP address (%s) is"
" reachable on the network. Aborting." %
new_ip)
new_ip, errors.ECODE_NOTUNIQUE)
self.op.name = new_name
......@@ -1856,9 +1869,10 @@ class LUSetClusterParams(LogicalUnit):
self.op.candidate_pool_size = int(self.op.candidate_pool_size)
except (ValueError, TypeError), err:
raise errors.OpPrereqError("Invalid candidate_pool_size value: %s" %
str(err))
str(err), errors.ECODE_INVAL)
if self.op.candidate_pool_size < 1:
raise errors.OpPrereqError("At least one master candidate needed")
raise errors.OpPrereqError("At least one master candidate needed",
errors.ECODE_INVAL)
def ExpandNames(self):
# FIXME: in the future maybe other cluster params won't require checking on
......@@ -1892,7 +1906,8 @@ class LUSetClusterParams(LogicalUnit):
for disk in inst.disks:
if _RecursiveCheckIfLVMBased(disk):
raise errors.OpPrereqError("Cannot disable lvm storage while"
" lvm-based instances exist")
" lvm-based instances exist",
errors.ECODE_INVAL)
node_list = self.acquired_locks[locking.LEVEL_NODE]
......@@ -1911,7 +1926,7 @@ class LUSetClusterParams(LogicalUnit):
constants.MIN_VG_SIZE)
if vgstatus:
raise errors.OpPrereqError("Error on node '%s': %s" %
(node, vgstatus))
(node, vgstatus), errors.ECODE_ENVIRON)
self.cluster = cluster = self.cfg.GetClusterInfo()
# validate params changes
......@@ -1930,7 +1945,8 @@ class LUSetClusterParams(LogicalUnit):
self.new_hvparams = objects.FillDict(cluster.hvparams, {})
if self.op.hvparams:
if not isinstance(self.op.hvparams, dict):
raise errors.OpPrereqError("Invalid 'hvparams' parameter on input")
raise errors.OpPrereqError("Invalid 'hvparams' parameter on input",
errors.ECODE_INVAL)
for hv_name, hv_dict in self.op.hvparams.items():
if hv_name not in self.new_hvparams:
self.new_hvparams[hv_name] = hv_dict
......@@ -1941,11 +1957,13 @@ class LUSetClusterParams(LogicalUnit):
self.hv_list = self.op.enabled_hypervisors
if not self.hv_list:
raise errors.OpPrereqError("Enabled hypervisors list must contain at"
" least one member")
" least one member",
errors.ECODE_INVAL)
invalid_hvs = set(self.hv_list) - constants.HYPER_TYPES
if invalid_hvs:
raise errors.OpPrereqError("Enabled hypervisors contains invalid"
" entries: %s" % " ,".join(invalid_hvs))
" entries: %s" % " ,".join(invalid_hvs),
errors.ECODE_INVAL)
else:
self.hv_list = cluster.enabled_hypervisors
......@@ -2181,7 +2199,8 @@ class LUDiagnoseOS(NoHooksLU):
def ExpandNames(self):
if self.op.names:
raise errors.OpPrereqError("Selective OS query not supported")
raise errors.OpPrereqError("Selective OS query not supported",
errors.ECODE_INVAL)
_CheckOutputFields(static=self._FIELDS_STATIC,
dynamic=self._FIELDS_DYNAMIC,
......@@ -2320,20 +2339,23 @@ class LURemoveNode(LogicalUnit):
"""
node = self.cfg.GetNodeInfo(self.cfg.ExpandNodeName(self.op.node_name))
if node is None:
raise errors.OpPrereqError, ("Node '%s' is unknown." % self.op.node_name)
raise errors.OpPrereqError("Node '%s' is unknown." % self.op.node_name,
errors.ECODE_NOENT)
instance_list = self.cfg.GetInstanceList()
masternode = self.cfg.GetMasterNode()
if node.name == masternode:
raise errors.OpPrereqError("Node is the master node,"
" you need to failover first.")
" you need to failover first.",
errors.ECODE_INVAL)
for instance_name in instance_list:
instance = self.cfg.GetInstanceInfo(instance_name)
if node.name in instance.all_nodes:
raise errors.OpPrereqError("Instance %s is still running on the node,"
" please remove first." % instance_name)
" please remove first." % instance_name,
errors.ECODE_INVAL)
self.op.node_name = node.name
self.node = node
......@@ -2624,7 +2646,8 @@ class LUQueryNodeStorage(NoHooksLU):
storage_type = self.op.storage_type
if storage_type not in constants.VALID_STORAGE_TYPES:
raise errors.OpPrereqError("Unknown storage type: %s" % storage_type)
raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
errors.ECODE_INVAL)
_CheckOutputFields(static=self._FIELDS_STATIC,
dynamic=utils.FieldSet(*constants.VALID_STORAGE_FIELDS),
......@@ -2718,13 +2741,15 @@ class LUModifyNodeStorage(NoHooksLU):
def CheckArguments(self):
node_name = self.cfg.ExpandNodeName(self.op.node_name)
if node_name is None:
raise errors.OpPrereqError("Invalid node name '%s'" % self.op.node_name)
raise errors.OpPrereqError("Invalid node name '%s'" % self.op.node_name,
errors.ECODE_NOENT)
self.op.node_name = node_name
storage_type = self.op.storage_type
if storage_type not in constants.VALID_STORAGE_TYPES:
raise errors.OpPrereqError("Unknown storage type: %s" % storage_type)
raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
errors.ECODE_INVAL)
def ExpandNames(self):
self.needed_locks = {
......@@ -2741,13 +2766,15 @@ class LUModifyNodeStorage(NoHooksLU):
modifiable = constants.MODIFIABLE_STORAGE_FIELDS[storage_type]
except KeyError:
raise errors.OpPrereqError("Storage units of type '%s' can not be"
" modified" % storage_type)
" modified" % storage_type,
errors.ECODE_INVAL)
diff = set(self.op.changes.keys()) - modifiable
if diff:
raise errors.OpPrereqError("The following fields can not be modified for"
" storage units of type '%s': %r" %
(storage_type, list(diff)))
(storage_type, list(diff)),
errors.ECODE_INVAL)
def Exec(self, feedback_fn):
"""Computes the list of nodes and their attributes.
......@@ -2807,15 +2834,17 @@ class LUAddNode(LogicalUnit):
if secondary_ip is None:
secondary_ip = primary_ip
if not utils.IsValidIP(secondary_ip):
raise errors.OpPrereqError("Invalid secondary IP given")
raise errors.OpPrereqError("Invalid secondary IP given",
errors.ECODE_INVAL)
self.op.secondary_ip = secondary_ip
node_list = cfg.GetNodeList()
if not self.op.readd and node in node_list:
raise errors.OpPrereqError("Node %s is already in the configuration" %
node)
node, errors.ECODE_EXISTS)
elif self.op.readd and node not in node_list:
raise errors.OpPrereqError("Node %s is not in the configuration" % node)
raise errors.OpPrereqError("Node %s is not in the configuration" % node,
errors.ECODE_NOENT)
for existing_node_name in node_list:
existing_node = cfg.GetNodeInfo(existing_node_name)
......@@ -2824,7 +2853,8 @@ class LUAddNode(LogicalUnit):
if (existing_node.primary_ip != primary_ip or
existing_node.secondary_ip != secondary_ip):
raise errors.OpPrereqError("Readded node doesn't have the same IP"
" address configuration as before")
" address configuration as before",
errors.ECODE_INVAL)
continue
if (existing_node.primary_ip == primary_ip or
......@@ -2832,7 +2862,8 @@ class LUAddNode(LogicalUnit):
existing_node.primary_ip == secondary_ip or
existing_node.secondary_ip == secondary_ip):
raise errors.OpPrereqError("New node ip address(es) conflict with"
" existing node %s" % existing_node.name)
" existing node %s" % existing_node.name,
errors.ECODE_NOTUNIQUE)
# check that the type of the node (single versus dual homed) is the
# same as for the master
......@@ -2842,21 +2873,25 @@ class LUAddNode(LogicalUnit):
if master_singlehomed != newbie_singlehomed:
if master_singlehomed:
raise errors.OpPrereqError("The master has no private ip but the"
" new node has one")
" new node has one",
errors.ECODE_INVAL)
else:
raise errors.OpPrereqError("The master has a private ip but the"
" new node doesn't have one")
" new node doesn't have one",
errors.ECODE_INVAL)
# checks reachability
if not utils.TcpPing(primary_ip, constants.DEFAULT_NODED_PORT):
raise errors.OpPrereqError("Node not reachable by ping")
raise errors.OpPrereqError("Node not reachable by ping",
errors.ECODE_ENVIRON)
if not newbie_singlehomed:
# check reachability from my secondary ip to newbie's secondary ip
if not utils.TcpPing(secondary_ip, constants.DEFAULT_NODED_PORT,
source=myself.secondary_ip):
raise errors.OpPrereqError("Node secondary ip not reachable by TCP"
" based ping to noded port")
" based ping to noded port",
errors.ECODE_ENVIRON)
if self.op.readd:
exceptions = [node]
......@@ -2985,17 +3020,20 @@ class LUSetNodeParams(LogicalUnit):
def CheckArguments(self):
node_name = self.cfg.ExpandNodeName(self.op.node_name)
if node_name is None:
raise errors.OpPrereqError("Invalid node name '%s'" % self.op.node_name)
raise errors.OpPrereqError("Invalid node name '%s'" % self.op.node_name,
errors.ECODE_INVAL)
self.op.node_name = node_name
_CheckBooleanOpField(self.op, 'master_candidate')
_CheckBooleanOpField(self.op, 'offline')
_CheckBooleanOpField(self.op, 'drained')
all_mods = [self.op.offline, self.op.master_candidate, self.op.drained]
if all_mods.count(None) == 3:
raise errors.OpPrereqError("Please pass at least one modification")
raise errors.OpPrereqError("Please pass at least one modification",
errors.ECODE_INVAL)
if all_mods.count(True) > 1:
raise errors.OpPrereqError("Can't set the node into more than one"
" state at the same time")
" state at the same time",
errors.ECODE_INVAL)
def ExpandNames(self):
self.needed_locks = {locking.LEVEL_NODE: self.op.node_name}
......@@ -3030,7 +3068,8 @@ class LUSetNodeParams(LogicalUnit):
# we can't change the master's node flags
if self.op.node_name == self.cfg.GetMasterNode():
raise errors.OpPrereqError("The master role can be changed"
" only via masterfailover")
" only via masterfailover",
errors.ECODE_INVAL)
# Boolean value that tells us whether we're offlining or draining the node
offline_or_drain = self.op.offline == True or self.op.drained == True
......@@ -3050,13 +3089,14 @@ class LUSetNodeParams(LogicalUnit):
if self.op.force and offline_or_drain and mc_should == mc_max:
self.LogWarning(msg)
else:
raise errors.OpPrereqError(msg)
raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
if (self.op.master_candidate == True and
((node.offline and not self.op.offline == False) or
(node.drained and not self.op.drained == False))):
raise errors.OpPrereqError("Node '%s' is offline or drained, can't set"
" to master_candidate" % node.name)
" to master_candidate" % node.name,
errors.ECODE_INVAL)
# If we're being deofflined/drained, we'll MC ourself if needed
if (deoffline_or_drain and not offline_or_drain and not
......@@ -3133,11 +3173,13 @@ class LUPowercycleNode(NoHooksLU):
def CheckArguments(self):
node_name = self.cfg.ExpandNodeName(self.op.node_name)
if node_name is None:
raise errors.OpPrereqError("Invalid node name '%s'" % self.op.node_name)
raise errors.OpPrereqError("Invalid node name '%s'" % self.op.node_name,
errors.ECODE_NOENT)
self.op.node_name = node_name
if node_name == self.cfg.GetMasterNode() and not self.op.force:
raise errors.OpPrereqError("The node is the master and the force"
" parameter was not set")
" parameter was not set",
errors.ECODE_INVAL)
def ExpandNames(self):
"""Locking for PowercycleNode.
......@@ -3501,11 +3543,13 @@ def _CheckNodeFreeMemory(lu, node, reason, requested, hypervisor_name):
free_mem = nodeinfo[node].payload.get('memory_free', None)
if not isinstance(free_mem, int):
raise errors.OpPrereqError("Can't compute free memory on node %s, result"
" was '%s'" % (node, free_mem))
" was '%s'" % (node, free_mem),
errors.ECODE_ENVIRON)
if requested > free_mem:
raise errors.OpPrereqError("Not enough memory on node %s for %s:"
" needed %s MiB, available %s MiB" %
(node, reason, requested, free_mem))
(node, reason, requested, free_mem),
errors.ECODE_NORES)
class LUStartupInstance(LogicalUnit):
......@@ -3548,7 +3592,8 @@ class LUStartupInstance(LogicalUnit):
if self.beparams:
if not isinstance(self.beparams, dict):
raise errors.OpPrereqError("Invalid beparams passed: %s, expected"
" dict" % (type(self.beparams), ))
" dict" % (type(self.beparams), ),
errors.ECODE_INVAL)
# fill the beparams dict
utils.ForceDictType(self.beparams, constants.BES_PARAMETER_TYPES)
self.op.beparams = self.beparams
......@@ -3558,7 +3603,8 @@ class LUStartupInstance(LogicalUnit):
if self.hvparams:
if not isinstance(self.hvparams, dict):
raise errors.OpPrereqError("Invalid hvparams passed: %s, expected"
" dict" % (type(self.hvparams), ))
" dict" % (type(self.hvparams), ),
errors.ECODE_INVAL)
# check hypervisor parameter syntax (locally)
cluster = self.cfg.GetClusterInfo()
......@@ -3790,10 +3836,12 @@ class LUReinstallInstance(LogicalUnit):
if instance.disk_template == constants.DT_DISKLESS:
raise errors.OpPrereqError("Instance '%s' has no disks" %
self.op.instance_name)
self.op.instance_name,
errors.ECODE_INVAL)
if instance.admin_up:
raise errors.OpPrereqError("Instance '%s' is marked to be up" %
self.op.instance_name)
self.op.instance_name,
errors.ECODE_STATE)
remote_info = self.rpc.call_instance_info(instance.primary_node,
instance.name,
instance.hypervisor)
......@@ -3802,7 +3850,8 @@ class LUReinstallInstance(LogicalUnit):
if remote_info.payload:
raise errors.OpPrereqError("Instance '%s' is running on the node %s" %
(self.op.instance_name,
instance.primary_node))
instance.primary_node),
errors.ECODE_STATE)
self.op.os_type = getattr(self.op, "os_type", None)
self.op.force_variant = getattr(self.op, "force_variant", False)
......@@ -3812,7 +3861,7 @@ class LUReinstallInstance(LogicalUnit):
self.cfg.ExpandNodeName(instance.primary_node))
if pnode is None:
raise errors.OpPrereqError("Primary node '%s' is unknown" %
self.op.pnode)
self.op.pnode, errors.ECODE_NOENT)
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" %
(self.op.os_type, pnode.name), prereq=True)
......@@ -3856,12 +3905,12 @@ class LURecreateInstanceDisks(LogicalUnit):
"""
if not isinstance(self.op.disks, list):
raise errors.OpPrereqError("Invalid disks parameter")
raise errors.OpPrereqError("Invalid disks parameter", errors.ECODE_INVAL)
for item in self.op.disks:
if (not isinstance(item, int) or
item < 0):
raise errors.OpPrereqError("Invalid disk specification '%s'" %
str(item))
str(item), errors.ECODE_INVAL)
def ExpandNames(self):
self._ExpandAndLockInstance()
......@@ -3889,10 +3938,10 @@ class LURecreateInstanceDisks(LogicalUnit):
if instance.disk_template == constants.DT_DISKLESS:
raise errors.OpPrereqError("Instance '%s' has no disks" %
self.op.instance_name)
self.op.instance_name, errors.ECODE_INVAL)
if instance.admin_up:
raise errors.OpPrereqError("Instance '%s' is marked to be up" %
self.op.instance_name)
self.op.instance_name, errors.ECODE_STATE)
remote_info = self.rpc.call_instance_info(instance.primary_node,
instance.name,
instance.hypervisor)
......@@ -3901,14 +3950,15 @@ class LURecreateInstanceDisks(LogicalUnit):
if remote_info.payload:
raise errors.OpPrereqError("Instance '%s' is running on the node %s" %
(self.op.instance_name,
instance.primary_node))
instance.primary_node), errors.ECODE_STATE)
if not self.op.disks:
self.op.disks = range(len(instance.disks))
else:
for idx in self.op.disks:
if idx >= len(instance.disks):
raise errors.OpPrereqError("Invalid disk index passed '%s'" % idx)
raise errors.OpPrereqError("Invalid disk index passed '%s'" % idx,
errors.ECODE_INVAL)
self.instance = instance
......@@ -3954,12 +4004,12 @@ class LURenameInstance(LogicalUnit):
self.cfg.ExpandInstanceName(self.op.instance_name))
if instance is None:
raise errors.OpPrereqError("Instance '%s' not known" %
self.op.instance_name)
self.op.instance_name, errors.ECODE_NOENT)
_CheckNodeOnline(self, instance.primary_node)
if instance.admin_up:
raise errors.OpPrereqError("Instance '%s' is marked to be up" %
self.op.instance_name)
self.op.instance_name, errors.ECODE_STATE)
remote_info = self.rpc.call_instance_info(instance.primary_node,
instance.name,
instance.hypervisor)
......@@ -3968,7 +4018,7 @@ class LURenameInstance(LogicalUnit):
if remote_info.payload:
raise errors.OpPrereqError("Instance '%s' is running on the node %s" %
(self.op.instance_name,
instance.primary_node))
instance.primary_node), errors.ECODE_STATE)
self.instance = instance
# new name verification
......@@ -3978,12 +4028,13 @@ class LURenameInstance(LogicalUnit):
instance_list = self.cfg.GetInstanceList()
if new_name in instance_list:
raise errors.OpPrereqError("Instance '%s' is already in the cluster" %
new_name)
new_name, errors.ECODE_EXISTS)
if not getattr(self.op, "ignore_ip", False):
if utils.TcpPing(name_info.ip, constants.DEFAULT_NODED_PORT):
raise errors.OpPrereqError("IP %s of instance %s already in use" %
(name_info.ip, new_name))
(name_info.ip, new_name),
errors.ECODE_NOTUNIQUE)
def Exec(self, feedback_fn):
......@@ -4437,7 +4488,8 @@ class LUFailoverInstance(LogicalUnit):
bep = self.cfg.GetClusterInfo().FillBE(instance)
if instance.disk_template not in constants.DTS_NET_MIRROR:
raise errors.OpPrereqError("Instance's disk layout is not"
" network mirrored, cannot failover.")
" network mirrored, cannot failover.",
errors.ECODE_STATE)
secondary_nodes = instance.secondary_nodes
if not secondary_nodes:
......@@ -4591,7 +4643,7 @@ class LUMoveInstance(LogicalUnit):
target_node = self.cfg.ExpandNodeName(self.op.target_node)
if target_node is None:
raise errors.OpPrereqError("Node '%s' not known" %
self.op.target_node)
self.op.target_node, errors.ECODE_NOENT)
self.op.target_node = target_node
self.needed_locks[locking.LEVEL_NODE] = [target_node]
self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_APPEND
......@@ -4633,14 +4685,15 @@ class LUMoveInstance(LogicalUnit):