locking: Change locking order, move NAL after instances
[ganeti-local] / test / ganeti.opcodes_unittest.py
index a31503e..a5e36d2 100755 (executable)
@@ -38,19 +38,6 @@ import testutils
 #: Unless an opcode is included in the following list it must have a result
 #: check of some sort
 MISSING_RESULT_CHECK = frozenset([
 #: Unless an opcode is included in the following list it must have a result
 #: check of some sort
 MISSING_RESULT_CHECK = frozenset([
-  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.OpTestAllocator,
   opcodes.OpTestDelay,
   opcodes.OpTestDummy,
@@ -90,7 +77,7 @@ class TestOpcodes(unittest.TestCase):
         {"dry_run": False, "debug_level": 0, },
 
         # All variables
         {"dry_run": False, "debug_level": 0, },
 
         # All variables
-        dict([(name, False) for name in cls._all_slots()])
+        dict([(name, []) for name in cls.GetAllSlots()])
         ]
 
       for i in args:
         ]
 
       for i in args:
@@ -108,7 +95,7 @@ class TestOpcodes(unittest.TestCase):
         self._checkSummary(restored)
 
         for name in ["x_y_z", "hello_world"]:
         self._checkSummary(restored)
 
         for name in ["x_y_z", "hello_world"]:
-          assert name not in cls._all_slots()
+          assert name not in cls.GetAllSlots()
           for value in [None, True, False, [], "Hello World"]:
             self.assertRaises(AttributeError, setattr, op, name, value)
 
           for value in [None, True, False, [], "Hello World"]:
             self.assertRaises(AttributeError, setattr, op, name, value)
 
@@ -171,7 +158,7 @@ class TestOpcodes(unittest.TestCase):
     self.assertTrue(opcodes.OpCode not in opcodes.OP_MAPPING.values())
 
     for cls in opcodes.OP_MAPPING.values() + [opcodes.OpCode]:
     self.assertTrue(opcodes.OpCode not in opcodes.OP_MAPPING.values())
 
     for cls in opcodes.OP_MAPPING.values() + [opcodes.OpCode]:
-      all_slots = cls._all_slots()
+      all_slots = cls.GetAllSlots()
 
       self.assertEqual(len(set(all_slots) & supported_by_all), 3,
                        msg=("Opcode %s doesn't support all base"
 
       self.assertEqual(len(set(all_slots) & supported_by_all), 3,
                        msg=("Opcode %s doesn't support all base"
@@ -204,8 +191,16 @@ class TestOpcodes(unittest.TestCase):
         self.assertTrue(doc is None or isinstance(doc, basestring))
 
         if callable(aval):
         self.assertTrue(doc is None or isinstance(doc, basestring))
 
         if callable(aval):
-          self.assertFalse(callable(aval()),
+          default_value = aval()
+          self.assertFalse(callable(default_value),
                            msg="Default value returned by function is callable")
                            msg="Default value returned by function is callable")
+        else:
+          default_value = aval
+
+        if aval is not ht.NoDefault and test is not ht.NoType:
+          self.assertTrue(test(default_value),
+                          msg=("Default value of '%s.%s' does not verify" %
+                               (cls.OP_ID, attr_name)))
 
       # If any parameter has documentation, all others need to have it as well
       has_doc = [doc is not None for (_, _, _, doc) in cls.OP_PARAMS]
 
       # If any parameter has documentation, all others need to have it as well
       has_doc = [doc is not None for (_, _, _, doc) in cls.OP_PARAMS]
@@ -303,6 +298,20 @@ class TestOpcodes(unittest.TestCase):
     self.assertEqual(op.debug_level, 123)
 
 
     self.assertEqual(op.debug_level, 123)
 
 
+  def testOpInstanceMultiAlloc(self):
+    inst = dict([(name, []) for name in opcodes.OpInstanceCreate.GetAllSlots()])
+    inst_op = opcodes.OpInstanceCreate(**inst)
+    inst_state = inst_op.__getstate__()
+
+    multialloc = opcodes.OpInstanceMultiAlloc(instances=[inst_op])
+    state = multialloc.__getstate__()
+    self.assertEquals(state["instances"], [inst_state])
+    loaded_multialloc = opcodes.OpCode.LoadOpCode(state)
+    (loaded_inst,) = loaded_multialloc.instances
+    self.assertNotEquals(loaded_inst, inst_op)
+    self.assertEquals(loaded_inst.__getstate__(), inst_state)
+
+
 class TestOpcodeDepends(unittest.TestCase):
   def test(self):
     check_relative = opcodes._BuildJobDepCheck(True)
 class TestOpcodeDepends(unittest.TestCase):
   def test(self):
     check_relative = opcodes._BuildJobDepCheck(True)