Revision d6f9f5bd htools/Ganeti/HTools/QC.hs

b/htools/Ganeti/HTools/QC.hs
167 167
   setInstanceSmallerThanNode node inst)
168 168

  
169 169
-- | Checks if a node is "big" enough.
170
isNodeBig :: Node.Node -> Int -> Bool
171
isNodeBig node size = Node.availDisk node > size * Types.unitDsk
170
isNodeBig :: Int -> Node.Node -> Bool
171
isNodeBig size node = Node.availDisk node > size * Types.unitDsk
172 172
                      && Node.availMem node > size * Types.unitMem
173 173
                      && Node.availCpu node > size * Types.unitCpu
174 174

  
......
265 265
      n' = Node.setPolicy nullIPolicy n
266 266
  return $ Node.buildPeers n' Container.empty
267 267

  
268
-- | Helper function to generate a sane node.
269
genOnlineNode :: Gen Node.Node
270
genOnlineNode = do
271
  arbitrary `suchThat` (\n -> not (Node.offline n) &&
272
                              not (Node.failN1 n) &&
273
                              Node.availDisk n > 0 &&
274
                              Node.availMem n > 0 &&
275
                              Node.availCpu n > 0)
276

  
268 277
-- and a random node
269 278
instance Arbitrary Node.Node where
270 279
  arbitrary = genNode Nothing Nothing
......
908 917
  in score <= 1e-12
909 918

  
910 919
-- | Check that cluster stats are sane.
911
prop_CStats_sane node =
920
prop_CStats_sane =
912 921
  forAll (choose (1, 1024)) $ \count ->
913
    (not (Node.offline node) && not (Node.failN1 node) &&
914
     (Node.availDisk node > 0) && (Node.availMem node > 0)) ==>
922
  forAll genOnlineNode $ \node ->
915 923
  let fn = Node.buildPeers node Container.empty
916 924
      nlst = zip [1..] $ replicate count fn::[(Types.Ndx, Node.Node)]
917 925
      nl = Container.fromList nlst
......
921 929

  
922 930
-- | Check that one instance is allocated correctly, without
923 931
-- rebalances needed.
924
prop_ClusterAlloc_sane node inst =
932
prop_ClusterAlloc_sane inst =
925 933
  forAll (choose (5, 20)) $ \count ->
926
  not (Node.offline node)
927
        && not (Node.failN1 node)
928
        && Node.availDisk node > 0
929
        && Node.availMem node > 0
930
        ==>
934
  forAll genOnlineNode $ \node ->
931 935
  let (nl, il, inst') = makeSmallEmptyCluster node count inst
932 936
  in case Cluster.genAllocNodes defGroupList nl 2 True >>=
933 937
     Cluster.tryAlloc nl il inst' of
......
943 947
-- | Checks that on a 2-5 node cluster, we can allocate a random
944 948
-- instance spec via tiered allocation (whatever the original instance
945 949
-- spec), on either one or two nodes.
946
prop_ClusterCanTieredAlloc node inst =
950
prop_ClusterCanTieredAlloc inst =
947 951
  forAll (choose (2, 5)) $ \count ->
948 952
  forAll (choose (1, 2)) $ \rqnodes ->
949
  not (Node.offline node)
950
        && not (Node.failN1 node)
951
        && isNodeBig node 4
952
        ==>
953
  forAll (genOnlineNode `suchThat` (isNodeBig 4)) $ \node ->
953 954
  let nl = makeSmallCluster node count
954 955
      il = Container.empty
955 956
      allocnodes = Cluster.genAllocNodes defGroupList nl rqnodes True
......
962 963

  
963 964
-- | Checks that on a 4-8 node cluster, once we allocate an instance,
964 965
-- we can also evacuate it.
965
prop_ClusterAllocEvac node inst =
966
prop_ClusterAllocEvac inst =
966 967
  forAll (choose (4, 8)) $ \count ->
967
  not (Node.offline node)
968
        && not (Node.failN1 node)
969
        && isNodeBig node 4
970
        ==>
968
  forAll (genOnlineNode `suchThat` (isNodeBig 4)) $ \node ->
971 969
  let (nl, il, inst') = makeSmallEmptyCluster node count inst
972 970
  in case Cluster.genAllocNodes defGroupList nl 2 True >>=
973 971
     Cluster.tryAlloc nl il inst' of

Also available in: Unified diff