Revision 20faaa74

b/lib/cmdlib/node.py
1183 1183
      # filter out non-vm_capable nodes
1184 1184
      toquery_node_uuids = [node.uuid for node in all_info.values()
1185 1185
                            if node.vm_capable and node.uuid in node_uuids]
1186
      lvm_enabled = utils.storage.IsLvmEnabled(
1187
          lu.cfg.GetClusterInfo().enabled_disk_templates)
1186 1188
      # FIXME: this per default asks for storage space information for all
1187 1189
      # enabled disk templates. Fix this by making it possible to specify
1188 1190
      # space report fields for specific disk templates.
1189 1191
      raw_storage_units = utils.storage.GetStorageUnitsOfCluster(
1190
          lu.cfg, include_spindles=True)
1192
          lu.cfg, include_spindles=lvm_enabled)
1191 1193
      storage_units = rpc.PrepareStorageUnitsForNodes(
1192 1194
          lu.cfg, raw_storage_units, toquery_node_uuids)
1193
      lvm_enabled = utils.storage.IsLvmEnabled(
1194
          lu.cfg.GetClusterInfo().enabled_disk_templates)
1195 1195
      default_hypervisor = lu.cfg.GetHypervisorType()
1196 1196
      hvparams = lu.cfg.GetClusterInfo().hvparams[default_hypervisor]
1197 1197
      hvspecs = [(default_hypervisor, hvparams)]
......
1199 1199
                                        hvspecs)
1200 1200
      live_data = dict(
1201 1201
          (uuid, rpc.MakeLegacyNodeInfo(nresult.payload,
1202
                                        require_vg_info=lvm_enabled))
1202
                                        require_spindles=lvm_enabled))
1203 1203
          for (uuid, nresult) in node_data.items()
1204 1204
          if not nresult.fail_msg and nresult.payload)
1205 1205
    else:
b/lib/rpc.py
610 610
  if lvm_pv_info:
611 611
    result["spindles_free"] = lvm_pv_info["storage_free"]
612 612
    result["spindles_total"] = lvm_pv_info["storage_size"]
613
  else:
614
    raise errors.OpExecError("No spindle storage information available.")
613 615

  
614 616

  
615
def _AddDefaultStorageInfoToLegacyNodeInfo(result, space_info,
616
                                           require_vg_info=True):
617
def _AddDefaultStorageInfoToLegacyNodeInfo(result, space_info):
617 618
  """Extracts the storage space information of the default storage type from
618 619
  the space info and adds it to the result dictionary.
619 620

  
620 621
  @see: C{_AddSpindlesToLegacyNodeInfo} for parameter information.
621
  @type require_vg_info: boolean
622
  @param require_vg_info: indicates whether volume group information is
623
    required or not
624 622

  
625 623
  """
626 624
  # Check if there is at least one row for non-spindle storage info.
......
633 631
  else:
634 632
    default_space_info = space_info[0]
635 633

  
636
  if require_vg_info:
637
    # if lvm storage is required, ignore the actual default and look for LVM
638
    lvm_info_found = False
639
    for space_entry in space_info:
640
      if space_entry["type"] == constants.ST_LVM_VG:
641
        default_space_info = space_entry
642
        lvm_info_found = True
643
        continue
644
    if not lvm_info_found:
645
      raise errors.OpExecError("LVM volume group info required, but not"
646
                               " provided.")
647

  
648 634
  if default_space_info:
649 635
    result["name"] = default_space_info["name"]
650 636
    result["storage_free"] = default_space_info["storage_free"]
651 637
    result["storage_size"] = default_space_info["storage_size"]
652 638

  
653 639

  
654
def MakeLegacyNodeInfo(data, require_vg_info=True):
640
def MakeLegacyNodeInfo(data, require_spindles=False):
655 641
  """Formats the data returned by L{rpc.RpcRunner.call_node_info}.
656 642

  
657 643
  Converts the data into a single dictionary. This is fine for most use cases,
658 644
  but some require information from more than one volume group or hypervisor.
659 645

  
660
  @param require_vg_info: raise an error if the returnd vg_info
661
      doesn't have any values
646
  @param require_spindles: add spindle storage information to the legacy node
647
      info
662 648

  
663 649
  """
664 650
  (bootid, space_info, (hv_info, )) = data
665 651

  
666 652
  ret = utils.JoinDisjointDicts(hv_info, {"bootid": bootid})
667 653

  
668
  _AddSpindlesToLegacyNodeInfo(ret, space_info)
669
  _AddDefaultStorageInfoToLegacyNodeInfo(ret, space_info,
670
                                         require_vg_info=require_vg_info)
654
  if require_spindles:
655
    _AddSpindlesToLegacyNodeInfo(ret, space_info)
