Revision e1dde6ad

b/htools/Ganeti/HTools/QC.hs
32 32
  , testInstance
33 33
  , testNode
34 34
  , testText
35
  , testSimu
35 36
  , testOpCodes
36 37
  , testJobs
37 38
  , testCluster
......
40 41
  ) where
41 42

  
42 43
import Test.QuickCheck
44
import Text.Printf (printf)
43 45
import Data.List (findIndex, intercalate, nub, isPrefixOf)
46
import qualified Data.Set as Set
44 47
import Data.Maybe
45 48
import Control.Monad
46 49
import qualified Text.JSON as J
......
62 65
import qualified Ganeti.HTools.Group as Group
63 66
import qualified Ganeti.HTools.PeerMap as PeerMap
64 67
import qualified Ganeti.HTools.Rapi
65
import qualified Ganeti.HTools.Simu
68
import qualified Ganeti.HTools.Simu as Simu
66 69
import qualified Ganeti.HTools.Text as Text
67 70
import qualified Ganeti.HTools.Types as Types
68 71
import qualified Ganeti.HTools.Utils as Utils
......
705 708
            , 'prop_Instance_setMovable
706 709
            ]
707 710

  
708
-- ** Text backend tests
711
-- ** Backends
712

  
713
-- *** Text backend tests
709 714

  
710 715
-- Instance text loader tests
711 716

  
......
856 861
            , 'prop_Text_CreateSerialise
857 862
            ]
858 863

  
864
-- *** Simu backend
865

  
866
-- | Generates a tuple of specs for simulation.
867
genSimuSpec :: Gen (String, Int, Int, Int, Int)
868
genSimuSpec = do
869
  pol <- elements [C.allocPolicyPreferred,
870
                   C.allocPolicyLastResort, C.allocPolicyUnallocable,
871
                  "p", "a", "u"]
872
 -- should be reasonable (nodes/group), bigger values only complicate
873
 -- the display of failed tests, and we don't care (in this particular
874
 -- test) about big node groups
875
  nodes <- choose (0, 20)
876
  dsk <- choose (0, maxDsk)
877
  mem <- choose (0, maxMem)
878
  cpu <- choose (0, maxCpu)
879
  return (pol, nodes, dsk, mem, cpu)
880

  
881
-- | Checks that given a set of corrects specs, we can load them
882
-- successfully, and that at high-level the values look right.
883
prop_SimuLoad =
884
  forAll (choose (0, 10)) $ \ngroups ->
885
  forAll (replicateM ngroups genSimuSpec) $ \specs ->
886
  let strspecs = map (\(p, n, d, m, c) -> printf "%s,%d,%d,%d,%d"
887
                                          p n d m c::String) specs
888
      totnodes = sum $ map (\(_, n, _, _, _) -> n) specs
889
      mdc_in = concatMap (\(_, n, d, m, c) ->
890
                            replicate n (fromIntegral m, fromIntegral d,
891
                                         fromIntegral c,
892
                                         fromIntegral m, fromIntegral d)) specs
893
  in case Simu.parseData strspecs of
894
       Types.Bad msg -> failTest $ "Failed to load specs: " ++ msg
895
       Types.Ok (Loader.ClusterData gl nl il tags ipol) ->
896
         let nodes = map snd $ IntMap.toAscList nl
897
             nidx = map Node.idx nodes
898
             mdc_out = map (\n -> (Node.tMem n, Node.tDsk n, Node.tCpu n,
899
                                   Node.fMem n, Node.fDsk n)) nodes
900
         in
901
         Container.size gl ==? ngroups .&&.
902
         Container.size nl ==? totnodes .&&.
903
         Container.size il ==? 0 .&&.
904
         length tags ==? 0 .&&.
905
         ipol ==? Types.defIPolicy .&&.
906
         nidx ==? [1..totnodes] .&&.
907
         mdc_in ==? mdc_out .&&.
908
         map Group.iPolicy (Container.elems gl) ==?
909
             replicate ngroups Types.defIPolicy
910

  
911
testSuite "Simu"
912
            [ 'prop_SimuLoad
913
            ]
914

  
859 915
-- ** Node tests
860 916

  
861 917
prop_Node_setAlias node name =
b/htools/test.hs
4 4

  
5 5
{-
6 6

  
7
Copyright (C) 2009, 2011 Google Inc.
7
Copyright (C) 2009, 2011, 2012 Google Inc.
8 8

  
9 9
This program is free software; you can redistribute it and/or modify
10 10
it under the terms of the GNU General Public License as published by
......
115 115
  , (fast, testInstance)
116 116
  , (fast, testNode)
117 117
  , (fast, testText)
118
  , (fast, testSimu)
118 119
  , (fast, testOpCodes)
119 120
  , (fast, testJobs)
120 121
  , (fast, testLoader)

Also available in: Unified diff