Commit a5c30dc2 authored by Adeodato Simo's avatar Adeodato Simo Committed by Guido Trotter
Browse files

Cluster verify: factor out error codes and functions



We move all error code definitions, plus the _Error and _ErrorIf helpers,
to a private _VerifyErrors mix-in class that can be later shared by the new
two cluster verify LUs.

(_Error and _ErrorIf code was moved around verbatim, except to disable
"_VerifyError class does not have 'op' or '_feedback_fn' members" errors
from pylint.)
Signed-off-by: default avatarAdeodato Simo <dato@google.com>
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 14970c32
......@@ -1286,14 +1286,13 @@ def _VerifyCertificate(filename):
raise errors.ProgrammerError("Unhandled certificate error code %r" % errcode)
class LUClusterVerify(LogicalUnit):
"""Verifies the cluster status.
class _VerifyErrors(object):
"""Mix-in for cluster/group verify LUs.
"""
HPATH = "cluster-verify"
HTYPE = constants.HTYPE_CLUSTER
REQ_BGL = False
It provides _Error and _ErrorIf, and updates the self.bad boolean. (Expects
self.op and self._feedback_fn to be available.)
"""
TCLUSTER = "cluster"
TNODE = "node"
TINSTANCE = "instance"
......@@ -1330,6 +1329,53 @@ class LUClusterVerify(LogicalUnit):
ETYPE_ERROR = "ERROR"
ETYPE_WARNING = "WARNING"
def _Error(self, ecode, item, msg, *args, **kwargs):
"""Format an error message.
Based on the opcode's error_codes parameter, either format a
parseable error code, or a simpler error string.
This must be called only from Exec and functions called from Exec.
"""
ltype = kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR)
itype, etxt = ecode
# first complete the msg
if args:
msg = msg % args
# then format the whole message
if self.op.error_codes: # This is a mix-in. pylint: disable-msg=E1101
msg = "%s:%s:%s:%s:%s" % (ltype, etxt, itype, item, msg)
else:
if item:
item = " " + item
else:
item = ""
msg = "%s: %s%s: %s" % (ltype, itype, item, msg)
# and finally report it via the feedback_fn
self._feedback_fn(" - %s" % msg) # Mix-in. pylint: disable-msg=E1101
def _ErrorIf(self, cond, *args, **kwargs):
"""Log an error message if the passed condition is True.
"""
cond = (bool(cond)
or self.op.debug_simulate_errors) # pylint: disable-msg=E1101
if cond:
self._Error(*args, **kwargs)
# do not mark the operation as failed for WARN cases only
if kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR) == self.ETYPE_ERROR:
self.bad = self.bad or cond
class LUClusterVerify(LogicalUnit, _VerifyErrors):
"""Verifies the cluster status.
"""
HPATH = "cluster-verify"
HTYPE = constants.HTYPE_CLUSTER
REQ_BGL = False
_HOOKS_INDENT_RE = re.compile("^", re.M)
class NodeImage(object):
......@@ -1397,43 +1443,6 @@ class LUClusterVerify(LogicalUnit):
self.my_inst_names = utils.NiceSort(list(self.all_inst_info))
self.my_inst_info = self.all_inst_info
def _Error(self, ecode, item, msg, *args, **kwargs):
"""Format an error message.
Based on the opcode's error_codes parameter, either format a
parseable error code, or a simpler error string.
This must be called only from Exec and functions called from Exec.
"""
ltype = kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR)
itype, etxt = ecode
# first complete the msg
if args:
msg = msg % args
# then format the whole message
if self.op.error_codes:
msg = "%s:%s:%s:%s:%s" % (ltype, etxt, itype, item, msg)
else:
if item:
item = " " + item
else:
item = ""
msg = "%s: %s%s: %s" % (ltype, itype, item, msg)
# and finally report it via the feedback_fn
self._feedback_fn(" - %s" % msg)
def _ErrorIf(self, cond, *args, **kwargs):
"""Log an error message if the passed condition is True.
"""
cond = bool(cond) or self.op.debug_simulate_errors
if cond:
self._Error(*args, **kwargs)
# do not mark the operation as failed for WARN cases only
if kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR) == self.ETYPE_ERROR:
self.bad = self.bad or cond
def _VerifyNode(self, ninfo, nresult):
"""Perform some basic validation on data returned from a node.
......
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