Revision 553cb5f7 test/ganeti.cmdlib_unittest.py

b/test/ganeti.cmdlib_unittest.py
645 645
  def test(self):
646 646
    compute_fn = _ValidateComputeMinMaxSpec
647 647
    ret = cmdlib._ComputeIPolicySpecViolation(NotImplemented, 1024, 1, 1, 1,
648
                                              [1024], _compute_fn=compute_fn)
648
                                              [1024], 1, _compute_fn=compute_fn)
649 649
    self.assertEqual(ret, [])
650 650

  
651 651
  def testInvalidArguments(self):
652 652
    self.assertRaises(AssertionError, cmdlib._ComputeIPolicySpecViolation,
653
                      NotImplemented, 1024, 1, 1, 1, [])
653
                      NotImplemented, 1024, 1, 1, 1, [], 1)
654 654

  
655 655
  def testInvalidSpec(self):
656
    spec = _SpecWrapper([None, False, "foo", None, "bar"])
656
    spec = _SpecWrapper([None, False, "foo", None, "bar", None])
657 657
    compute_fn = spec.ComputeMinMaxSpec
658 658
    ret = cmdlib._ComputeIPolicySpecViolation(NotImplemented, 1024, 1, 1, 1,
659
                                              [1024], _compute_fn=compute_fn)
659
                                              [1024], 1, _compute_fn=compute_fn)
660 660
    self.assertEqual(ret, ["foo", "bar"])
661 661
    self.assertFalse(spec.spec)
662 662

  
663 663

  
664 664
class _StubComputeIPolicySpecViolation:
665
  def __init__(self, mem_size, cpu_count, disk_count, nic_count, disk_sizes):
665
  def __init__(self, mem_size, cpu_count, disk_count, nic_count, disk_sizes,
666
               spindle_use):
666 667
    self.mem_size = mem_size
667 668
    self.cpu_count = cpu_count
668 669
    self.disk_count = disk_count
669 670
    self.nic_count = nic_count
670 671
    self.disk_sizes = disk_sizes
672
    self.spindle_use = spindle_use
671 673

  
672
  def __call__(self, _, mem_size, cpu_count, disk_count, nic_count, disk_sizes):
674
  def __call__(self, _, mem_size, cpu_count, disk_count, nic_count, disk_sizes,
675
               spindle_use):
673 676
    assert self.mem_size == mem_size
674 677
    assert self.cpu_count == cpu_count
675 678
    assert self.disk_count == disk_count
676 679
    assert self.nic_count == nic_count
677 680
    assert self.disk_sizes == disk_sizes
681
    assert self.spindle_use == spindle_use
678 682

  
679 683
    return []
680 684

  
......
684 688
    beparams = {
685 689
      constants.BE_MAXMEM: 2048,
686 690
      constants.BE_VCPUS: 2,
691
      constants.BE_SPINDLE_USAGE: 4,
687 692
      }
688 693
    disks = [objects.Disk(size=512)]
689 694
    instance = objects.Instance(beparams=beparams, disks=disks, nics=[])
690
    stub = _StubComputeIPolicySpecViolation(2048, 2, 1, 0, [512])
695
    stub = _StubComputeIPolicySpecViolation(2048, 2, 1, 0, [512], 4)
691 696
    ret = cmdlib._ComputeIPolicyInstanceViolation(NotImplemented, instance,
692 697
                                                  _compute_fn=stub)
693 698
    self.assertEqual(ret, [])
......
701 706
      constants.ISPEC_DISK_COUNT: 1,
702 707
      constants.ISPEC_DISK_SIZE: [512],
703 708
      constants.ISPEC_NIC_COUNT: 0,
709
      constants.ISPEC_SPINDLE_USE: 1,
704 710
      }
705
    stub = _StubComputeIPolicySpecViolation(2048, 2, 1, 0, [512])
711
    stub = _StubComputeIPolicySpecViolation(2048, 2, 1, 0, [512], 1)
706 712
    ret = cmdlib._ComputeIPolicyInstanceSpecViolation(NotImplemented, ispec,
707 713
                                                      _compute_fn=stub)
708 714
    self.assertEqual(ret, [])

Also available in: Unified diff