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 <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 56372573
...@@ -29,6 +29,7 @@ from ganeti import utils ...@@ -29,6 +29,7 @@ from ganeti import utils
from ganeti import cmdlib from ganeti import cmdlib
from ganeti import build from ganeti import build
from ganeti import compat from ganeti import compat
from ganeti import mcpu
from ganeti.rapi import connector from ganeti.rapi import connector
import testutils import testutils
...@@ -51,21 +52,35 @@ class TestDocs(unittest.TestCase): ...@@ -51,21 +52,35 @@ class TestDocs(unittest.TestCase):
""" """
hooksdoc = self._ReadDocFile("hooks.rst") 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): for name in dir(cmdlib):
obj = getattr(cmdlib, name) obj = getattr(cmdlib, name)
if (isinstance(obj, type) and if (isinstance(obj, type) and
issubclass(obj, cmdlib.LogicalUnit) and issubclass(obj, cmdlib.LogicalUnit) and
hasattr(obj, "HPATH")): 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: if lucls.HTYPE is None:
return return
# TODO: Improve this test (e.g. find hooks documented but no longer # TODO: Improve this test (e.g. find hooks documented but no longer
# existing) # 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) pattern = r"^:directory:\s*%s\s*$" % re.escape(lucls.HPATH)
self.assert_(re.findall(pattern, hooksdoc, re.M), 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