Revision 3c8a599a

b/lib/backend.py
594 594
                                 " received '%s'" % (num_params, len(params)))
595 595

  
596 596

  
597
def _CheckLvmStorageParams(params):
598
  """Performs sanity check for the 'exclusive storage' flag.
599

  
600
  @see: C{_CheckStorageParams}
601

  
602
  """
603
  _CheckStorageParams(params, 1)
604
  excl_stor = params[0]
605
  if not isinstance(params[0], bool):
606
    raise errors.ProgrammerError("Exclusive storage parameter is not"
607
                                 " boolean: '%s'." % excl_stor)
608
  return excl_stor
609

  
610

  
597 611
def _GetLvmVgSpaceInfo(name, params):
598 612
  """Wrapper around C{_GetVgInfo} which checks the storage parameters.
599 613

  
......
604 618
    containing only one for exclusive storage
605 619

  
606 620
  """
607
  _CheckStorageParams(params, 1)
608
  excl_stor = params[0]
609
  if not isinstance(params[0], bool):
610
    raise errors.ProgrammerError("Exclusive storage parameter is not"
611
                                 " boolean: '%s'." % excl_stor)
621
  excl_stor = _CheckLvmStorageParams(params)
612 622
  return _GetVgInfo(name, excl_stor)
613 623

  
614 624

  
......
633 643
    }
634 644

  
635 645

  
646
def _GetLvmPvSpaceInfo(name, params):
647
  """Wrapper around C{_GetVgSpindlesInfo} with sanity checks.
648

  
649
  @see C{_GetLvmVgSpaceInfo}
650

  
651
  """
652
  excl_stor = _CheckLvmStorageParams(params)
653
  return _GetVgSpindlesInfo(name, excl_stor)
654
 
655

  
636 656
def _GetVgSpindlesInfo(name, excl_stor):
637 657
  """Retrieves information about spindles in an LVM volume group.
638 658

  
......
752 772
  constants.ST_DISKLESS: None,
753 773
  constants.ST_EXT: None,
754 774
  constants.ST_FILE: _GetFileStorageSpaceInfo,
755
  constants.ST_LVM_PV: _GetVgSpindlesInfo,
775
  constants.ST_LVM_PV: _GetLvmPvSpaceInfo,
756 776
  constants.ST_LVM_VG: _GetLvmVgSpaceInfo,
757 777
  constants.ST_RADOS: None,
758 778
}
b/test/py/ganeti.backend_unittest.py
671 671
    self.assertRaises(errors.ProgrammerError, backend._GetLvmVgSpaceInfo,
672 672
                      path, excl_stor)
673 673

  
674
class TestGetLvmPvSpaceInfo(unittest.TestCase):
675

  
676
  def testValid(self):
677
    path = "somepath"
678
    excl_stor = True
679
    backend._GetVgSpindlesInfo = mock.Mock()
680
    backend._GetLvmPvSpaceInfo(path, [excl_stor])
681
    backend._GetVgSpindlesInfo.assert_called_with(path, excl_stor)
682

  
674 683

  
675 684
class TestCheckStorageParams(unittest.TestCase):
676 685

  

Also available in: Unified diff