Improve hooks documentation unittest
authorMichael Hanselmann <hansmi@google.com>
Tue, 17 May 2011 16:12:27 +0000 (18:12 +0200)
committerMichael Hanselmann <hansmi@google.com>
Fri, 20 May 2011 16:44:12 +0000 (18:44 +0200)
Also check for the opcode ID.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

test/docs_unittest.py

index 6959616..82e5a9d 100755 (executable)
@@ -29,6 +29,7 @@ from ganeti import utils
 from ganeti import cmdlib
 from ganeti import build
 from ganeti import compat
+from ganeti import mcpu
 from ganeti.rapi import connector
 
 import testutils
@@ -51,21 +52,35 @@ class TestDocs(unittest.TestCase):
     """
     hooksdoc = self._ReadDocFile("hooks.rst")
 
+    # Reverse mapping from LU to opcode
+    lu2opcode = dict((lu, op)
+                     for (op, lu) in mcpu.Processor.DISPATCH_TABLE.items())
+    assert len(lu2opcode) == len(mcpu.Processor.DISPATCH_TABLE), \
+      "Found duplicate entries"
+
     for name in dir(cmdlib):
       obj = getattr(cmdlib, name)
 
       if (isinstance(obj, type) and
           issubclass(obj, cmdlib.LogicalUnit) and
           hasattr(obj, "HPATH")):
-        self._CheckHook(name, obj, hooksdoc)
+        self._CheckHook(name, obj, hooksdoc, lu2opcode)
+
+  def _CheckHook(self, name, lucls, hooksdoc, lu2opcode):
+    opcls = lu2opcode.get(lucls, None)
 
-  def _CheckHook(self, name, lucls, hooksdoc):
     if lucls.HTYPE is None:
       return
 
     # TODO: Improve this test (e.g. find hooks documented but no longer
     # existing)
 
+    if opcls:
+      self.assertTrue(re.findall("^%s$" % re.escape(opcls.OP_ID),
+                                 hooksdoc, re.M),
+                      msg=("Missing hook documentation for %s" %
+                           (opcls.OP_ID)))
+
     pattern = r"^:directory:\s*%s\s*$" % re.escape(lucls.HPATH)
 
     self.assert_(re.findall(pattern, hooksdoc, re.M),