Revision cfa79a23 test/ganeti.cmdlib_unittest.py

b/test/ganeti.cmdlib_unittest.py
1501 1501
    self.assertNotEqual(id(names), id(output), msg="List was not copied")
1502 1502

  
1503 1503

  
1504
class TestCheckOpportunisticLocking(unittest.TestCase):
1505
  class OpTest(opcodes.OpCode):
1506
    OP_PARAMS = [
1507
      opcodes._POpportunisticLocking,
1508
      opcodes._PIAllocFromDesc(""),
1509
      ]
1510

  
1511
  @classmethod
1512
  def _MakeOp(cls, **kwargs):
1513
    op = cls.OpTest(**kwargs)
1514
    op.Validate(True)
1515
    return op
1516

  
1517
  def testMissingAttributes(self):
1518
    self.assertRaises(AttributeError, cmdlib._CheckOpportunisticLocking,
1519
                      object())
1520

  
1521
  def testDefaults(self):
1522
    op = self._MakeOp()
1523
    cmdlib._CheckOpportunisticLocking(op)
1524

  
1525
  def test(self):
1526
    for iallocator in [None, "something", "other"]:
1527
      for opplock in [False, True]:
1528
        op = self._MakeOp(iallocator=iallocator, opportunistic_locking=opplock)
1529
        if opplock and not iallocator:
1530
          self.assertRaises(errors.OpPrereqError,
1531
                            cmdlib._CheckOpportunisticLocking, op)
1532
        else:
1533
          cmdlib._CheckOpportunisticLocking(op)
1534

  
1535

  
1504 1536
if __name__ == "__main__":
1505 1537
  testutils.GanetiTestProgram()

Also available in: Unified diff