Commit 83a2da0f authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Improve hooks documentation unittest

Also check for the opcode ID.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent 56372573
......@@ -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:
# 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" %
pattern = r"^:directory:\s*%s\s*$" % re.escape(lucls.HPATH)
self.assert_(re.findall(pattern, hooksdoc, re.M),
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment