diff --git a/test/ganeti.cmdlib_unittest.py b/test/ganeti.cmdlib_unittest.py
index 0606f8d0cb77b4272be099c37b25e4a21231bf9f..067eba31b78a9ef0023507338cd95951cf280605 100755
--- a/test/ganeti.cmdlib_unittest.py
+++ b/test/ganeti.cmdlib_unittest.py
@@ -35,6 +35,7 @@ from ganeti import errors
 from ganeti import utils
 
 import testutils
+import mocks
 
 
 class TestCertVerification(testutils.GanetiTestCase):
@@ -94,5 +95,57 @@ class TestOpcodeParams(testutils.GanetiTestCase):
                   (lu_name, utils.CommaJoin(extra)))
 
 
+class TestIAllocatorChecks(testutils.GanetiTestCase):
+  def testFunction(self):
+    class TestLU(object):
+      def __init__(self, opcode):
+        self.cfg = mocks.FakeConfig()
+        self.op = opcode
+
+    class TestOpcode(opcodes.OpCode):
+      OP_ID = "OP_TEST"
+      __slots__ = ["iallocator", "node"]
+
+    default_iallocator = mocks.FakeConfig().GetDefaultIAllocator()
+    other_iallocator = default_iallocator + "_not"
+
+    op = TestOpcode()
+    lu = TestLU(op)
+
+    c_i = lambda: cmdlib._CheckIAllocatorOrNode(lu, "iallocator", "node")
+
+    # Neither node nor iallocator given
+    op.iallocator = None
+    op.node = None
+    c_i()
+    self.assertEqual(lu.op.iallocator, default_iallocator)
+    self.assertEqual(lu.op.node, None)
+
+    # Both, iallocator and node given
+    op.iallocator = "test"
+    op.node = "test"
+    self.assertRaises(errors.OpPrereqError, c_i)
+
+    # Only iallocator given
+    op.iallocator = other_iallocator
+    op.node = None
+    c_i()
+    self.assertEqual(lu.op.iallocator, other_iallocator)
+    self.assertEqual(lu.op.node, None)
+
+    # Only node given
+    op.iallocator = None
+    op.node = "node"
+    c_i()
+    self.assertEqual(lu.op.iallocator, None)
+    self.assertEqual(lu.op.node, "node")
+
+    # No node, iallocator or default iallocator
+    op.iallocator = None
+    op.node = None
+    lu.cfg.GetDefaultIAllocator = lambda: None
+    self.assertRaises(errors.OpPrereqError, c_i)
+
+
 if __name__ == "__main__":
   testutils.GanetiTestProgram()
diff --git a/test/mocks.py b/test/mocks.py
index 4c0ae072c0a9c007b08c345452ad9fdc0956921c..5729ac646b8c8462695130a1f74df7e79a210e50 100644
--- a/test/mocks.py
+++ b/test/mocks.py
@@ -51,6 +51,9 @@ class FakeConfig:
     def GetMasterNode(self):
         return utils.HostInfo().name
 
+    def GetDefaultIAllocator(Self):
+        return "testallocator"
+
 
 class FakeProc:
     """Fake processor object"""