Revision da4a52a3 test/py/ganeti.query_unittest.py

b/test/py/ganeti.query_unittest.py
346 346
                   ndparams={constants.ND_SPINDLE_COUNT: 4}),
347 347
      ]
348 348
    for live_data in [None, dict.fromkeys([node.name for node in nodes], {})]:
349
      nqd = query.NodeQueryData(nodes, live_data, None, None, None,
349
      nqd = query.NodeQueryData(nodes, live_data, None, None, None, None,
350 350
                                groups, None, cluster)
351 351

  
352 352
      q = self._Create(["name", "drained"])
......
448 448
      dict((query._NODE_LIVE_FIELDS[name][2], value)
449 449
           for name, value in fake_live_data.items())
450 450

  
451
    node_to_primary = dict((node.uuid, set()) for node in nodes)
452
    node_to_primary[master_node.uuid].update(["inst1", "inst2"])
451
    node_to_primary_uuid = dict((node.uuid, set()) for node in nodes)
452
    node_to_primary_uuid[master_node.uuid].update(["inst1", "inst2"])
453 453

  
454
    node_to_secondary = dict((node.uuid, set()) for node in nodes)
455
    node_to_secondary[live_data_node.uuid].update(["instX", "instY", "instZ"])
454
    node_to_secondary_uuid = dict((node.uuid, set()) for node in nodes)
455
    node_to_secondary_uuid[live_data_node.uuid].update(["instX", "instY",
456
                                                        "instZ"])
457

  
458
    inst_uuid_to_inst_name = {
459
      "inst1": "inst1-name",
460
      "inst2": "inst2-name",
461
      "instX": "instX-name",
462
      "instY": "instY-name",
463
      "instZ": "instZ-name"
464
    }
456 465

  
457 466
    ng_uuid = "492b4b74-8670-478a-b98d-4c53a76238e6"
458 467
    groups = {
......
468 477
    master_node.group = ng_uuid
469 478

  
470 479
    nqd = query.NodeQueryData(nodes, live_data, master_node.uuid,
471
                              node_to_primary, node_to_secondary, groups,
472
                              oob_support, cluster)
480
                              node_to_primary_uuid, node_to_secondary_uuid,
481
                              inst_uuid_to_inst_name, groups, oob_support,
482
                              cluster)
473 483
    result = q.Query(nqd)
474 484
    self.assert_(compat.all(len(row) == len(selected) for row in result))
475 485
    self.assertEqual([row[field_index["name"]] for row in result],
......
523 533
                     (constants.RS_NORMAL, 3))
524 534
    self.assertEqual(master_row[field_index["pinst_list"]],
525 535
                     (constants.RS_NORMAL,
526
                      list(node_to_primary[master_node.uuid])))
536
                      [inst_uuid_to_inst_name[uuid] for uuid in
537
                       node_to_primary_uuid[master_node.uuid]]))
527 538
    self.assertEqual(live_data_row[field_index["sinst_list"]],
528 539
                     (constants.RS_NORMAL,
529
                      utils.NiceSort(list(
530
                        node_to_secondary[live_data_node.uuid]))))
540
                      utils.NiceSort(
541
                        [inst_uuid_to_inst_name[uuid] for uuid in
542
                        node_to_secondary_uuid[live_data_node.uuid]])))
531 543

  
532 544
  def testGetLiveNodeField(self):
