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,6 +1266,11 @@ def FormatError(err): ...@@ -1266,6 +1266,11 @@ def FormatError(err):
msg = "Failure: can't resolve hostname '%s'" msg = "Failure: can't resolve hostname '%s'"
obuf.write(msg % err.args[0]) obuf.write(msg % err.args[0])
elif isinstance(err, errors.OpPrereqError): elif isinstance(err, errors.OpPrereqError):
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" obuf.write("Failure: prerequisites not met for this"
" operation:\n%s" % msg) " operation:\n%s" % msg)
elif isinstance(err, errors.OpExecError): elif isinstance(err, errors.OpExecError):
......
...@@ -100,7 +100,7 @@ class LogicalUnit(object): ...@@ -100,7 +100,7 @@ class LogicalUnit(object):
attr_val = getattr(op, attr_name, None) attr_val = getattr(op, attr_name, None)
if attr_val is None: if attr_val is None:
raise errors.OpPrereqError("Required parameter '%s' missing" % raise errors.OpPrereqError("Required parameter '%s' missing" %
attr_name) attr_name, errors.ECODE_INVAL)
self.CheckArguments() self.CheckArguments()
...@@ -297,7 +297,7 @@ class LogicalUnit(object): ...@@ -297,7 +297,7 @@ class LogicalUnit(object):
expanded_name = self.cfg.ExpandInstanceName(self.op.instance_name) expanded_name = self.cfg.ExpandInstanceName(self.op.instance_name)
if expanded_name is None: if expanded_name is None:
raise errors.OpPrereqError("Instance '%s' not known" % 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.needed_locks[locking.LEVEL_INSTANCE] = expanded_name
self.op.instance_name = expanded_name self.op.instance_name = expanded_name
...@@ -417,7 +417,8 @@ def _GetWantedNodes(lu, nodes): ...@@ -417,7 +417,8 @@ def _GetWantedNodes(lu, nodes):
""" """
if not isinstance(nodes, list): 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: if not nodes:
raise errors.ProgrammerError("_GetWantedNodes should only be called with a" raise errors.ProgrammerError("_GetWantedNodes should only be called with a"
...@@ -427,7 +428,8 @@ def _GetWantedNodes(lu, nodes): ...@@ -427,7 +428,8 @@ def _GetWantedNodes(lu, nodes):
for name in nodes: for name in nodes:
node = lu.cfg.ExpandNodeName(name) node = lu.cfg.ExpandNodeName(name)
if node is None: 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) wanted.append(node)
return utils.NiceSort(wanted) return utils.NiceSort(wanted)
...@@ -447,7 +449,8 @@ def _GetWantedInstances(lu, instances): ...@@ -447,7 +449,8 @@ def _GetWantedInstances(lu, instances):
""" """
if not isinstance(instances, list): if not isinstance(instances, list):
raise errors.OpPrereqError("Invalid argument type 'instances'") raise errors.OpPrereqError("Invalid argument type 'instances'",
errors.ECODE_INVAL)
if instances: if instances:
wanted = [] wanted = []
...@@ -455,7 +458,8 @@ def _GetWantedInstances(lu, instances): ...@@ -455,7 +458,8 @@ def _GetWantedInstances(lu, instances):
for name in instances: for name in instances:
instance = lu.cfg.ExpandInstanceName(name) instance = lu.cfg.ExpandInstanceName(name)
if instance is None: 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) wanted.append(instance)
else: else:
...@@ -479,7 +483,7 @@ def _CheckOutputFields(static, dynamic, selected): ...@@ -479,7 +483,7 @@ def _CheckOutputFields(static, dynamic, selected):
delta = f.NonMatching(selected) delta = f.NonMatching(selected)
if delta: if delta:
raise errors.OpPrereqError("Unknown output fields selected: %s" raise errors.OpPrereqError("Unknown output fields selected: %s"
% ",".join(delta)) % ",".join(delta), errors.ECODE_INVAL)
def _CheckBooleanOpField(op, name): def _CheckBooleanOpField(op, name):
...@@ -492,7 +496,7 @@ def _CheckBooleanOpField(op, name): ...@@ -492,7 +496,7 @@ def _CheckBooleanOpField(op, name):
val = getattr(op, name, None) val = getattr(op, name, None)
if not (val is None or isinstance(val, bool)): if not (val is None or isinstance(val, bool)):
raise errors.OpPrereqError("Invalid boolean parameter '%s' (%s)" % raise errors.OpPrereqError("Invalid boolean parameter '%s' (%s)" %
(name, str(val))) (name, str(val)), errors.ECODE_INVAL)
setattr(op, name, val) setattr(op, name, val)
...@@ -505,7 +509,8 @@ def _CheckNodeOnline(lu, node): ...@@ -505,7 +509,8 @@ def _CheckNodeOnline(lu, node):
""" """
if lu.cfg.GetNodeInfo(node).offline: 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): def _CheckNodeNotDrained(lu, node):
...@@ -517,7 +522,8 @@ def _CheckNodeNotDrained(lu, node): ...@@ -517,7 +522,8 @@ def _CheckNodeNotDrained(lu, node):
""" """
if lu.cfg.GetNodeInfo(node).drained: 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, def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status,
...@@ -736,10 +742,11 @@ def _CheckOSVariant(os_obj, name): ...@@ -736,10 +742,11 @@ def _CheckOSVariant(os_obj, name):
try: try:
variant = name.split("+", 1)[1] variant = name.split("+", 1)[1]
except IndexError: 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: 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): def _GetNodeInstancesInner(cfg, fn):
...@@ -856,11 +863,13 @@ class LUDestroyCluster(LogicalUnit): ...@@ -856,11 +863,13 @@ class LUDestroyCluster(LogicalUnit):
nodelist = self.cfg.GetNodeList() nodelist = self.cfg.GetNodeList()
if len(nodelist) != 1 or nodelist[0] != master: if len(nodelist) != 1 or nodelist[0] != master:
raise errors.OpPrereqError("There are still %d node(s) in" 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() instancelist = self.cfg.GetInstanceList()
if instancelist: if instancelist:
raise errors.OpPrereqError("There are still %d instance(s) in" 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): def Exec(self, feedback_fn):
"""Destroys the cluster. """Destroys the cluster.
...@@ -1217,7 +1226,8 @@ class LUVerifyCluster(LogicalUnit): ...@@ -1217,7 +1226,8 @@ class LUVerifyCluster(LogicalUnit):
""" """
self.skip_set = frozenset(self.op.skip_checks) self.skip_set = frozenset(self.op.skip_checks)
if not constants.VERIFY_OPTIONAL_CHECKS.issuperset(self.skip_set): 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): def BuildHooksEnv(self):
"""Build hooks env. """Build hooks env.
...@@ -1626,14 +1636,16 @@ class LURepairDiskSizes(NoHooksLU): ...@@ -1626,14 +1636,16 @@ class LURepairDiskSizes(NoHooksLU):
def ExpandNames(self): def ExpandNames(self):
if not isinstance(self.op.instances, list): 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: if self.op.instances:
self.wanted_names = [] self.wanted_names = []
for name in self.op.instances: for name in self.op.instances:
full_name = self.cfg.ExpandInstanceName(name) full_name = self.cfg.ExpandInstanceName(name)
if full_name is None: 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.wanted_names.append(full_name)
self.needed_locks = { self.needed_locks = {
locking.LEVEL_NODE: [], locking.LEVEL_NODE: [],
...@@ -1769,12 +1781,13 @@ class LURenameCluster(LogicalUnit): ...@@ -1769,12 +1781,13 @@ class LURenameCluster(LogicalUnit):
old_ip = self.cfg.GetMasterIP() old_ip = self.cfg.GetMasterIP()
if new_name == old_name and new_ip == old_ip: if new_name == old_name and new_ip == old_ip:
raise errors.OpPrereqError("Neither the name nor the IP address of the" 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 new_ip != old_ip:
if utils.TcpPing(new_ip, constants.DEFAULT_NODED_PORT): if utils.TcpPing(new_ip, constants.DEFAULT_NODED_PORT):
raise errors.OpPrereqError("The given cluster IP address (%s) is" raise errors.OpPrereqError("The given cluster IP address (%s) is"
" reachable on the network. Aborting." % " reachable on the network. Aborting." %
new_ip) new_ip, errors.ECODE_NOTUNIQUE)
self.op.name = new_name self.op.name = new_name
...@@ -1856,9 +1869,10 @@ class LUSetClusterParams(LogicalUnit): ...@@ -1856,9 +1869,10 @@ class LUSetClusterParams(LogicalUnit):
self.op.candidate_pool_size = int(self.op.candidate_pool_size) self.op.candidate_pool_size = int(self.op.candidate_pool_size)
except (ValueError, TypeError), err: except (ValueError, TypeError), err:
raise errors.OpPrereqError("Invalid candidate_pool_size value: %s" % raise errors.OpPrereqError("Invalid candidate_pool_size value: %s" %
str(err)) str(err), errors.ECODE_INVAL)
if self.op.candidate_pool_size < 1: 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): def ExpandNames(self):
# FIXME: in the future maybe other cluster params won't require checking on # FIXME: in the future maybe other cluster params won't require checking on
...@@ -1892,7 +1906,8 @@ class LUSetClusterParams(LogicalUnit): ...@@ -1892,7 +1906,8 @@ class LUSetClusterParams(LogicalUnit):
for disk in inst.disks: for disk in inst.disks:
if _RecursiveCheckIfLVMBased(disk): if _RecursiveCheckIfLVMBased(disk):
raise errors.OpPrereqError("Cannot disable lvm storage while" 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] node_list = self.acquired_locks[locking.LEVEL_NODE]
...@@ -1911,7 +1926,7 @@ class LUSetClusterParams(LogicalUnit): ...@@ -1911,7 +1926,7 @@ class LUSetClusterParams(LogicalUnit):
constants.MIN_VG_SIZE) constants.MIN_VG_SIZE)
if vgstatus: if vgstatus:
raise errors.OpPrereqError("Error on node '%s': %s" % raise errors.OpPrereqError("Error on node '%s': %s" %
(node, vgstatus)) (node, vgstatus), errors.ECODE_ENVIRON)
self.cluster = cluster = self.cfg.GetClusterInfo() self.cluster = cluster = self.cfg.GetClusterInfo()
# validate params changes # validate params changes
...@@ -1930,7 +1945,8 @@ class LUSetClusterParams(LogicalUnit): ...@@ -1930,7 +1945,8 @@ class LUSetClusterParams(LogicalUnit):
self.new_hvparams = objects.FillDict(cluster.hvparams, {}) self.new_hvparams = objects.FillDict(cluster.hvparams, {})
if self.op.hvparams: if self.op.hvparams:
if not isinstance(self.op.hvparams, dict): 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(): for hv_name, hv_dict in self.op.hvparams.items():
if hv_name not in self.new_hvparams: if hv_name not in self.new_hvparams:
self.new_hvparams[hv_name] = hv_dict self.new_hvparams[hv_name] = hv_dict
...@@ -1941,11 +1957,13 @@ class LUSetClusterParams(LogicalUnit): ...@@ -1941,11 +1957,13 @@ class LUSetClusterParams(LogicalUnit):
self.hv_list = self.op.enabled_hypervisors self.hv_list = self.op.enabled_hypervisors
if not self.hv_list: if not self.hv_list:
raise errors.OpPrereqError("Enabled hypervisors list must contain at" 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 invalid_hvs = set(self.hv_list) - constants.HYPER_TYPES
if invalid_hvs: if invalid_hvs:
raise errors.OpPrereqError("Enabled hypervisors contains invalid" raise errors.OpPrereqError("Enabled hypervisors contains invalid"
" entries: %s" % " ,".join(invalid_hvs)) " entries: %s" % " ,".join(invalid_hvs),
errors.ECODE_INVAL)
else: else:
self.hv_list = cluster.enabled_hypervisors self.hv_list = cluster.enabled_hypervisors
...@@ -2181,7 +2199,8 @@ class LUDiagnoseOS(NoHooksLU): ...@@ -2181,7 +2199,8 @@ class LUDiagnoseOS(NoHooksLU):
def ExpandNames(self): def ExpandNames(self):
if self.op.names: 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, _CheckOutputFields(static=self._FIELDS_STATIC,
dynamic=self._FIELDS_DYNAMIC, dynamic=self._FIELDS_DYNAMIC,
...@@ -2320,20 +2339,23 @@ class LURemoveNode(LogicalUnit): ...@@ -2320,20 +2339,23 @@ class LURemoveNode(LogicalUnit):
""" """
node = self.cfg.GetNodeInfo(self.cfg.ExpandNodeName(self.op.node_name)) node = self.cfg.GetNodeInfo(self.cfg.ExpandNodeName(self.op.node_name))
if node is None: 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() instance_list = self.cfg.GetInstanceList()
masternode = self.cfg.GetMasterNode() masternode = self.cfg.GetMasterNode()
if node.name == masternode: if node.name == masternode:
raise errors.OpPrereqError("Node is the master node," 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: for instance_name in instance_list:
instance = self.cfg.GetInstanceInfo(instance_name) instance = self.cfg.GetInstanceInfo(instance_name)
if node.name in instance.all_nodes: if node.name in instance.all_nodes:
raise errors.OpPrereqError("Instance %s is still running on the node," 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.op.node_name = node.name
self.node = node self.node = node
...@@ -2624,7 +2646,8 @@ class LUQueryNodeStorage(NoHooksLU): ...@@ -2624,7 +2646,8 @@ class LUQueryNodeStorage(NoHooksLU):
storage_type = self.op.storage_type storage_type = self.op.storage_type
if storage_type not in constants.VALID_STORAGE_TYPES: 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, _CheckOutputFields(static=self._FIELDS_STATIC,
dynamic=utils.FieldSet(*constants.VALID_STORAGE_FIELDS), dynamic=utils.FieldSet(*constants.VALID_STORAGE_FIELDS),
...@@ -2718,13 +2741,15 @@ class LUModifyNodeStorage(NoHooksLU): ...@@ -2718,13 +2741,15 @@ class LUModifyNodeStorage(NoHooksLU):
def CheckArguments(self): def CheckArguments(self):
node_name = self.cfg.ExpandNodeName(self.op.node_name) node_name = self.cfg.ExpandNodeName(self.op.node_name)
if node_name is None: 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 self.op.node_name = node_name
storage_type = self.op.storage_type storage_type = self.op.storage_type
if storage_type not in constants.VALID_STORAGE_TYPES: 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): def ExpandNames(self):
self.needed_locks = { self.needed_locks = {
...@@ -2741,13 +2766,15 @@ class LUModifyNodeStorage(NoHooksLU): ...@@ -2741,13 +2766,15 @@ class LUModifyNodeStorage(NoHooksLU):
modifiable = constants.MODIFIABLE_STORAGE_FIELDS[storage_type] modifiable = constants.MODIFIABLE_STORAGE_FIELDS[storage_type]
except KeyError: except KeyError:
raise errors.OpPrereqError("Storage units of type '%s' can not be" 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 diff = set(self.op.changes.keys()) - modifiable
if diff: if diff:
raise errors.OpPrereqError("The following fields can not be modified for" raise errors.OpPrereqError("The following fields can not be modified for"
" storage units of type '%s': %r" % " storage units of type '%s': %r" %
(storage_type, list(diff))) (storage_type, list(diff)),
errors.ECODE_INVAL)
def Exec(self, feedback_fn): def Exec(self, feedback_fn):
"""Computes the list of nodes and their attributes. """Computes the list of nodes and their attributes.
...@@ -2807,15 +2834,17 @@ class LUAddNode(LogicalUnit): ...@@ -2807,15 +2834,17 @@ class LUAddNode(LogicalUnit):
if secondary_ip is None: if secondary_ip is None:
secondary_ip = primary_ip secondary_ip = primary_ip
if not utils.IsValidIP(secondary_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 self.op.secondary_ip = secondary_ip
node_list = cfg.GetNodeList() node_list = cfg.GetNodeList()
if not self.op.readd and node in node_list: if not self.op.readd and node in node_list:
raise errors.OpPrereqError("Node %s is already in the configuration" % 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: 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: for existing_node_name in node_list:
existing_node = cfg.GetNodeInfo(existing_node_name) existing_node = cfg.GetNodeInfo(existing_node_name)
...@@ -2824,7 +2853,8 @@ class LUAddNode(LogicalUnit): ...@@ -2824,7 +2853,8 @@ class LUAddNode(LogicalUnit):
if (existing_node.primary_ip != primary_ip or if (existing_node.primary_ip != primary_ip or
existing_node.secondary_ip != secondary_ip): existing_node.secondary_ip != secondary_ip):
raise errors.OpPrereqError("Readded node doesn't have the same IP" raise errors.OpPrereqError("Readded node doesn't have the same IP"
" address configuration as before") " address configuration as before",
errors.ECODE_INVAL)
continue continue
if (existing_node.primary_ip == primary_ip or if (existing_node.primary_ip == primary_ip or
...@@ -2832,7 +2862,8 @@ class LUAddNode(LogicalUnit): ...@@ -2832,7 +2862,8 @@ class LUAddNode(LogicalUnit):
existing_node.primary_ip == secondary_ip or existing_node.primary_ip == secondary_ip or
existing_node.secondary_ip == secondary_ip): existing_node.secondary_ip == secondary_ip):
raise errors.OpPrereqError("New node ip address(es) conflict with" 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 # check that the type of the node (single versus dual homed) is the
# same as for the master # same as for the master
...@@ -2842,21 +2873,25 @@ class LUAddNode(LogicalUnit): ...@@ -2842,21 +2873,25 @@ class LUAddNode(LogicalUnit):
if master_singlehomed != newbie_singlehomed: if master_singlehomed != newbie_singlehomed:
if master_singlehomed: if master_singlehomed:
raise errors.OpPrereqError("The master has no private ip but the" raise errors.OpPrereqError("The master has no private ip but the"
" new node has one") " new node has one",
errors.ECODE_INVAL)
else: else:
raise errors.OpPrereqError("The master has a private ip but the" 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 # checks reachability
if not utils.TcpPing(primary_ip, constants.DEFAULT_NODED_PORT): 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: if not newbie_singlehomed:
# check reachability from my secondary ip to newbie's secondary ip # check reachability from my secondary ip to newbie's secondary ip
if not utils.TcpPing(secondary_ip, constants.DEFAULT_NODED_PORT, if not utils.TcpPing(secondary_ip, constants.DEFAULT_NODED_PORT,
source=myself.secondary_ip): source=myself.secondary_ip):
raise errors.OpPrereqError("Node secondary ip not reachable by TCP" 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: if self.op.readd:
exceptions = [node] exceptions = [node]
...@@ -2985,17 +3020,20 @@ class LUSetNodeParams(LogicalUnit): ...@@ -2985,17 +3020,20 @@ class LUSetNodeParams(LogicalUnit):
def CheckArguments(self): def CheckArguments(self):
node_name = self.cfg.ExpandNodeName(self.op.node_name) node_name = self.cfg.ExpandNodeName(self.op.node_name)
if node_name is None: 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 self.op.node_name = node_name
_CheckBooleanOpField(self.op, 'master_candidate') _CheckBooleanOpField(self.op, 'master_candidate')
_CheckBooleanOpField(self.op, 'offline') _CheckBooleanOpField(self.op, 'offline')
_CheckBooleanOpField(self.op, 'drained') _CheckBooleanOpField(self.op, 'drained')
all_mods = [self.op.offline, self.op.master_candidate, self.op.drained] all_mods = [self.op.offline, self.op.master_candidate, self.op.drained]
if all_mods.count(None) == 3: 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: if all_mods.count(True) > 1:
raise errors.OpPrereqError("Can't set the node into more than one" 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): def ExpandNames(self):
self.needed_locks = {locking.LEVEL_NODE: self.op.node_name} self.needed_locks = {locking.LEVEL_NODE: self.op.node_name}
...@@ -3030,7 +3068,8 @@ class LUSetNodeParams(LogicalUnit): ...@@ -3030,7 +3068,8 @@ class LUSetNodeParams(LogicalUnit):
# we can't change the master's node flags # we can't change the master's node flags
if self.op.node_name == self.cfg.GetMasterNode(): if self.op.node_name == self.cfg.GetMasterNode():
raise errors.OpPrereqError("The master role can be changed" 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 # 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 offline_or_drain = self.op.offline == True or self.op.drained == True
...@@ -3050,13 +3089,14 @@ class LUSetNodeParams(LogicalUnit): ...@@ -3050,13 +3089,14 @@ class LUSetNodeParams(LogicalUnit):