Revision 75bf3149 lib/backend.py

b/lib/backend.py
726 726
  return res
727 727

  
728 728

  
729
def _VerifyHypervisors(what, vm_capable, result, all_hvparams,
730
                       get_hv_fn=hypervisor.GetHypervisor):
731
  """Verifies the hypervisor. Appends the results to the 'results' list.
732

  
733
  @type what: C{dict}
734
  @param what: a dictionary of things to check
735
  @type vm_capable: boolean
736
  @param vm_capable: whether or not this not is vm capable
737
  @type result: dict
738
  @param result: dictionary of verification results; results of the
739
    verifications in this function will be added here
740
  @type all_hvparams: dict of dict of string
741
  @param all_hvparams: dictionary mapping hypervisor names to hvparams
742
  @type get_hv_fn: function
743
  @param get_hv_fn: function to retrieve the hypervisor, to improve testability
744

  
745
  """
746
  if not vm_capable:
747
    return
748

  
749
  if constants.NV_HYPERVISOR in what:
750
    result[constants.NV_HYPERVISOR] = {}
751
    for hv_name in what[constants.NV_HYPERVISOR]:
752
      hvparams = all_hvparams[hv_name]
753
      try:
754
        val = get_hv_fn(hv_name).Verify(hvparams=hvparams)
755
      except errors.HypervisorError, err:
756
        val = "Error while checking hypervisor: %s" % str(err)
757
      result[constants.NV_HYPERVISOR][hv_name] = val
758

  
759

  
760
def _VerifyHvparams(what, vm_capable, result,
761
                    get_hv_fn=hypervisor.GetHypervisor):
762
  """Verifies the hvparams. Appends the results to the 'results' list.
763

  
764
  @type what: C{dict}
765
  @param what: a dictionary of things to check
766
  @type vm_capable: boolean
767
  @param vm_capable: whether or not this not is vm capable
768
  @type result: dict
769
  @param result: dictionary of verification results; results of the
770
    verifications in this function will be added here
771
  @type get_hv_fn: function
772
  @param get_hv_fn: function to retrieve the hypervisor, to improve testability
773

  
774
  """
775
  if not vm_capable:
776
    return
777

  
778
  if constants.NV_HVPARAMS in what:
779
    result[constants.NV_HVPARAMS] = []
780
    for source, hv_name, hvparms in what[constants.NV_HVPARAMS]:
781
      try:
782
        logging.info("Validating hv %s, %s", hv_name, hvparms)
783
        get_hv_fn(hv_name).ValidateParameters(hvparms)
784
      except errors.HypervisorError, err:
785
        result[constants.NV_HVPARAMS].append((source, hv_name, str(err)))
786

  
787

  
729 788
def VerifyNode(what, cluster_name):
730 789
  """Verify the status of the local node.
731 790

  
......
750 809
      - node-net-test: list of nodes we should check node daemon port
751 810
        connectivity with
752 811
      - hypervisor: list with hypervisors to run the verify for
812

  
753 813
  @rtype: dict
754 814
  @return: a dictionary with the same keys as the input dict, and
755 815
      values representing the result of the checks
......
760 820
  port = netutils.GetDaemonPort(constants.NODED)
761 821
  vm_capable = my_name not in what.get(constants.NV_VMNODES, [])
762 822

  
763
  if constants.NV_HYPERVISOR in what and vm_capable:
764
    result[constants.NV_HYPERVISOR] = tmp = {}
765
    for hv_name in what[constants.NV_HYPERVISOR]:
766
      try:
767
        val = hypervisor.GetHypervisor(hv_name).Verify()
768
      except errors.HypervisorError, err:
769
        val = "Error while checking hypervisor: %s" % str(err)
770
      tmp[hv_name] = val
771

  
772
  if constants.NV_HVPARAMS in what and vm_capable:
773
    result[constants.NV_HVPARAMS] = tmp = []
774
    for source, hv_name, hvparms in what[constants.NV_HVPARAMS]:
775
      try:
776
        logging.info("Validating hv %s, %s", hv_name, hvparms)
777
        hypervisor.GetHypervisor(hv_name).ValidateParameters(hvparms)
778
      except errors.HypervisorError, err:
779
        tmp.append((source, hv_name, str(err)))
823
  _VerifyHypervisors(what, vm_capable, result, all_hvparams)
824
  _VerifyHvparams(what, vm_capable, result)
780 825

  
781 826
  if constants.NV_FILELIST in what:
782 827
    fingerprints = utils.FingerprintFiles(map(vcluster.LocalizeVirtualPath,

Also available in: Unified diff