Revision 83a2da0f

b/test/docs_unittest.py
29 29
from ganeti import cmdlib
30 30
from ganeti import build
31 31
from ganeti import compat
32
from ganeti import mcpu
32 33
from ganeti.rapi import connector
33 34

  
34 35
import testutils
......
51 52
    """
52 53
    hooksdoc = self._ReadDocFile("hooks.rst")
53 54

  
55
    # Reverse mapping from LU to opcode
56
    lu2opcode = dict((lu, op)
57
                     for (op, lu) in mcpu.Processor.DISPATCH_TABLE.items())
58
    assert len(lu2opcode) == len(mcpu.Processor.DISPATCH_TABLE), \
59
      "Found duplicate entries"
60

  
54 61
    for name in dir(cmdlib):
55 62
      obj = getattr(cmdlib, name)
56 63

  
57 64
      if (isinstance(obj, type) and
58 65
          issubclass(obj, cmdlib.LogicalUnit) and
59 66
          hasattr(obj, "HPATH")):
60
        self._CheckHook(name, obj, hooksdoc)
67
        self._CheckHook(name, obj, hooksdoc, lu2opcode)
68

  
69
  def _CheckHook(self, name, lucls, hooksdoc, lu2opcode):
70
    opcls = lu2opcode.get(lucls, None)
61 71

  
62
  def _CheckHook(self, name, lucls, hooksdoc):
63 72
    if lucls.HTYPE is None:
64 73
      return
65 74

  
66 75
    # TODO: Improve this test (e.g. find hooks documented but no longer
67 76
    # existing)
68 77

  
78
    if opcls:
79
      self.assertTrue(re.findall("^%s$" % re.escape(opcls.OP_ID),
80
                                 hooksdoc, re.M),
81
                      msg=("Missing hook documentation for %s" %
82
                           (opcls.OP_ID)))
83

  
69 84
    pattern = r"^:directory:\s*%s\s*$" % re.escape(lucls.HPATH)
70 85

  
71 86
    self.assert_(re.findall(pattern, hooksdoc, re.M),

Also available in: Unified diff