656
  _AddDefaultStorageInfoToLegacyNodeInfo(ret, space_info)
671 657

  
672 658
  return ret
673 659

  
b/test/py/ganeti.rpc_unittest.py
936 936
    KEY_VG1: VAL_VG1,
937 937
    KEY_VG2: VAL_VG2,
938 938
    KEY_HV: VAL_HV,
939
    KEY_SP1: VAL_SP1,
940
    KEY_SP2: VAL_SP2,
941 939
    }
942 940

  
943 941
  def testStandard(self):
944 942
    result = rpc.MakeLegacyNodeInfo(self.STD_LST)
945 943
    self.assertEqual(result, self.STD_DICT)
946 944

  
947
  def testReqVg(self):
945
  def testSpindlesRequired(self):
948 946
    my_lst = [self.VAL_BOOT, [], [self.DICT_HV]]
949
    self.assertRaises(errors.OpExecError, rpc.MakeLegacyNodeInfo, my_lst)
947
    self.assertRaises(errors.OpExecError, rpc.MakeLegacyNodeInfo, my_lst,
948
        require_spindles=True)
950 949

  
951
  def testNoReqVg(self):
950
  def testNoSpindlesRequired(self):
952 951
    my_lst = [self.VAL_BOOT, [], [self.DICT_HV]]
953
    result = rpc.MakeLegacyNodeInfo(my_lst, require_vg_info = False)
952
    result = rpc.MakeLegacyNodeInfo(my_lst, require_spindles = False)
954 953
    self.assertEqual(result, {self.KEY_BOOT: self.VAL_BOOT,
955 954
                              self.KEY_HV: self.VAL_HV})
956
    result = rpc.MakeLegacyNodeInfo(self.STD_LST, require_vg_info = False)
955
    result = rpc.MakeLegacyNodeInfo(self.STD_LST, require_spindles = False)
957 956
    self.assertEqual(result, self.STD_DICT)
958 957

  
959 958

  
......
964 963
    self.total_storage_file = 42
965 964
    self.free_storage_lvm = 69
966 965
    self.total_storage_lvm = 666
967
    self.node_info = [{"name": "mynode",
966
    self.node_info = [{"name": "myfile",
968 967
                       "type": constants.ST_FILE,
969 968
                       "storage_free": self.free_storage_file,
970 969
                       "storage_size": self.total_storage_file},
971
                      {"name": "mynode",
970
                      {"name": "myvg",
972 971
                       "type": constants.ST_LVM_VG,
973 972
                       "storage_free": self.free_storage_lvm,
974 973
                       "storage_size": self.total_storage_lvm},
975
                      {"name": "mynode",
974
                      {"name": "myspindle",
976 975
                       "type": constants.ST_LVM_PV,
977 976
                       "storage_free": 33,
978 977
                       "storage_size": 44}]
979 978

  
980 979
  def testAddDefaultStorageInfoToLegacyNodeInfo(self):
981 980
    result = {}
982
    has_lvm = False
983
    rpc._AddDefaultStorageInfoToLegacyNodeInfo(result, self.node_info, has_lvm)
981
    rpc._AddDefaultStorageInfoToLegacyNodeInfo(result, self.node_info)
984 982
    self.assertEqual(self.free_storage_file, result["storage_free"])
985 983
    self.assertEqual(self.total_storage_file, result["storage_size"])
986 984

  
987
  def testAddDefaultStorageInfoToLegacyNodeInfoOverrideDefault(self):
988
    result = {}
989
    has_lvm = True
990
    rpc._AddDefaultStorageInfoToLegacyNodeInfo(result, self.node_info, has_lvm)
991
    self.assertEqual(self.free_storage_lvm, result["storage_free"])
992
    self.assertEqual(self.total_storage_lvm, result["storage_size"])
993

  
994 985
  def testAddDefaultStorageInfoToLegacyNodeInfoNoDefaults(self):
995 986
    result = {}
996
    has_lvm = False
997
    rpc._AddDefaultStorageInfoToLegacyNodeInfo(result, self.node_info[-1:],
998
                                               has_lvm)
987
    rpc._AddDefaultStorageInfoToLegacyNodeInfo(result, self.node_info[-1:])
999 988
    self.assertFalse("storage_free" in result)
1000 989
    self.assertFalse("storage_size" in result)
1001 990

  
1002
  def testAddDefaultStorageInfoToLegacyNodeInfoNoLvm(self):
1003
    result = {}
1004
    has_lvm = True
1005
    self.assertRaises(errors.OpExecError,
1006
                      rpc._AddDefaultStorageInfoToLegacyNodeInfo,
1007
                      result, self.node_info[-1:], has_lvm)
1008

  
1009 991

  
1010 992
if __name__ == "__main__":
1011 993
  testutils.GanetiTestProgram()

Also available in: Unified diff