Commit 2fd213a6 authored by René Nussbaumer's avatar René Nussbaumer
Browse files

Update the hooks documentation



Also provide some extended unittests to catch those cases.
Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent a8dbf746
...@@ -148,16 +148,6 @@ Changes a node's parameters. ...@@ -148,16 +148,6 @@ Changes a node's parameters.
:pre-execution: master node, the target node :pre-execution: master node, the target node
:post-execution: master node, the target node :post-execution: master node, the target node
OP_NODE_EVACUATE
++++++++++++++++
Relocate secondary instances from a node.
:directory: node-evacuate
:env. vars: NEW_SECONDARY, NODE_NAME
:pre-execution: master node, target node
:post-execution: master node, target node
OP_NODE_MIGRATE OP_NODE_MIGRATE
++++++++++++++++ ++++++++++++++++
...@@ -344,16 +334,6 @@ Remove an instance. ...@@ -344,16 +334,6 @@ Remove an instance.
:pre-execution: master node :pre-execution: master node
:post-execution: master node, primary and secondary nodes :post-execution: master node, primary and secondary nodes
OP_INSTANCE_REPLACE_DISKS
+++++++++++++++++++++++++
Replace an instance's disks.
:directory: mirror-replace
:env. vars: MODE, NEW_SECONDARY, OLD_SECONDARY
:pre-execution: master node, primary and secondary nodes
:post-execution: master node, primary and secondary nodes
OP_INSTANCE_GROW_DISK OP_INSTANCE_GROW_DISK
+++++++++++++++++++++ +++++++++++++++++++++
......
...@@ -86,6 +86,11 @@ def _ReadDocFile(filename): ...@@ -86,6 +86,11 @@ def _ReadDocFile(filename):
class TestHooksDocs(unittest.TestCase): class TestHooksDocs(unittest.TestCase):
HOOK_PATH_OK = frozenset([
"master-ip-turnup",
"master-ip-turndown",
])
def test(self): def test(self):
"""Check whether all hooks are documented. """Check whether all hooks are documented.
...@@ -98,34 +103,62 @@ class TestHooksDocs(unittest.TestCase): ...@@ -98,34 +103,62 @@ class TestHooksDocs(unittest.TestCase):
assert len(lu2opcode) == len(mcpu.Processor.DISPATCH_TABLE), \ assert len(lu2opcode) == len(mcpu.Processor.DISPATCH_TABLE), \
"Found duplicate entries" "Found duplicate entries"
for name in dir(cmdlib): hooks_paths = frozenset(re.findall("^:directory:\s*(.+)\s*$", hooksdoc,
obj = getattr(cmdlib, name) re.M))
self.assertTrue(self.HOOK_PATH_OK.issubset(hooks_paths),
if (isinstance(obj, type) and msg="Whitelisted path not found in documentation")
issubclass(obj, cmdlib.LogicalUnit) and
hasattr(obj, "HPATH")): raw_hooks_ops = re.findall("^OP_(?!CODE$).+$", hooksdoc, re.M)
self._CheckHook(name, obj, hooksdoc, lu2opcode) hooks_ops = set()
duplicate_ops = set()
def _CheckHook(self, name, lucls, hooksdoc, lu2opcode): for op in raw_hooks_ops:
opcls = lu2opcode.get(lucls, None) if op in hooks_ops:
duplicate_ops.add(op)
if lucls.HTYPE is None: else:
return hooks_ops.add(op)
# TODO: Improve this test (e.g. find hooks documented but no longer self.assertFalse(duplicate_ops,
# existing) msg="Found duplicate opcode documentation: %s" %
utils.CommaJoin(duplicate_ops))
if opcls: seen_paths = set()
self.assertTrue(re.findall("^%s$" % re.escape(opcls.OP_ID), seen_ops = set()
hooksdoc, re.M),
msg=("Missing hook documentation for %s" %
(opcls.OP_ID)))
pattern = r"^:directory:\s*%s\s*$" % re.escape(lucls.HPATH) self.assertFalse(duplicate_ops,
msg="Found duplicated hook documentation: %s" %
utils.CommaJoin(duplicate_ops))
self.assert_(re.findall(pattern, hooksdoc, re.M), for name in dir(cmdlib):
msg=("Missing documentation for hook %s/%s" % lucls = getattr(cmdlib, name)
(lucls.HTYPE, lucls.HPATH)))
if (isinstance(lucls, type) and
issubclass(lucls, cmdlib.LogicalUnit) and
hasattr(lucls, "HPATH")):
if lucls.HTYPE is None:
continue
opcls = lu2opcode.get(lucls, None)
if opcls:
seen_ops.add(opcls.OP_ID)
self.assertTrue(opcls.OP_ID in hooks_ops,
msg="Missing hook documentation for %s" %
opcls.OP_ID)
self.assertTrue(lucls.HPATH in hooks_paths,
msg="Missing documentation for hook %s/%s" %
(lucls.HTYPE, lucls.HPATH))
seen_paths.add(lucls.HPATH)
missed_ops = hooks_ops - seen_ops
missed_paths = hooks_paths - seen_paths - self.HOOK_PATH_OK
self.assertFalse(missed_ops,
msg="Op documents hook not existing anymore: %s" %
utils.CommaJoin(missed_ops))
self.assertFalse(missed_paths,
msg="Hook path does not exist in opcode: %s" %
utils.CommaJoin(missed_paths))
class TestRapiDocs(unittest.TestCase): class TestRapiDocs(unittest.TestCase):
......
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