Commit 5fa3d337 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Improve opcode result check test to have a whitelist



Only whitelisted opcodes may not have a result check.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 82c54b5b
......@@ -35,6 +35,32 @@ from ganeti import compat
import testutils
#: Unless an opcode is included in the following list it must have a result
#: check of some sort
MISSING_RESULT_CHECK = frozenset([
opcodes.OpBackupExport,
opcodes.OpBackupQuery,
opcodes.OpBackupRemove,
opcodes.OpClusterQuery,
opcodes.OpGroupQuery,
opcodes.OpInstanceQuery,
opcodes.OpInstanceQueryData,
opcodes.OpNodeQuery,
opcodes.OpNodeQueryStorage,
opcodes.OpOsDiagnose,
opcodes.OpQuery,
opcodes.OpQueryFields,
opcodes.OpTagsDel,
opcodes.OpTagsGet,
opcodes.OpTagsSearch,
opcodes.OpTagsSet,
opcodes.OpTestAllocator,
opcodes.OpTestDelay,
opcodes.OpTestDummy,
opcodes.OpTestJqueue,
])
class TestOpcodes(unittest.TestCase):
def test(self):
self.assertRaises(ValueError, opcodes.OpCode.LoadOpCode, None)
......@@ -49,7 +75,13 @@ class TestOpcodes(unittest.TestCase):
self.assertEqual(cls.OP_ID, opcodes._NameToId(cls.__name__))
self.assertFalse(compat.any(cls.OP_ID.startswith(prefix)
for prefix in opcodes._SUMMARY_PREFIX.keys()))
self.assertTrue(cls.OP_RESULT is None or callable(cls.OP_RESULT))
if cls in MISSING_RESULT_CHECK:
self.assertTrue(cls.OP_RESULT is None,
msg=("%s is listed to not have a result check" %
cls.OP_ID))
else:
self.assertTrue(callable(cls.OP_RESULT),
msg=("%s should have a result check" % cls.OP_ID))
self.assertRaises(TypeError, cls, unsupported_parameter="some value")
......
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