533 545
    nodes = [
......
545 557
    live_data = dict.fromkeys([node.name for node in nodes], {})
546 558

  
547 559
    # No data
548
    nqd = query.NodeQueryData(None, None, None, None, None, None, None, None)
560
    nqd = query.NodeQueryData(None, None, None, None, None, None, None, None,
561
                              None)
549 562
    self.assertEqual(query._GetLiveNodeField("hello", constants.QFT_NUMBER,
550 563
                                             nqd, nodes[0]),
551 564
                     query._FS_NODATA)
......
674 687

  
675 688
    instances = [
676 689
      objects.Instance(name="inst1", hvparams={}, beparams={}, nics=[],
677
        uuid="f90eccb3-e227-4e3c-bf2a-94a21ca8f9cd",
690
        uuid="inst1-uuid",
678 691
        ctime=1291244000, mtime=1291244400, serial_no=30,
679 692
        admin_state=constants.ADMINST_UP, hypervisor=constants.HT_XEN_PVM,
680 693
        os="linux1",
......
684 697
        disks_active=True,
685 698
        osparams={}),
686 699
      objects.Instance(name="inst2", hvparams={}, nics=[],
687
        uuid="73a0f8a7-068c-4630-ada2-c3440015ab1a",
700
        uuid="inst2-uuid",
688 701
        ctime=1291211000, mtime=1291211077, serial_no=1,
689 702
        admin_state=constants.ADMINST_UP, hypervisor=constants.HT_XEN_HVM,
690 703
        os="deb99",
......
698 711
        },
699 712
        osparams={}),
700 713
      objects.Instance(name="inst3", hvparams={}, beparams={},
701
        uuid="11ec8dff-fb61-4850-bfe0-baa1803ff280",
714
        uuid="inst3-uuid",
702 715
        ctime=1291011000, mtime=1291013000, serial_no=1923,
703 716
        admin_state=constants.ADMINST_DOWN, hypervisor=constants.HT_KVM,
704 717
        os="busybox",
......
715 728
          ],
716 729
        osparams={}),
717 730
      objects.Instance(name="inst4", hvparams={}, beparams={},
718
        uuid="68dab168-3ef5-4c9d-b4d3-801e0672068c",
731
        uuid="inst4-uuid",
719 732
        ctime=1291244390, mtime=1291244395, serial_no=25,
720 733
        admin_state=constants.ADMINST_DOWN, hypervisor=constants.HT_XEN_PVM,
721 734
        os="linux1",
......
741 754
          ],
742 755
        osparams={}),
743 756
      objects.Instance(name="inst5", hvparams={}, nics=[],
744
        uuid="0e3dca12-5b42-4e24-98a2-415267545bd0",
757
        uuid="inst5-uuid",
745 758
        ctime=1231211000, mtime=1261200000, serial_no=3,
746 759
        admin_state=constants.ADMINST_UP, hypervisor=constants.HT_XEN_HVM,
747 760
        os="deb99",
......
755 768
        },
756 769
        osparams={}),
757 770
      objects.Instance(name="inst6", hvparams={}, nics=[],
758
        uuid="72de6580-c8d5-4661-b902-38b5785bb8b3",
771
        uuid="inst6-uuid",
759 772
        ctime=7513, mtime=11501, serial_no=13390,
760 773
        admin_state=constants.ADMINST_DOWN, hypervisor=constants.HT_XEN_HVM,
761 774
        os="deb99",
......
771 784
          "clean_install": "no",
772 785
          }),
773 786
      objects.Instance(name="inst7", hvparams={}, nics=[],
774
        uuid="ceec5dc4-b729-4f42-ae28-69b3cd24920e",
787
        uuid="inst7-uuid",
775 788
        ctime=None, mtime=None, serial_no=1947,
776 789
        admin_state=constants.ADMINST_DOWN, hypervisor=constants.HT_XEN_HVM,
777 790
        os="deb99",
......
782 795
        beparams={},
783 796
        osparams={}),
784 797
      objects.Instance(name="inst8", hvparams={}, nics=[],
785
        uuid="ceec5dc4-b729-4f42-ae28-69b3cd24920f",
798
        uuid="inst8-uuid",
786 799
        ctime=None, mtime=None, serial_no=19478,
787 800
        admin_state=constants.ADMINST_OFFLINE, hypervisor=constants.HT_XEN_HVM,
788 801
        os="deb99",
......
794 807
        osparams={}),
795 808
      ]
796 809

  
810
    assert not utils.FindDuplicates(inst.uuid for inst in instances)
797 811
    assert not utils.FindDuplicates(inst.name for inst in instances)
798 812

  
799 813
    instbyname = dict((inst.name, inst) for inst in instances)
