Revision 41044e04 test/hs/Test/Ganeti/HTools/Types.hs
b/test/hs/Test/Ganeti/HTools/Types.hs | ||
---|---|---|
42 | 42 |
|
43 | 43 |
import Control.Applicative |
44 | 44 |
import Data.List (sort) |
45 |
import Control.Monad (replicateM) |
|
45 | 46 |
|
46 | 47 |
import Test.Ganeti.TestHelper |
47 | 48 |
import Test.Ganeti.TestCommon |
... | ... | |
101 | 102 |
, Types.iSpecSpindleUse = fromIntegral su |
102 | 103 |
} |
103 | 104 |
|
105 |
genMinMaxISpecs :: Gen Types.MinMaxISpecs |
|
106 |
genMinMaxISpecs = do |
|
107 |
imin <- arbitrary |
|
108 |
imax <- genBiggerISpec imin |
|
109 |
return Types.MinMaxISpecs { Types.minMaxISpecsMinSpec = imin |
|
110 |
, Types.minMaxISpecsMaxSpec = imax |
|
111 |
} |
|
112 |
|
|
113 |
instance Arbitrary Types.MinMaxISpecs where |
|
114 |
arbitrary = genMinMaxISpecs |
|
115 |
|
|
116 |
genMinMaxStdISpecs :: Gen (Types.MinMaxISpecs, Types.ISpec) |
|
117 |
genMinMaxStdISpecs = do |
|
118 |
imin <- arbitrary |
|
119 |
istd <- genBiggerISpec imin |
|
120 |
imax <- genBiggerISpec istd |
|
121 |
return (Types.MinMaxISpecs { Types.minMaxISpecsMinSpec = imin |
|
122 |
, Types.minMaxISpecsMaxSpec = imax |
|
123 |
}, |
|
124 |
istd) |
|
125 |
|
|
126 |
genIPolicySpecs :: Gen ([Types.MinMaxISpecs], Types.ISpec) |
|
127 |
genIPolicySpecs = do |
|
128 |
num_mm <- choose (1, 6) -- 6 is just an arbitrary limit |
|
129 |
std_compl <- choose (1, num_mm) |
|
130 |
mm_head <- replicateM (std_compl - 1) genMinMaxISpecs |
|
131 |
(mm_middle, istd) <- genMinMaxStdISpecs |
|
132 |
mm_tail <- replicateM (num_mm - std_compl) genMinMaxISpecs |
|
133 |
return (mm_head ++ (mm_middle : mm_tail), istd) |
|
134 |
|
|
135 |
|
|
104 | 136 |
instance Arbitrary Types.IPolicy where |
105 | 137 |
arbitrary = do |
106 |
imin <- arbitrary |
|
107 |
istd <- genBiggerISpec imin |
|
108 |
imax <- genBiggerISpec istd |
|
138 |
(iminmax, istd) <- genIPolicySpecs |
|
109 | 139 |
num_tmpl <- choose (0, length allDiskTemplates) |
110 | 140 |
dts <- genUniquesList num_tmpl arbitrary |
111 | 141 |
vcpu_ratio <- choose (1.0, maxVcpuRatio) |
112 | 142 |
spindle_ratio <- choose (1.0, maxSpindleRatio) |
113 |
return Types.IPolicy { Types.iPolicyMinMaxISpecs = Types.MinMaxISpecs |
|
114 |
{ Types.minMaxISpecsMinSpec = imin |
|
115 |
, Types.minMaxISpecsMaxSpec = imax |
|
116 |
} |
|
143 |
return Types.IPolicy { Types.iPolicyMinMaxISpecs = iminmax |
|
117 | 144 |
, Types.iPolicyStdSpec = istd |
118 | 145 |
, Types.iPolicyDiskTemplates = dts |
119 | 146 |
, Types.iPolicyVcpuRatio = vcpu_ratio |
Also available in: Unified diff