Revision 587f8ff6 qa/qa_cluster.py

b/qa/qa_cluster.py
1 1
#
2 2
#
3 3

  
4
# Copyright (C) 2007, 2010, 2011, 2012 Google Inc.
4
# Copyright (C) 2007, 2010, 2011, 2012, 2013 Google Inc.
5 5
#
6 6
# This program is free software; you can redistribute it and/or modify
7 7
# it under the terms of the GNU General Public License as published by
......
23 23

  
24 24
"""
25 25

  
26
import re
26 27
import tempfile
27 28
import os.path
28 29

  
......
59 60
    AssertEqual(qa_utils.GetCommandOutput(node["primary"], cmd), content)
60 61

  
61 62

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

  
66

  
67
def _GetCVErrorCodes(cvout):
68
  ret = set()
69
  for l in cvout.splitlines():
70
    m = _CVERROR_RE.match(l)
71
    if m:
72
      ecode = m.group(1)
73
      ret.add(ecode)
74
  return ret
75

  
76

  
77
def AssertClusterVerify(fail=False, errors=None):
78
  """Run cluster-verify and check the result
79

  
80
  @type fail: bool
81
  @param fail: if cluster-verify is expected to fail instead of succeeding
82
  @type errors: list of tuples
83
  @param errors: List of CV_XXX errors that are expected; if specified, all the
84
      errors listed must appear in cluster-verify output. A non-empty value
85
      implies C{fail=True}.
86

  
87
  """
88
  cvcmd = "gnt-cluster verify"
89
  mnode = qa_config.GetMasterNode()
90
  if errors:
91
    cvout = GetCommandOutput(mnode["primary"], cvcmd + " --error-codes",
92
                             fail=True)
93
    actual = _GetCVErrorCodes(cvout)
94
    expected = compat.UniqueFrozenset(e for (_, e, _) in errors)
95
    if not actual.issuperset(expected):
96
      missing = expected.difference(actual)
97
      raise qa_error.Error("Cluster-verify didn't return these expected"
98
                           " errors: %s" % utils.CommaJoin(missing))
99
  else:
100
    AssertCommand(cvcmd, fail=fail, node=mnode)
101

  
102

  
62 103
# data for testing failures due to bad keys/values for disk parameters
63 104
_FAIL_PARAMS = ["nonexistent:resync-rate=1",
64 105
                "drbd:nonexistent=1",

Also available in: Unified diff