800 814

  
801
    disk_usage = dict((inst.name,
815
    disk_usage = dict((inst.uuid,
802 816
                       gmi.ComputeDiskSize(inst.disk_template,
803 817
                                           [{"size": disk.size}
804 818
                                           for disk in inst.disks]))
805 819
                      for inst in instances)
806 820

  
807 821
    inst_bridges = {
808
      "inst3": [constants.DEFAULT_BRIDGE, constants.DEFAULT_BRIDGE],
809
      "inst4": [constants.DEFAULT_BRIDGE, constants.DEFAULT_BRIDGE,
810
                None, "eth123"],
822
      "inst3-uuid": [constants.DEFAULT_BRIDGE, constants.DEFAULT_BRIDGE],
823
      "inst4-uuid": [constants.DEFAULT_BRIDGE, constants.DEFAULT_BRIDGE,
824
                     None, "eth123"],
811 825
      }
812 826

  
813 827
    live_data = {
814
      "inst2": {
828
      "inst2-uuid": {
815 829
        "vcpus": 3,
816 830
        },
817
      "inst4": {
831
      "inst4-uuid": {
818 832
        "memory": 123,
819 833
        },
820
      "inst6": {
834
      "inst6-uuid": {
821 835
        "memory": 768,
822 836
        },
823
      "inst7": {
837
      "inst7-uuid": {
824 838
        "vcpus": 3,
825 839
        },
826 840
      }
827
    wrongnode_inst = set(["inst7"])
841
    wrongnode_inst = set(["inst7-uuid"])
828 842

  
829
    consinfo = dict((inst.name, None) for inst in instances)
830
    consinfo["inst7"] = \
843
    consinfo = dict((inst.uuid, None) for inst in instances)
844
    consinfo["inst7-uuid"] = \
831 845
      objects.InstanceConsole(instance="inst7", kind=constants.CONS_SSH,
832 846
                              host=instbyname["inst7"].primary_node,
833 847
                              user="root",
......
862 876
        exp_status = constants.INSTST_NODEOFFLINE
863 877
      elif inst.primary_node in bad_nodes:
864 878
        exp_status = constants.INSTST_NODEDOWN
865
      elif inst.name in live_data:
866
        if inst.name in wrongnode_inst:
879
      elif inst.uuid in live_data:
880
        if inst.uuid in wrongnode_inst:
867 881
          exp_status = constants.INSTST_WRONGNODE
868 882
        elif inst.admin_state == constants.ADMINST_UP:
869 883
          exp_status = constants.INSTST_RUNNING
......
886 900
      for (field, livefield) in [("oper_vcpus", "vcpus")]:
887 901
        if inst.primary_node in bad_nodes:
888 902
          exp = (constants.RS_NODATA, None)
889
        elif inst.name in live_data:
890
          value = live_data[inst.name].get(livefield, None)
903
        elif inst.uuid in live_data:
904
          value = live_data[inst.uuid].get(livefield, None)
891 905
          if value is None:
892 906
            exp = (constants.RS_UNAVAIL, None)
893 907
          else:
......
897 911

  
898 912
        self.assertEqual(row[fieldidx[field]], exp)
899 913

  
900
      bridges = inst_bridges.get(inst.name, [])
914
      bridges = inst_bridges.get(inst.uuid, [])
901 915
      self.assertEqual(row[fieldidx["nic.bridges"]],
902 916
                       (constants.RS_NORMAL, bridges))
903 917
      if bridges:
......
917 931
      if inst.primary_node in bad_nodes:
918 932
        exp = (constants.RS_NODATA, None)
919 933
      else:
920
        exp = (constants.RS_NORMAL, inst.name in live_data)
934
        exp = (constants.RS_NORMAL, inst.uuid in live_data)
921 935
      self.assertEqual(row[fieldidx["oper_state"]], exp)
922 936

  
923 937
      cust_exp = (constants.RS_NORMAL, {})
924 938
      if inst.os == "deb99":
925
        if inst.name == "inst6":
939
        if inst.uuid == "inst6-uuid":
926 940
          exp = (constants.RS_NORMAL, {"clean_install": "no"})
927 941
          cust_exp = exp
928 942
        else:
......
932 946
      self.assertEqual(row[fieldidx["osparams"]], exp)
933 947
      self.assertEqual(row[fieldidx["custom_osparams"]], cust_exp)
934 948

  
935
      usage = disk_usage[inst.name]
949
      usage = disk_usage[inst.uuid]
936 950
      if usage is None:
937 951
        usage = 0
938 952
      self.assertEqual(row[fieldidx["disk_usage"]],

Also available in: Unified diff