Revision d83903ee htest/Test/Ganeti/HTools/Cluster.hs

b/htest/Test/Ganeti/HTools/Cluster.hs
146 146
                printTestCase "Solution score differs from actual node list:"
147 147
                  (Cluster.compCV xnl ==? cv)
148 148

  
149
-- | Check that multiple instances can allocated correctly, without
150
-- rebalances needed.
151
prop_IterateAlloc_sane :: Instance.Instance -> Property
152
prop_IterateAlloc_sane inst =
153
  forAll (choose (5, 10)) $ \count ->
154
  forAll genOnlineNode $ \node ->
155
  forAll (choose (2, 5)) $ \limit ->
156
  let (nl, il, inst') = makeSmallEmptyCluster node count inst
157
      reqnodes = Instance.requiredNodes $ Instance.diskTemplate inst
158
      allocnodes = Cluster.genAllocNodes defGroupList nl reqnodes True
159
  in case allocnodes >>= \allocnodes' ->
160
     Cluster.iterateAlloc nl il (Just limit) inst' allocnodes' [] [] of
161
       Types.Bad msg -> failTest msg
162
       Types.Ok (_, xnl, xil, _, _) ->
163
         let old_score = Cluster.compCV xnl
164
             tbl = Cluster.Table xnl xil old_score []
165
         in case Cluster.tryBalance tbl True True False 0 1e-4 of
166
              Nothing -> passTest
167
              Just (Cluster.Table ynl _ new_score plcs) ->
168
                -- note that with a "min_gain" of zero, sometime
169
                -- rounding errors can trigger a rebalance that
170
                -- improves the score by e.g. 2e-14; in order to
171
                -- prevent such no-real-change moves from happening,
172
                -- we check for a min-gain of 1e-9
173
                -- FIXME: correct rebalancing to not do no-ops
174
                printTestCase
175
                  ("Cluster can be balanced after allocation\n" ++
176
                   " old cluster (score " ++ show old_score ++
177
                   "):\n" ++ Cluster.printNodes xnl [] ++
178
                   " new cluster (score " ++ show new_score ++
179
                   "):\n" ++ Cluster.printNodes ynl [] ++
180
                   "placements:\n" ++ show plcs ++ "\nscore delta: " ++
181
                   show (old_score - new_score))
182
                  (old_score - new_score < 1e-9)
183

  
149 184
-- | Checks that on a 2-5 node cluster, we can allocate a random
150 185
-- instance spec via tiered allocation (whatever the original instance
151 186
-- spec), on either one or two nodes. Furthermore, we test that
......
361 396
            [ 'prop_Score_Zero
362 397
            , 'prop_CStats_sane
363 398
            , 'prop_Alloc_sane
399
            , 'prop_IterateAlloc_sane
364 400
            , 'prop_CanTieredAlloc
365 401
            , 'prop_AllocRelocate
366 402
            , 'prop_AllocEvacuate

Also available in: Unified diff