Revision 439e1d3f

b/lib/backend.py
616 616
    }
617 617

  
618 618

  
619
def _GetHvInfo(name):
619
def _GetHvInfo(name, hvparams, get_hv_fn=hypervisor.GetHypervisor):
620 620
  """Retrieves node information from a hypervisor.
621 621

  
622 622
  The information returned depends on the hypervisor. Common items:
......
628 628
    - memory_total is the total number of ram in MiB
629 629
    - hv_version: the hypervisor version, if available
630 630

  
631
  @type hvparams: dict of string
632
  @param hvparams: the hypervisor's hvparams
633

  
631 634
  """
632
  return hypervisor.GetHypervisor(name).GetNodeInfo()
635
  return get_hv_fn(name).GetNodeInfo(hvparams=hvparams)
636

  
637

  
638
def _GetHvInfoAll(hv_specs, get_hv_fn=hypervisor.GetHypervisor):
639
  """Retrieves node information for all hypervisors.
640

  
641
  See C{_GetHvInfo} for information on the output.
642

  
643
  @type hv_specs: list of pairs (string, dict of strings)
644
  @param hv_specs: list of pairs of a hypervisor's name and its hvparams
645

  
646
  """
647
  if hv_specs is None:
648
    return None
649

  
650
  # FIXME: remove this fallback once all calls to call_node_info are fixed
651
  if (len(hv_specs) > 0) and isinstance(hv_specs[0], str):
652
    result = []
653
    for hvname in hv_specs:
654
      result.append(_GetHvInfo(hvname, None, get_hv_fn))
655
    return result
656

  
657
  result = []
658
  for hvname, hvparams in hv_specs:
659
    result.append(_GetHvInfo(hvname, hvparams, get_hv_fn))
660
  return result
633 661

  
634 662

  
635 663
def _GetNamedNodeInfo(names, fn):
......
644 672
    return map(fn, names)
645 673

  
646 674

  
647
def GetNodeInfo(storage_units, hv_names, excl_stor):
675
def GetNodeInfo(storage_units, hv_specs, excl_stor):
648 676
  """Gives back a hash with different information about the node.
649 677

  
650 678
  @type storage_units: list of pairs (string, string)
651 679
  @param storage_units: List of pairs (storage unit, identifier) to ask for disk
652 680
                        space information. In case of lvm-vg, the identifier is
653 681
                        the VG name.
654
  @type hv_names: list of string
655
  @param hv_names: Names of the hypervisors to ask for node information
682
  @type hv_specs: list of pairs (string, dict of strings)
683
  @param hv_specs: list of pairs of a hypervisor's name and its hvparams
656 684
  @type excl_stor: boolean
657 685
  @param excl_stor: Whether exclusive_storage is active
658 686
  @rtype: tuple; (string, None/dict, None/dict)
......
666 694
    (lambda storage_unit: _ApplyStorageInfoFunction(storage_unit[0],
667 695
                                                    storage_unit[1],
668 696
                                                    excl_stor)))
669
  hv_info = _GetNamedNodeInfo(hv_names, _GetHvInfo)
670

  
697
  hv_info = _GetHvInfoAll(hv_specs)
671 698
  return (bootid, storage_info, hv_info)
672 699

  
673 700

  
b/test/py/ganeti.backend_unittest.py
593 593
    self._test_hv.ListInstances.assert_called_with(hvparams=fake_hvparams)
594 594

  
595 595

  
596
class TestGetHvInfo(unittest.TestCase):
597

  
598
  def setUp(self):
599
    self._test_hv = self._TestHypervisor()
600
    self._test_hv.GetNodeInfo = mock.Mock()
601

  
602
  class _TestHypervisor(hypervisor.hv_base.BaseHypervisor):
603
    def __init__(self):
604
      hypervisor.hv_base.BaseHypervisor.__init__(self)
605

  
606
  def _GetHypervisor(self, name):
607
    return self._test_hv
608

  
609
  def testGetHvInfoAllNone(self):
610
    result = backend._GetHvInfoAll(None)
611
    self.assertTrue(result is None)
612

  
613
  def testGetHvInfoAll(self):
614
    hvname = constants.HT_XEN_PVM
615
    hvparams = {constants.HV_XEN_CMD: constants.XEN_CMD_XL}
616
    hv_specs = [(hvname, hvparams)]
617

  
618
    result = backend._GetHvInfoAll(hv_specs, self._GetHypervisor)
619
    self._test_hv.GetNodeInfo.assert_called_with(hvparams=hvparams)
620

  
621

  
596 622
if __name__ == "__main__":
597 623
  testutils.GanetiTestProgram()

Also available in: Unified diff