• Iustin Pop's avatar
    Add an error-simulation mode to cluster verify · a0c9776a
    Iustin Pop authored
    
    
    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>
    a0c9776a
cli.py 36.3 KB