Revision 99b63608 Ganeti/HTools/QC.hs

b/Ganeti/HTools/QC.hs
110 110
    let fn = Node.buildPeers node Container.empty
111 111
        namelst = map (\n -> (Node.name n, n)) (replicate count fn)
112 112
        (_, nlst) = Loader.assignIndices namelst
113
    in Container.fromAssocList nlst
113
    in nlst
114 114

  
115 115
-- | Checks if a node is "big" enough
116 116
isNodeBig :: Node.Node -> Int -> Bool
......
448 448
        ndx = if null snode
449 449
              then [(pnode, pdx)]
450 450
              else [(pnode, pdx), (snode, rsdx)]
451
        nl = Data.Map.fromList ndx
451 452
        tags = ""
452
        inst = Text.loadInst ndx
453
        inst = Text.loadInst nl
453 454
               [name, mem_s, dsk_s, vcpus_s, status, pnode, snode, tags]::
454 455
               Maybe (String, Instance.Instance)
455
        fail1 = Text.loadInst ndx
456
        fail1 = Text.loadInst nl
456 457
               [name, mem_s, dsk_s, vcpus_s, status, pnode, pnode, tags]::
457 458
               Maybe (String, Instance.Instance)
458 459
        _types = ( name::String, mem::Int, dsk::Int
......
473 474
             isNothing fail1)
474 475

  
475 476
prop_Text_Load_InstanceFail ktn fields =
476
    length fields /= 8 ==> isNothing $ Text.loadInst ktn fields
477
    length fields /= 8 ==> isNothing $ Text.loadInst nl fields
478
    where nl = Data.Map.fromList ktn
477 479

  
478 480
prop_Text_Load_Node name tm nm fm td fd tc fo =
479 481
    let conv v = if v < 0
......
822 824
-- | Loader tests
823 825

  
824 826
prop_Loader_lookupNode ktn inst node =
825
  isJust (Loader.lookupNode ktn inst node) == (node `elem` names)
826
    where names = map fst ktn
827
  Loader.lookupNode nl inst node == Data.Map.lookup node nl
828
  where nl = Data.Map.fromList ktn
827 829

  
828 830
prop_Loader_lookupInstance kti inst =
829
  isJust (Loader.lookupInstance kti inst) == (inst `elem` names)
830
    where names = map fst kti
831

  
832
prop_Loader_lookupInstanceIdx kti inst =
833
  case (Loader.lookupInstance kti inst,
834
        findIndex (\p -> fst p == inst) kti) of
835
    (Nothing, Nothing) -> True
836
    (Just idx, Just ex) -> idx == snd (kti !! ex)
837
    _ -> False
838

  
839
prop_Loader_assignIndices enames =
840
  length nassoc == length enames &&
841
  length kt == length enames &&
842
  (if not (null enames)
843
   then maximum (map fst kt) == length enames - 1
831
  Loader.lookupInstance il inst == Data.Map.lookup inst il
832
  where il = Data.Map.fromList kti
833

  
834
prop_Loader_assignIndices nodes =
835
  Data.Map.size nassoc == length nodes &&
836
  Container.size kt == length nodes &&
837
  (if not (null nodes)
838
   then maximum (IntMap.keys kt) == length nodes - 1
844 839
   else True)
845
  where (nassoc, kt) = Loader.assignIndices enames
846
        _types = enames::[(String, Node.Node)]
840
  where (nassoc, kt) = Loader.assignIndices (map (\n -> (Node.name n, n)) nodes)
847 841

  
848 842

  
849 843
-- | Checks that the number of primary instances recorded on the nodes
850 844
-- is zero
851 845
prop_Loader_mergeData ns =
852
  let na = map (\n -> (Node.idx n, n)) ns
853
  in case Loader.mergeData [] [] [] (na, [], []) of
846
  let na = Container.fromAssocList $ map (\n -> (Node.idx n, n)) ns
847
  in case Loader.mergeData [] [] [] (na, Container.empty, []) of
854 848
    Types.Bad _ -> False
855 849
    Types.Ok (nl, il, _) ->
856 850
      let nodes = Container.elems nl
......
861 855
testLoader =
862 856
  [ run prop_Loader_lookupNode
863 857
  , run prop_Loader_lookupInstance
864
  , run prop_Loader_lookupInstanceIdx
865 858
  , run prop_Loader_assignIndices
866 859
  , run prop_Loader_mergeData
867 860
  ]

Also available in: Unified diff