Revision ab4832d1 qa/qa_cluster.py

b/qa/qa_cluster.py
96 96

  
97 97

  
98 98
# Cluster-verify errors (date, "ERROR", then error code)
99
_CVERROR_RE = re.compile(r"^[\w\s:]+\s+- ERROR:([A-Z0-9_-]+):")
99
_CVERROR_RE = re.compile(r"^[\w\s:]+\s+- (ERROR|WARNING):([A-Z0-9_-]+):")
100 100

  
101 101

  
102 102
def _GetCVErrorCodes(cvout):
103
  ret = set()
103
  errs = set()
104
  warns = set()
104 105
  for l in cvout.splitlines():
105 106
    m = _CVERROR_RE.match(l)
106 107
    if m:
107
      ecode = m.group(1)
108
      ret.add(ecode)
109
  return ret
108
      etype = m.group(1)
109
      ecode = m.group(2)
110
      if etype == "ERROR":
111
        errs.add(ecode)
112
      elif etype == "WARNING":
113
        warns.add(ecode)
114
  return (errs, warns)
110 115

  
111 116

  
112
def AssertClusterVerify(fail=False, errors=None):
117
def _CheckVerifyErrors(actual, expected, etype):
118
  exp_codes = compat.UniqueFrozenset(e for (_, e, _) in expected)
119
  if not actual.issuperset(exp_codes):
120
    missing = exp_codes.difference(actual)
121
    raise qa_error.Error("Cluster-verify didn't return these expected"
122
                         " %ss: %s" % (etype, utils.CommaJoin(missing)))
123

  
124

  
125
def AssertClusterVerify(fail=False, errors=None, warnings=None):
113 126
  """Run cluster-verify and check the result
114 127

  
115 128
  @type fail: bool
......
118 131
  @param errors: List of CV_XXX errors that are expected; if specified, all the
119 132
      errors listed must appear in cluster-verify output. A non-empty value
120 133
      implies C{fail=True}.
134
  @type warnings: list of tuples
135
  @param warnings: Same as C{errors} but for warnings.
121 136

  
122 137
  """
123 138
  cvcmd = "gnt-cluster verify"
124 139
  mnode = qa_config.GetMasterNode()
125
  if errors:
140
  if errors or warnings:
126 141
    cvout = GetCommandOutput(mnode["primary"], cvcmd + " --error-codes",
127
                             fail=True)
128
    actual = _GetCVErrorCodes(cvout)
129
    expected = compat.UniqueFrozenset(e for (_, e, _) in errors)
130
    if not actual.issuperset(expected):
131
      missing = expected.difference(actual)
132
      raise qa_error.Error("Cluster-verify didn't return these expected"
133
                           " errors: %s" % utils.CommaJoin(missing))
142
                             fail=(fail or errors))
143
    (act_errs, act_warns) = _GetCVErrorCodes(cvout)
144
    if errors:
145
      _CheckVerifyErrors(act_errs, errors, "error")
146
    if warnings:
147
      _CheckVerifyErrors(act_warns, warnings, "warning")
134 148
  else:
135 149
    AssertCommand(cvcmd, fail=fail, node=mnode)
136 150

  

Also available in: Unified diff