From 83a2da0f417fb0a6a57ef7ef98c50951d40c8dcd Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Tue, 17 May 2011 18:12:27 +0200
Subject: [PATCH] Improve hooks documentation unittest

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 | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/test/docs_unittest.py b/test/docs_unittest.py
index 6959616e6..82e5a9d06 100755
--- a/test/docs_unittest.py
+++ b/test/docs_unittest.py
@@ -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),
-- 
GitLab