Revision 59ed268d htools/Ganeti/HTools/QC.hs
b/htools/Ganeti/HTools/QC.hs | ||
---|---|---|
154 | 154 |
, Instance.vcpus = Node.availCpu node `div` 2 |
155 | 155 |
} |
156 | 156 |
|
157 |
-- | Check if an instance is smaller than a node. |
|
158 |
isInstanceSmallerThanNode node inst = |
|
159 |
Instance.mem inst <= Node.availMem node `div` 2 && |
|
160 |
Instance.dsk inst <= Node.availDisk node `div` 2 && |
|
161 |
Instance.vcpus inst <= Node.availCpu node `div` 2 |
|
162 |
|
|
163 | 157 |
-- | Create an instance given its spec. |
164 | 158 |
createInstance mem dsk vcpus = |
165 | 159 |
Instance.create "inst-unnamed" mem dsk vcpus Types.Running [] True (-1) (-1) |
... | ... | |
279 | 273 |
instance Arbitrary Types.InstanceStatus where |
280 | 274 |
arbitrary = elements [minBound..maxBound] |
281 | 275 |
|
276 |
-- | Generates a random instance with maximum disk/mem/cpu values. |
|
277 |
genInstanceSmallerThan :: Int -> Int -> Int -> Gen Instance.Instance |
|
278 |
genInstanceSmallerThan lim_mem lim_dsk lim_cpu = do |
|
279 |
name <- getFQDN |
|
280 |
mem <- choose (0, lim_mem) |
|
281 |
dsk <- choose (0, lim_dsk) |
|
282 |
run_st <- arbitrary |
|
283 |
pn <- arbitrary |
|
284 |
sn <- arbitrary |
|
285 |
vcpus <- choose (0, lim_cpu) |
|
286 |
return $ Instance.create name mem dsk vcpus run_st [] True pn sn |
|
287 |
Types.DTDrbd8 |
|
288 |
|
|
289 |
-- | Generates an instance smaller than a node. |
|
290 |
genInstanceSmallerThanNode :: Node.Node -> Gen Instance.Instance |
|
291 |
genInstanceSmallerThanNode node = |
|
292 |
genInstanceSmallerThan (Node.availMem node `div` 2) |
|
293 |
(Node.availDisk node `div` 2) |
|
294 |
(Node.availCpu node `div` 2) |
|
295 |
|
|
282 | 296 |
-- let's generate a random instance |
283 | 297 |
instance Arbitrary Instance.Instance where |
284 |
arbitrary = do |
|
285 |
name <- getFQDN |
|
286 |
mem <- choose (0, maxMem) |
|
287 |
dsk <- choose (0, maxDsk) |
|
288 |
run_st <- arbitrary |
|
289 |
pn <- arbitrary |
|
290 |
sn <- arbitrary |
|
291 |
vcpus <- choose (0, maxCpu) |
|
292 |
return $ Instance.create name mem dsk vcpus run_st [] True pn sn |
|
293 |
Types.DTDrbd8 |
|
298 |
arbitrary = genInstanceSmallerThan maxMem maxDsk maxCpu |
|
294 | 299 |
|
295 | 300 |
-- | Generas an arbitrary node based on sizing information. |
296 | 301 |
genNode :: Maybe Int -- ^ Minimum node size in terms of units |
... | ... | |
818 | 823 |
forAll (choose (1, 20)) $ \maxiter -> |
819 | 824 |
forAll (choose (2, 10)) $ \count -> |
820 | 825 |
forAll genOnlineNode $ \node -> |
821 |
forAll (arbitrary `suchThat` isInstanceSmallerThanNode node) $ \inst ->
|
|
822 |
let inst' = Instance.setMovable inst $ Utils.if' (reqnodes == 2) True False
|
|
826 |
forAll (genInstanceSmallerThanNode node) $ \inst ->
|
|
827 |
let inst' = Instance.setMovable inst (reqnodes == 2)
|
|
823 | 828 |
nl = makeSmallCluster node count |
824 | 829 |
in case Cluster.genAllocNodes defGroupList nl reqnodes True >>= \allocn -> |
825 | 830 |
Cluster.iterateAlloc nl Container.empty (Just maxiter) inst' allocn [] [] |
... | ... | |
1095 | 1100 |
prop_ClusterAllocRelocate = |
1096 | 1101 |
forAll (choose (4, 8)) $ \count -> |
1097 | 1102 |
forAll (genOnlineNode `suchThat` (isNodeBig 4)) $ \node -> |
1098 |
forAll (arbitrary `suchThat` (isInstanceSmallerThanNode node)) $ \inst ->
|
|
1103 |
forAll (genInstanceSmallerThanNode node) $ \inst ->
|
|
1099 | 1104 |
case genClusterAlloc count node inst of |
1100 | 1105 |
Types.Bad msg -> failTest msg |
1101 | 1106 |
Types.Ok (nl, il, inst') -> |
... | ... | |
1130 | 1135 |
prop_ClusterAllocEvacuate = |
1131 | 1136 |
forAll (choose (4, 8)) $ \count -> |
1132 | 1137 |
forAll (genOnlineNode `suchThat` (isNodeBig 4)) $ \node -> |
1133 |
forAll (arbitrary `suchThat` (isInstanceSmallerThanNode node)) $ \inst ->
|
|
1138 |
forAll (genInstanceSmallerThanNode node) $ \inst ->
|
|
1134 | 1139 |
case genClusterAlloc count node inst of |
1135 | 1140 |
Types.Bad msg -> failTest msg |
1136 | 1141 |
Types.Ok (nl, il, inst') -> |
... | ... | |
1144 | 1149 |
prop_ClusterAllocChangeGroup = |
1145 | 1150 |
forAll (choose (4, 8)) $ \count -> |
1146 | 1151 |
forAll (genOnlineNode `suchThat` (isNodeBig 4)) $ \node -> |
1147 |
forAll (arbitrary `suchThat` (isInstanceSmallerThanNode node)) $ \inst ->
|
|
1152 |
forAll (genInstanceSmallerThanNode node) $ \inst ->
|
|
1148 | 1153 |
case genClusterAlloc count node inst of |
1149 | 1154 |
Types.Bad msg -> failTest msg |
1150 | 1155 |
Types.Ok (nl, il, inst') -> |
Also available in: Unified diff