Improve opcode result check test to have a whitelist
authorMichael Hanselmann <hansmi@google.com>
Mon, 20 Feb 2012 12:29:38 +0000 (13:29 +0100)
committerMichael Hanselmann <hansmi@google.com>
Mon, 20 Feb 2012 12:57:37 +0000 (13:57 +0100)
Only whitelisted opcodes may not have a result check.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: RenĂ© Nussbaumer <rn@google.com>

test/ganeti.opcodes_unittest.py

index 7e46873..099800f 100755 (executable)
@@ -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")