Revision 4a8c84f3

b/test/py/cmdlib/instance_unittest.py
1622 1622
    self.ExecOpCode(op)
1623 1623

  
1624 1624

  
1625
class TestLUInstanceMultiAlloc(CmdlibTestCase):
1626
  def setUp(self):
1627
    super(TestLUInstanceMultiAlloc, self).setUp()
1628

  
1629
    self.inst_op = opcodes.OpInstanceCreate(instance_name="inst.example.com",
1630
                                            disk_template=constants.DT_DRBD8,
1631
                                            disks=[],
1632
                                            nics=[],
1633
                                            os_type="mock_os",
1634
                                            hypervisor=constants.HT_XEN_HVM,
1635
                                            mode=constants.INSTANCE_CREATE)
1636

  
1637
  def testInstanceWithIAllocator(self):
1638
    inst = self.CopyOpCode(self.inst_op,
1639
                           iallocator="mock")
1640
    op = opcodes.OpInstanceMultiAlloc(instances=[inst])
1641
    self.ExecOpCodeExpectOpPrereqError(
1642
      op, "iallocator are not allowed to be set on instance objects")
1643

  
1644
  def testOnlySomeNodesGiven(self):
1645
    inst1 = self.CopyOpCode(self.inst_op,
1646
                            pnode=self.master.name)
1647
    inst2 = self.CopyOpCode(self.inst_op)
1648
    op = opcodes.OpInstanceMultiAlloc(instances=[inst1, inst2])
1649
    self.ExecOpCodeExpectOpPrereqError(
1650
      op, "There are instance objects providing pnode/snode while others"
1651
          " do not")
1652

  
1653
  def testMissingIAllocator(self):
1654
    self.cluster.default_iallocator = None
1655
    inst = self.CopyOpCode(self.inst_op)
1656
    op = opcodes.OpInstanceMultiAlloc(instances=[inst])
1657
    self.ExecOpCodeExpectOpPrereqError(
1658
      op, "No iallocator or nodes on the instances given and no cluster-wide"
1659
          " default iallocator found")
1660

  
1661
  def testDuplicateInstanceNames(self):
1662
    inst1 = self.CopyOpCode(self.inst_op)
1663
    inst2 = self.CopyOpCode(self.inst_op)
1664
    op = opcodes.OpInstanceMultiAlloc(instances=[inst1, inst2])
1665
    self.ExecOpCodeExpectOpPrereqError(
1666
      op, "There are duplicate instance names")
1667

  
1668
  def testWithGivenNodes(self):
1669
    snode = self.cfg.AddNewNode()
1670
    inst = self.CopyOpCode(self.inst_op,
1671
                           pnode=self.master.name,
1672
                           snode=snode.name)
1673
    op = opcodes.OpInstanceMultiAlloc(instances=[inst])
1674
    self.ExecOpCode(op)
1675

  
1676
  def testDryRun(self):
1677
    snode = self.cfg.AddNewNode()
1678
    inst = self.CopyOpCode(self.inst_op,
1679
                           pnode=self.master.name,
1680
                           snode=snode.name)
1681
    op = opcodes.OpInstanceMultiAlloc(instances=[inst],
1682
                                      dry_run=True)
1683
    self.ExecOpCode(op)
1684

  
1685
  def testWithIAllocator(self):
1686
    snode = self.cfg.AddNewNode()
1687
    self.iallocator_cls.return_value.result = \
1688
      ([("inst.example.com", [self.master.name, snode.name])], [])
1689

  
1690
    inst = self.CopyOpCode(self.inst_op)
1691
    op = opcodes.OpInstanceMultiAlloc(instances=[inst],
1692
                                      iallocator="mock_ialloc")
1693
    self.ExecOpCode(op)
1694

  
1695
  def testWithIAllocatorOpportunisticLocking(self):
1696
    snode = self.cfg.AddNewNode()
1697
    self.iallocator_cls.return_value.result = \
1698
      ([("inst.example.com", [self.master.name, snode.name])], [])
1699

  
1700
    inst = self.CopyOpCode(self.inst_op)
1701
    op = opcodes.OpInstanceMultiAlloc(instances=[inst],
1702
                                      iallocator="mock_ialloc",
1703
                                      opportunistic_locking=True)
1704
    self.ExecOpCode(op)
1705

  
1706
  def testFailingIAllocator(self):
1707
    self.iallocator_cls.return_value.success = False
1708

  
1709
    inst = self.CopyOpCode(self.inst_op)
1710
    op = opcodes.OpInstanceMultiAlloc(instances=[inst],
1711
                                      iallocator="mock_ialloc")
1712
    self.ExecOpCodeExpectOpPrereqError(
1713
      op, "Can't compute nodes using iallocator")
1714

  
1715

  
1625 1716
if __name__ == "__main__":
1626 1717
  testutils.GanetiTestProgram()

Also available in: Unified diff