Revision 834bea99 test/hs/Test/Ganeti/Objects.hs
b/test/hs/Test/Ganeti/Objects.hs | ||
---|---|---|
29 | 29 |
module Test.Ganeti.Objects |
30 | 30 |
( testObjects |
31 | 31 |
, Node(..) |
32 |
, genConfigDataWithNetworks |
|
32 | 33 |
, genEmptyCluster |
34 |
, genInstWithNets |
|
33 | 35 |
, genValidNetwork |
34 | 36 |
, genBitStringMaxLen |
35 | 37 |
) where |
... | ... | |
40 | 42 |
import Control.Applicative |
41 | 43 |
import Control.Monad |
42 | 44 |
import Data.Char |
45 |
import qualified Data.List as List |
|
43 | 46 |
import qualified Data.Map as Map |
44 | 47 |
import qualified Data.Set as Set |
45 | 48 |
import qualified Text.JSON as J |
... | ... | |
116 | 119 |
-- tags |
117 | 120 |
<*> (Set.fromList <$> genTags) |
118 | 121 |
|
122 |
-- | Generates an instance that is connected to the given networks |
|
123 |
-- and possibly some other networks |
|
124 |
genInstWithNets :: [String] -> Gen Instance |
|
125 |
genInstWithNets nets = do |
|
126 |
plain_inst <- arbitrary |
|
127 |
mac <- arbitrary |
|
128 |
ip <- arbitrary |
|
129 |
nicparams <- arbitrary |
|
130 |
-- generate some more networks than the given ones |
|
131 |
num_more_nets <- choose (0,3) |
|
132 |
more_nets <- vectorOf num_more_nets genName |
|
133 |
let partial_nics = map (PartialNic mac ip nicparams . Just) |
|
134 |
(List.nub (nets ++ more_nets)) |
|
135 |
new_inst = plain_inst { instNics = partial_nics } |
|
136 |
return new_inst |
|
137 |
|
|
119 | 138 |
-- | FIXME: This generates completely random data, without normal |
120 | 139 |
-- validation rules. |
121 | 140 |
$(genArbitrary ''PartialISpecParams) |
... | ... | |
216 | 235 |
serial |
217 | 236 |
return c |
218 | 237 |
|
238 |
-- | FIXME: make an even simpler base version of creating a cluster. |
|
239 |
|
|
240 |
-- | Generates config data with a couple of networks. |
|
241 |
genConfigDataWithNetworks :: ConfigData -> Gen ConfigData |
|
242 |
genConfigDataWithNetworks old_cfg = do |
|
243 |
num_nets <- choose (0, 3) |
|
244 |
-- generate a list of network names (no duplicates) |
|
245 |
net_names <- genUniquesList num_nets genName >>= mapM mkNonEmpty |
|
246 |
-- generate a random list of networks (possibly with duplicate names) |
|
247 |
nets <- vectorOf num_nets genValidNetwork |
|
248 |
-- use unique names for the networks |
|
249 |
let nets_unique = map ( \(name, net) -> net { networkName = name } ) |
|
250 |
(zip net_names nets) |
|
251 |
net_map = GenericContainer $ Map.fromList |
|
252 |
(map (\n -> (networkUuid n, n)) nets_unique) |
|
253 |
new_cfg = old_cfg { configNetworks = net_map } |
|
254 |
return new_cfg |
|
255 |
|
|
219 | 256 |
-- * Test properties |
220 | 257 |
|
221 | 258 |
-- | Tests that fillDict behaves correctly |
Also available in: Unified diff