Revision c09359ee
b/src/Ganeti/HTools/Backend/Text.hs | ||
---|---|---|
34 | 34 |
, loadISpec |
35 | 35 |
, loadMultipleMinMaxISpecs |
36 | 36 |
, loadIPolicy |
37 |
, serializeInstance |
|
37 | 38 |
, serializeInstances |
38 | 39 |
, serializeNode |
39 | 40 |
, serializeNodes |
... | ... | |
248 | 249 |
disk_template <- annotateResult ("Instance " ++ name) |
249 | 250 |
(diskTemplateFromRaw dt) |
250 | 251 |
spindle_use <- tryRead name su |
251 |
when (sidx == pidx) . fail $ "Instance " ++ name ++ |
|
252 |
" has same primary and secondary node - " ++ pnode |
|
253 | 252 |
let vtags = commaSplit tags |
254 | 253 |
newinst = Instance.create name vmem vdsk [vdsk] vvcpus vstatus vtags |
255 | 254 |
auto_balance pidx sidx disk_template spindle_use [] |
255 |
when (Instance.hasSecondary newinst && sidx == pidx) . fail $ |
|
256 |
"Instance " ++ name ++ " has same primary and secondary node - " ++ pnode |
|
256 | 257 |
return (name, newinst) |
257 | 258 |
|
258 | 259 |
loadInst ktn [ name, mem, dsk, vcpus, status, auto_bal, pnode, snode |
b/test/hs/Test/Ganeti/HTools/Backend/Text.hs | ||
---|---|---|
38 | 38 |
import Test.Ganeti.TestHelper |
39 | 39 |
import Test.Ganeti.TestCommon |
40 | 40 |
import Test.Ganeti.TestHTools |
41 |
import Test.Ganeti.HTools.Instance (genInstanceSmallerThanNode) |
|
42 |
import Test.Ganeti.HTools.Node (genNode, genOnlineNode) |
|
41 |
import Test.Ganeti.HTools.Instance (genInstanceSmallerThanNode, |
|
42 |
genInstanceOnNodeList) |
|
43 |
import Test.Ganeti.HTools.Node (genNode, genOnlineNode, genUniqueNodeList) |
|
43 | 44 |
|
44 | 45 |
import Ganeti.BasicTypes |
45 | 46 |
import qualified Ganeti.HTools.Backend.Text as Text |
... | ... | |
97 | 98 |
|
98 | 99 |
prop_Load_InstanceFail :: [(String, Int)] -> [String] -> Property |
99 | 100 |
prop_Load_InstanceFail ktn fields = |
100 |
length fields /= 10 && length fields /= 11 ==>
|
|
101 |
length fields < 10 || length fields > 12 ==>
|
|
101 | 102 |
case Text.loadInst nl fields of |
102 | 103 |
Ok _ -> failTest "Managed to load instance from invalid data" |
103 | 104 |
Bad msg -> printTestCase ("Unrecognised error message: " ++ msg) $ |
104 | 105 |
"Invalid/incomplete instance data: '" `isPrefixOf` msg |
105 | 106 |
where nl = Map.fromList ktn |
106 | 107 |
|
108 |
genInstanceNodes :: Gen (Instance.Instance, Node.List, Types.NameAssoc) |
|
109 |
genInstanceNodes = do |
|
110 |
(nl, na) <- genUniqueNodeList genOnlineNode |
|
111 |
inst <- genInstanceOnNodeList nl |
|
112 |
return (inst, nl, na) |
|
113 |
|
|
114 |
prop_InstanceLSIdempotent :: Property |
|
115 |
prop_InstanceLSIdempotent = |
|
116 |
forAll genInstanceNodes $ \(inst, nl, assoc) -> |
|
117 |
(Text.loadInst assoc . Utils.sepSplit '|' . Text.serializeInstance nl) |
|
118 |
inst ==? Ok (Instance.name inst, inst) |
|
119 |
|
|
107 | 120 |
prop_Load_Node :: String -> Int -> Int -> Int -> Int -> Int |
108 | 121 |
-> Int -> Bool -> Bool |
109 | 122 |
prop_Load_Node name tm nm fm td fd tc fo = |
... | ... | |
213 | 226 |
testSuite "HTools/Backend/Text" |
214 | 227 |
[ 'prop_Load_Instance |
215 | 228 |
, 'prop_Load_InstanceFail |
229 |
, 'prop_InstanceLSIdempotent |
|
216 | 230 |
, 'prop_Load_Node |
217 | 231 |
, 'prop_Load_NodeFail |
218 | 232 |
, 'prop_NodeLSIdempotent |
b/test/hs/Test/Ganeti/HTools/Node.hs | ||
---|---|---|
33 | 33 |
, genNode |
34 | 34 |
, genOnlineNode |
35 | 35 |
, genNodeList |
36 |
, genUniqueNodeList |
|
36 | 37 |
) where |
37 | 38 |
|
38 | 39 |
import Test.QuickCheck |
... | ... | |
114 | 115 |
genNodeList ngen = fmap (snd . Loader.assignIndices) names_nodes |
115 | 116 |
where names_nodes = (fmap . map) (\n -> (Node.name n, n)) $ listOf1 ngen |
116 | 117 |
|
118 |
-- | Node list generator where node names are unique |
|
119 |
genUniqueNodeList :: Gen Node.Node -> Gen (Node.List, Types.NameAssoc) |
|
120 |
genUniqueNodeList ngen = (do |
|
121 |
nl <- genNodeList ngen |
|
122 |
let na = (fst . Loader.assignIndices) $ |
|
123 |
map (\n -> (Node.name n, n)) (Container.elems nl) |
|
124 |
return (nl, na)) `suchThat` |
|
125 |
(\(nl, na) -> Container.size nl == Map.size na) |
|
126 |
|
|
117 | 127 |
-- | Generate a node list, an instance list, and a node graph. |
118 | 128 |
-- We choose instances with nodes contained in the node list. |
119 | 129 |
genNodeGraph :: Gen (Maybe Graph.Graph, Node.List, Instance.List) |
Also available in: Unified diff