Commit a0c9776a authored by Iustin Pop's avatar Iustin Pop
Browse files

Add an error-simulation mode to cluster verify



One of the issues we have in ganeti is that it's very hard to test the
error-handling paths; QA and burnin only test the OK code-path, since
it's hard to simulate errors.

LUVerifyCluster is special amongst the LUs in the fact that a) it has a
lot of error paths and b) the error paths only log the error, they don't
do any rollback or other similar actions. Thus, it's enough for this LU
to separate the testing of the error condition from the logging of the
error condition.

This patch does this by replacing code blocks of the form:

  if x:
    log_error()
    [y]

into:

  log_error_if(x)
  [if x:
    y
  ]

After this change, it's simple enough to turn on logging of all errors
by adding a special case inside log_error_if such that if the incoming
opcode has a special ‘debug_simulate_errors’ attribute and it's true, it
will log unconditionally the error.

Surprisingly this also turns into an absolute code reduction, since some
of the if blocks were simplified. The only downside to this patch is
that the various _VerifyX() functions are now stateful (modifying an
attribute on the LU instance) instead of returning a boolean result.

Last note: yes, this discovered some error cases in the logging.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 7c874ee1
...@@ -46,6 +46,7 @@ __all__ = [ ...@@ -46,6 +46,7 @@ __all__ = [
# Command line options # Command line options
"CONFIRM_OPT", "CONFIRM_OPT",
"DEBUG_OPT", "DEBUG_OPT",
"DEBUG_SIMERR_OPT",
"FIELDS_OPT", "FIELDS_OPT",
"FORCE_OPT", "FORCE_OPT",
"NOHDR_OPT", "NOHDR_OPT",
...@@ -464,6 +465,11 @@ VERBOSE_OPT = cli_option("-v", "--verbose", default=False, ...@@ -464,6 +465,11 @@ VERBOSE_OPT = cli_option("-v", "--verbose", default=False,
action="store_true", action="store_true",
help="Increase the verbosity of the operation") help="Increase the verbosity of the operation")
DEBUG_SIMERR_OPT = cli_option("--debug-simulate-errors", default=False,
action="store_true", dest="simulate_errors",
help="Debugging option that makes the operation"
" treat most runtime checks as failed")
def _ParseArgs(argv, commands, aliases): def _ParseArgs(argv, commands, aliases):
"""Parser for the command line arguments. """Parser for the command line arguments.
......
This diff is collapsed.
...@@ -209,7 +209,8 @@ class OpVerifyCluster(OpCode): ...@@ -209,7 +209,8 @@ class OpVerifyCluster(OpCode):
""" """
OP_ID = "OP_CLUSTER_VERIFY" OP_ID = "OP_CLUSTER_VERIFY"
__slots__ = OpCode.__slots__ + ["skip_checks", "verbose", "error_codes"] __slots__ = OpCode.__slots__ + ["skip_checks", "verbose", "error_codes",
"debug_simulate_errors"]
class OpVerifyDisks(OpCode): class OpVerifyDisks(OpCode):
......
...@@ -340,7 +340,8 @@ def VerifyCluster(opts, args): ...@@ -340,7 +340,8 @@ def VerifyCluster(opts, args):
skip_checks.append(constants.VERIFY_NPLUSONE_MEM) skip_checks.append(constants.VERIFY_NPLUSONE_MEM)
op = opcodes.OpVerifyCluster(skip_checks=skip_checks, op = opcodes.OpVerifyCluster(skip_checks=skip_checks,
verbose=opts.verbose, verbose=opts.verbose,
error_codes=opts.error_codes) error_codes=opts.error_codes,
debug_simulate_errors=opts.simulate_errors)
if SubmitOpCode(op): if SubmitOpCode(op):
return 0 return 0
else: else:
...@@ -669,7 +670,7 @@ commands = { ...@@ -669,7 +670,7 @@ commands = {
"Forces a push of the configuration file and ssconf files" "Forces a push of the configuration file and ssconf files"
" to the nodes in the cluster"), " to the nodes in the cluster"),
'verify': (VerifyCluster, ARGS_NONE, 'verify': (VerifyCluster, ARGS_NONE,
[DEBUG_OPT, VERBOSE_OPT, [DEBUG_OPT, VERBOSE_OPT, DEBUG_SIMERR_OPT,
cli_option("--error-codes", dest="error_codes", cli_option("--error-codes", dest="error_codes",
help="Enable parseable error messages", help="Enable parseable error messages",
action="store_true", default=False), action="store_true", default=False),
......
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