root / htools / Ganeti / HTools / QC.hs @ c5b4a186
History | View | Annotate | Download (66.2 kB)
1 | 23fe06c2 | Iustin Pop | {-# LANGUAGE TemplateHaskell #-} |
---|---|---|---|
2 | 23fe06c2 | Iustin Pop | |
3 | 525bfb36 | Iustin Pop | {-| Unittests for ganeti-htools. |
4 | e2fa2baf | Iustin Pop | |
5 | e2fa2baf | Iustin Pop | -} |
6 | e2fa2baf | Iustin Pop | |
7 | e2fa2baf | Iustin Pop | {- |
8 | e2fa2baf | Iustin Pop | |
9 | d6eec019 | Iustin Pop | Copyright (C) 2009, 2010, 2011, 2012 Google Inc. |
10 | e2fa2baf | Iustin Pop | |
11 | e2fa2baf | Iustin Pop | This program is free software; you can redistribute it and/or modify |
12 | e2fa2baf | Iustin Pop | it under the terms of the GNU General Public License as published by |
13 | e2fa2baf | Iustin Pop | the Free Software Foundation; either version 2 of the License, or |
14 | e2fa2baf | Iustin Pop | (at your option) any later version. |
15 | e2fa2baf | Iustin Pop | |
16 | e2fa2baf | Iustin Pop | This program is distributed in the hope that it will be useful, but |
17 | e2fa2baf | Iustin Pop | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | e2fa2baf | Iustin Pop | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 | e2fa2baf | Iustin Pop | General Public License for more details. |
20 | e2fa2baf | Iustin Pop | |
21 | e2fa2baf | Iustin Pop | You should have received a copy of the GNU General Public License |
22 | e2fa2baf | Iustin Pop | along with this program; if not, write to the Free Software |
23 | e2fa2baf | Iustin Pop | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
24 | e2fa2baf | Iustin Pop | 02110-1301, USA. |
25 | e2fa2baf | Iustin Pop | |
26 | e2fa2baf | Iustin Pop | -} |
27 | e2fa2baf | Iustin Pop | |
28 | 15f4c8ca | Iustin Pop | module Ganeti.HTools.QC |
29 | d5dfae0a | Iustin Pop | ( testUtils |
30 | d5dfae0a | Iustin Pop | , testPeerMap |
31 | d5dfae0a | Iustin Pop | , testContainer |
32 | d5dfae0a | Iustin Pop | , testInstance |
33 | d5dfae0a | Iustin Pop | , testNode |
34 | d5dfae0a | Iustin Pop | , testText |
35 | e1dde6ad | Iustin Pop | , testSimu |
36 | d5dfae0a | Iustin Pop | , testOpCodes |
37 | d5dfae0a | Iustin Pop | , testJobs |
38 | d5dfae0a | Iustin Pop | , testCluster |
39 | d5dfae0a | Iustin Pop | , testLoader |
40 | d5dfae0a | Iustin Pop | , testTypes |
41 | 8b5a517a | Iustin Pop | , testCLI |
42 | 3ad57194 | Iustin Pop | , testJSON |
43 | cdd495ae | Iustin Pop | , testLUXI |
44 | c5b4a186 | Iustin Pop | , testSsconf |
45 | d5dfae0a | Iustin Pop | ) where |
46 | 15f4c8ca | Iustin Pop | |
47 | 15f4c8ca | Iustin Pop | import Test.QuickCheck |
48 | e1dde6ad | Iustin Pop | import Text.Printf (printf) |
49 | bc782180 | Iustin Pop | import Data.List (findIndex, intercalate, nub, isPrefixOf) |
50 | e1dde6ad | Iustin Pop | import qualified Data.Set as Set |
51 | 15f4c8ca | Iustin Pop | import Data.Maybe |
52 | 88f25dd0 | Iustin Pop | import Control.Monad |
53 | 5cefb2b2 | Iustin Pop | import Control.Applicative |
54 | 89298c04 | Iustin Pop | import qualified System.Console.GetOpt as GetOpt |
55 | 88f25dd0 | Iustin Pop | import qualified Text.JSON as J |
56 | 8fcf251f | Iustin Pop | import qualified Data.Map |
57 | 3fea6959 | Iustin Pop | import qualified Data.IntMap as IntMap |
58 | 89298c04 | Iustin Pop | |
59 | 88f25dd0 | Iustin Pop | import qualified Ganeti.OpCodes as OpCodes |
60 | db079755 | Iustin Pop | import qualified Ganeti.Jobs as Jobs |
61 | cdd495ae | Iustin Pop | import qualified Ganeti.Luxi as Luxi |
62 | c5b4a186 | Iustin Pop | import qualified Ganeti.Ssconf as Ssconf |
63 | 15f4c8ca | Iustin Pop | import qualified Ganeti.HTools.CLI as CLI |
64 | 15f4c8ca | Iustin Pop | import qualified Ganeti.HTools.Cluster as Cluster |
65 | 15f4c8ca | Iustin Pop | import qualified Ganeti.HTools.Container as Container |
66 | 223dbe53 | Iustin Pop | import qualified Ganeti.HTools.ExtLoader |
67 | 15f4c8ca | Iustin Pop | import qualified Ganeti.HTools.IAlloc as IAlloc |
68 | 15f4c8ca | Iustin Pop | import qualified Ganeti.HTools.Instance as Instance |
69 | b69be409 | Iustin Pop | import qualified Ganeti.HTools.JSON as JSON |
70 | 15f4c8ca | Iustin Pop | import qualified Ganeti.HTools.Loader as Loader |
71 | cdd495ae | Iustin Pop | import qualified Ganeti.HTools.Luxi as HTools.Luxi |
72 | 15f4c8ca | Iustin Pop | import qualified Ganeti.HTools.Node as Node |
73 | 10ef6b4e | Iustin Pop | import qualified Ganeti.HTools.Group as Group |
74 | 15f4c8ca | Iustin Pop | import qualified Ganeti.HTools.PeerMap as PeerMap |
75 | c478f837 | Iustin Pop | import qualified Ganeti.HTools.Rapi |
76 | e1dde6ad | Iustin Pop | import qualified Ganeti.HTools.Simu as Simu |
77 | 15f4c8ca | Iustin Pop | import qualified Ganeti.HTools.Text as Text |
78 | 15f4c8ca | Iustin Pop | import qualified Ganeti.HTools.Types as Types |
79 | 15f4c8ca | Iustin Pop | import qualified Ganeti.HTools.Utils as Utils |
80 | 223dbe53 | Iustin Pop | import qualified Ganeti.HTools.Version |
81 | e82271f8 | Iustin Pop | import qualified Ganeti.Constants as C |
82 | 15f4c8ca | Iustin Pop | |
83 | a292b4e0 | Iustin Pop | import qualified Ganeti.HTools.Program as Program |
84 | 33b9d92d | Iustin Pop | import qualified Ganeti.HTools.Program.Hail |
85 | 33b9d92d | Iustin Pop | import qualified Ganeti.HTools.Program.Hbal |
86 | 33b9d92d | Iustin Pop | import qualified Ganeti.HTools.Program.Hscan |
87 | 33b9d92d | Iustin Pop | import qualified Ganeti.HTools.Program.Hspace |
88 | 33b9d92d | Iustin Pop | |
89 | 23fe06c2 | Iustin Pop | import Ganeti.HTools.QCHelper (testSuite) |
90 | 8e4f6d56 | Iustin Pop | |
91 | 3fea6959 | Iustin Pop | -- * Constants |
92 | 3fea6959 | Iustin Pop | |
93 | 525bfb36 | Iustin Pop | -- | Maximum memory (1TiB, somewhat random value). |
94 | 8fcf251f | Iustin Pop | maxMem :: Int |
95 | 8fcf251f | Iustin Pop | maxMem = 1024 * 1024 |
96 | 8fcf251f | Iustin Pop | |
97 | 525bfb36 | Iustin Pop | -- | Maximum disk (8TiB, somewhat random value). |
98 | 8fcf251f | Iustin Pop | maxDsk :: Int |
99 | 49f9627a | Iustin Pop | maxDsk = 1024 * 1024 * 8 |
100 | 8fcf251f | Iustin Pop | |
101 | 525bfb36 | Iustin Pop | -- | Max CPUs (1024, somewhat random value). |
102 | 8fcf251f | Iustin Pop | maxCpu :: Int |
103 | 8fcf251f | Iustin Pop | maxCpu = 1024 |
104 | 8fcf251f | Iustin Pop | |
105 | c22d4dd4 | Iustin Pop | -- | Max vcpu ratio (random value). |
106 | c22d4dd4 | Iustin Pop | maxVcpuRatio :: Double |
107 | c22d4dd4 | Iustin Pop | maxVcpuRatio = 1024.0 |
108 | c22d4dd4 | Iustin Pop | |
109 | c22d4dd4 | Iustin Pop | -- | Max spindle ratio (random value). |
110 | c22d4dd4 | Iustin Pop | maxSpindleRatio :: Double |
111 | c22d4dd4 | Iustin Pop | maxSpindleRatio = 1024.0 |
112 | c22d4dd4 | Iustin Pop | |
113 | 5cefb2b2 | Iustin Pop | -- | Max nodes, used just to limit arbitrary instances for smaller |
114 | 5cefb2b2 | Iustin Pop | -- opcode definitions (e.g. list of nodes in OpTestDelay). |
115 | 5cefb2b2 | Iustin Pop | maxNodes :: Int |
116 | 5cefb2b2 | Iustin Pop | maxNodes = 32 |
117 | 5cefb2b2 | Iustin Pop | |
118 | 5cefb2b2 | Iustin Pop | -- | Max opcodes or jobs in a submit job and submit many jobs. |
119 | 5cefb2b2 | Iustin Pop | maxOpCodes :: Int |
120 | 5cefb2b2 | Iustin Pop | maxOpCodes = 16 |
121 | 5cefb2b2 | Iustin Pop | |
122 | 7806125e | Iustin Pop | -- | All disk templates (used later) |
123 | 7806125e | Iustin Pop | allDiskTemplates :: [Types.DiskTemplate] |
124 | 7806125e | Iustin Pop | allDiskTemplates = [minBound..maxBound] |
125 | 7806125e | Iustin Pop | |
126 | 6cff91f5 | Iustin Pop | -- | Null iPolicy, and by null we mean very liberal. |
127 | 6cff91f5 | Iustin Pop | nullIPolicy = Types.IPolicy |
128 | 6cff91f5 | Iustin Pop | { Types.iPolicyMinSpec = Types.ISpec { Types.iSpecMemorySize = 0 |
129 | 6cff91f5 | Iustin Pop | , Types.iSpecCpuCount = 0 |
130 | 6cff91f5 | Iustin Pop | , Types.iSpecDiskSize = 0 |
131 | 6cff91f5 | Iustin Pop | , Types.iSpecDiskCount = 0 |
132 | 6cff91f5 | Iustin Pop | , Types.iSpecNicCount = 0 |
133 | d953a965 | Renรฉ Nussbaumer | , Types.iSpecSpindleUse = 0 |
134 | 6cff91f5 | Iustin Pop | } |
135 | 6cff91f5 | Iustin Pop | , Types.iPolicyMaxSpec = Types.ISpec { Types.iSpecMemorySize = maxBound |
136 | 6cff91f5 | Iustin Pop | , Types.iSpecCpuCount = maxBound |
137 | 6cff91f5 | Iustin Pop | , Types.iSpecDiskSize = maxBound |
138 | 6cff91f5 | Iustin Pop | , Types.iSpecDiskCount = C.maxDisks |
139 | 6cff91f5 | Iustin Pop | , Types.iSpecNicCount = C.maxNics |
140 | d953a965 | Renรฉ Nussbaumer | , Types.iSpecSpindleUse = maxBound |
141 | 6cff91f5 | Iustin Pop | } |
142 | 6cff91f5 | Iustin Pop | , Types.iPolicyStdSpec = Types.ISpec { Types.iSpecMemorySize = Types.unitMem |
143 | 6cff91f5 | Iustin Pop | , Types.iSpecCpuCount = Types.unitCpu |
144 | 6cff91f5 | Iustin Pop | , Types.iSpecDiskSize = Types.unitDsk |
145 | 6cff91f5 | Iustin Pop | , Types.iSpecDiskCount = 1 |
146 | 6cff91f5 | Iustin Pop | , Types.iSpecNicCount = 1 |
147 | d953a965 | Renรฉ Nussbaumer | , Types.iSpecSpindleUse = 1 |
148 | 6cff91f5 | Iustin Pop | } |
149 | 64946775 | Iustin Pop | , Types.iPolicyDiskTemplates = [minBound..maxBound] |
150 | c22d4dd4 | Iustin Pop | , Types.iPolicyVcpuRatio = maxVcpuRatio -- somewhat random value, high |
151 | c22d4dd4 | Iustin Pop | -- enough to not impact us |
152 | c22d4dd4 | Iustin Pop | , Types.iPolicySpindleRatio = maxSpindleRatio |
153 | 6cff91f5 | Iustin Pop | } |
154 | 6cff91f5 | Iustin Pop | |
155 | 6cff91f5 | Iustin Pop | |
156 | 10ef6b4e | Iustin Pop | defGroup :: Group.Group |
157 | 10ef6b4e | Iustin Pop | defGroup = flip Group.setIdx 0 $ |
158 | f3f76ccc | Iustin Pop | Group.create "default" Types.defaultGroupID Types.AllocPreferred |
159 | 6cff91f5 | Iustin Pop | nullIPolicy |
160 | 10ef6b4e | Iustin Pop | |
161 | 10ef6b4e | Iustin Pop | defGroupList :: Group.List |
162 | cb0c77ff | Iustin Pop | defGroupList = Container.fromList [(Group.idx defGroup, defGroup)] |
163 | 10ef6b4e | Iustin Pop | |
164 | 10ef6b4e | Iustin Pop | defGroupAssoc :: Data.Map.Map String Types.Gdx |
165 | 10ef6b4e | Iustin Pop | defGroupAssoc = Data.Map.singleton (Group.uuid defGroup) (Group.idx defGroup) |
166 | 10ef6b4e | Iustin Pop | |
167 | 3fea6959 | Iustin Pop | -- * Helper functions |
168 | 3fea6959 | Iustin Pop | |
169 | 525bfb36 | Iustin Pop | -- | Simple checker for whether OpResult is fail or pass. |
170 | 79a72ce7 | Iustin Pop | isFailure :: Types.OpResult a -> Bool |
171 | 79a72ce7 | Iustin Pop | isFailure (Types.OpFail _) = True |
172 | 79a72ce7 | Iustin Pop | isFailure _ = False |
173 | 79a72ce7 | Iustin Pop | |
174 | 72bb6b4e | Iustin Pop | -- | Checks for equality with proper annotation. |
175 | 72bb6b4e | Iustin Pop | (==?) :: (Show a, Eq a) => a -> a -> Property |
176 | 72bb6b4e | Iustin Pop | (==?) x y = printTestCase |
177 | 72bb6b4e | Iustin Pop | ("Expected equality, but '" ++ |
178 | 72bb6b4e | Iustin Pop | show x ++ "' /= '" ++ show y ++ "'") (x == y) |
179 | 72bb6b4e | Iustin Pop | infix 3 ==? |
180 | 72bb6b4e | Iustin Pop | |
181 | 96bc2003 | Iustin Pop | -- | Show a message and fail the test. |
182 | 96bc2003 | Iustin Pop | failTest :: String -> Property |
183 | 96bc2003 | Iustin Pop | failTest msg = printTestCase msg False |
184 | 96bc2003 | Iustin Pop | |
185 | 525bfb36 | Iustin Pop | -- | Update an instance to be smaller than a node. |
186 | 3fea6959 | Iustin Pop | setInstanceSmallerThanNode node inst = |
187 | d5dfae0a | Iustin Pop | inst { Instance.mem = Node.availMem node `div` 2 |
188 | d5dfae0a | Iustin Pop | , Instance.dsk = Node.availDisk node `div` 2 |
189 | d5dfae0a | Iustin Pop | , Instance.vcpus = Node.availCpu node `div` 2 |
190 | d5dfae0a | Iustin Pop | } |
191 | 3fea6959 | Iustin Pop | |
192 | 525bfb36 | Iustin Pop | -- | Create an instance given its spec. |
193 | 3fea6959 | Iustin Pop | createInstance mem dsk vcpus = |
194 | d5dfae0a | Iustin Pop | Instance.create "inst-unnamed" mem dsk vcpus Types.Running [] True (-1) (-1) |
195 | 981bb5cf | Renรฉ Nussbaumer | Types.DTDrbd8 1 |
196 | 3fea6959 | Iustin Pop | |
197 | 525bfb36 | Iustin Pop | -- | Create a small cluster by repeating a node spec. |
198 | 3fea6959 | Iustin Pop | makeSmallCluster :: Node.Node -> Int -> Node.List |
199 | 3fea6959 | Iustin Pop | makeSmallCluster node count = |
200 | e73c5fe2 | Iustin Pop | let origname = Node.name node |
201 | e73c5fe2 | Iustin Pop | origalias = Node.alias node |
202 | e73c5fe2 | Iustin Pop | nodes = map (\idx -> node { Node.name = origname ++ "-" ++ show idx |
203 | e73c5fe2 | Iustin Pop | , Node.alias = origalias ++ "-" ++ show idx }) |
204 | e73c5fe2 | Iustin Pop | [1..count] |
205 | e73c5fe2 | Iustin Pop | fn = flip Node.buildPeers Container.empty |
206 | e73c5fe2 | Iustin Pop | namelst = map (\n -> (Node.name n, fn n)) nodes |
207 | d5dfae0a | Iustin Pop | (_, nlst) = Loader.assignIndices namelst |
208 | d5dfae0a | Iustin Pop | in nlst |
209 | 3fea6959 | Iustin Pop | |
210 | 3603605a | Iustin Pop | -- | Make a small cluster, both nodes and instances. |
211 | 3603605a | Iustin Pop | makeSmallEmptyCluster :: Node.Node -> Int -> Instance.Instance |
212 | 3603605a | Iustin Pop | -> (Node.List, Instance.List, Instance.Instance) |
213 | 3603605a | Iustin Pop | makeSmallEmptyCluster node count inst = |
214 | 3603605a | Iustin Pop | (makeSmallCluster node count, Container.empty, |
215 | 3603605a | Iustin Pop | setInstanceSmallerThanNode node inst) |
216 | 3603605a | Iustin Pop | |
217 | 525bfb36 | Iustin Pop | -- | Checks if a node is "big" enough. |
218 | d6f9f5bd | Iustin Pop | isNodeBig :: Int -> Node.Node -> Bool |
219 | d6f9f5bd | Iustin Pop | isNodeBig size node = Node.availDisk node > size * Types.unitDsk |
220 | 3fea6959 | Iustin Pop | && Node.availMem node > size * Types.unitMem |
221 | 3fea6959 | Iustin Pop | && Node.availCpu node > size * Types.unitCpu |
222 | 3fea6959 | Iustin Pop | |
223 | e08424a8 | Guido Trotter | canBalance :: Cluster.Table -> Bool -> Bool -> Bool -> Bool |
224 | e08424a8 | Guido Trotter | canBalance tbl dm im evac = isJust $ Cluster.tryBalance tbl dm im evac 0 0 |
225 | 3fea6959 | Iustin Pop | |
226 | f4161783 | Iustin Pop | -- | Assigns a new fresh instance to a cluster; this is not |
227 | 525bfb36 | Iustin Pop | -- allocation, so no resource checks are done. |
228 | f4161783 | Iustin Pop | assignInstance :: Node.List -> Instance.List -> Instance.Instance -> |
229 | f4161783 | Iustin Pop | Types.Idx -> Types.Idx -> |
230 | f4161783 | Iustin Pop | (Node.List, Instance.List) |
231 | f4161783 | Iustin Pop | assignInstance nl il inst pdx sdx = |
232 | f4161783 | Iustin Pop | let pnode = Container.find pdx nl |
233 | f4161783 | Iustin Pop | snode = Container.find sdx nl |
234 | f4161783 | Iustin Pop | maxiidx = if Container.null il |
235 | d5dfae0a | Iustin Pop | then 0 |
236 | d5dfae0a | Iustin Pop | else fst (Container.findMax il) + 1 |
237 | f4161783 | Iustin Pop | inst' = inst { Instance.idx = maxiidx, |
238 | f4161783 | Iustin Pop | Instance.pNode = pdx, Instance.sNode = sdx } |
239 | f4161783 | Iustin Pop | pnode' = Node.setPri pnode inst' |
240 | f4161783 | Iustin Pop | snode' = Node.setSec snode inst' |
241 | f4161783 | Iustin Pop | nl' = Container.addTwo pdx pnode' sdx snode' nl |
242 | f4161783 | Iustin Pop | il' = Container.add maxiidx inst' il |
243 | f4161783 | Iustin Pop | in (nl', il') |
244 | f4161783 | Iustin Pop | |
245 | a2a0bcd8 | Iustin Pop | -- | Generates a list of a given size with non-duplicate elements. |
246 | a2a0bcd8 | Iustin Pop | genUniquesList :: (Eq a, Arbitrary a) => Int -> Gen [a] |
247 | a2a0bcd8 | Iustin Pop | genUniquesList cnt = |
248 | a2a0bcd8 | Iustin Pop | foldM (\lst _ -> do |
249 | a2a0bcd8 | Iustin Pop | newelem <- arbitrary `suchThat` (`notElem` lst) |
250 | a2a0bcd8 | Iustin Pop | return (newelem:lst)) [] [1..cnt] |
251 | a2a0bcd8 | Iustin Pop | |
252 | ac1c0a07 | Iustin Pop | -- | Checks if an instance is mirrored. |
253 | ac1c0a07 | Iustin Pop | isMirrored :: Instance.Instance -> Bool |
254 | fafd0773 | Iustin Pop | isMirrored = (/= Types.MirrorNone) . Instance.mirrorType |
255 | ac1c0a07 | Iustin Pop | |
256 | ac1c0a07 | Iustin Pop | -- | Returns the possible change node types for a disk template. |
257 | ac1c0a07 | Iustin Pop | evacModeOptions :: Types.MirrorType -> [Types.EvacMode] |
258 | ac1c0a07 | Iustin Pop | evacModeOptions Types.MirrorNone = [] |
259 | ac1c0a07 | Iustin Pop | evacModeOptions Types.MirrorInternal = [minBound..maxBound] -- DRBD can do all |
260 | ac1c0a07 | Iustin Pop | evacModeOptions Types.MirrorExternal = [Types.ChangePrimary, Types.ChangeAll] |
261 | ac1c0a07 | Iustin Pop | |
262 | 3fea6959 | Iustin Pop | -- * Arbitrary instances |
263 | 3fea6959 | Iustin Pop | |
264 | 525bfb36 | Iustin Pop | -- | Defines a DNS name. |
265 | a070c426 | Iustin Pop | newtype DNSChar = DNSChar { dnsGetChar::Char } |
266 | 525bfb36 | Iustin Pop | |
267 | a070c426 | Iustin Pop | instance Arbitrary DNSChar where |
268 | d5dfae0a | Iustin Pop | arbitrary = do |
269 | d5dfae0a | Iustin Pop | x <- elements (['a'..'z'] ++ ['0'..'9'] ++ "_-") |
270 | d5dfae0a | Iustin Pop | return (DNSChar x) |
271 | a070c426 | Iustin Pop | |
272 | a2a0bcd8 | Iustin Pop | -- | Generates a single name component. |
273 | a070c426 | Iustin Pop | getName :: Gen String |
274 | a070c426 | Iustin Pop | getName = do |
275 | a070c426 | Iustin Pop | n <- choose (1, 64) |
276 | 5cefb2b2 | Iustin Pop | dn <- vector n |
277 | a070c426 | Iustin Pop | return (map dnsGetChar dn) |
278 | a070c426 | Iustin Pop | |
279 | a2a0bcd8 | Iustin Pop | -- | Generates an entire FQDN. |
280 | a070c426 | Iustin Pop | getFQDN :: Gen String |
281 | a070c426 | Iustin Pop | getFQDN = do |
282 | a070c426 | Iustin Pop | ncomps <- choose (1, 4) |
283 | 5cefb2b2 | Iustin Pop | names <- vectorOf ncomps getName |
284 | a2a0bcd8 | Iustin Pop | return $ intercalate "." names |
285 | a070c426 | Iustin Pop | |
286 | 5cefb2b2 | Iustin Pop | -- | Combinator that generates a 'Maybe' using a sub-combinator. |
287 | 5cefb2b2 | Iustin Pop | getMaybe :: Gen a -> Gen (Maybe a) |
288 | 5cefb2b2 | Iustin Pop | getMaybe subgen = do |
289 | 5cefb2b2 | Iustin Pop | bool <- arbitrary |
290 | 5cefb2b2 | Iustin Pop | if bool |
291 | 5cefb2b2 | Iustin Pop | then Just <$> subgen |
292 | 5cefb2b2 | Iustin Pop | else return Nothing |
293 | 5cefb2b2 | Iustin Pop | |
294 | 5cefb2b2 | Iustin Pop | -- | Generates a fields list. This uses the same character set as a |
295 | 5cefb2b2 | Iustin Pop | -- DNS name (just for simplicity). |
296 | 5cefb2b2 | Iustin Pop | getFields :: Gen [String] |
297 | 5cefb2b2 | Iustin Pop | getFields = do |
298 | 5cefb2b2 | Iustin Pop | n <- choose (1, 32) |
299 | 5cefb2b2 | Iustin Pop | vectorOf n getName |
300 | 5cefb2b2 | Iustin Pop | |
301 | dce9bbb3 | Iustin Pop | -- | Defines a tag type. |
302 | dce9bbb3 | Iustin Pop | newtype TagChar = TagChar { tagGetChar :: Char } |
303 | dce9bbb3 | Iustin Pop | |
304 | dce9bbb3 | Iustin Pop | -- | All valid tag chars. This doesn't need to match _exactly_ |
305 | dce9bbb3 | Iustin Pop | -- Ganeti's own tag regex, just enough for it to be close. |
306 | dce9bbb3 | Iustin Pop | tagChar :: [Char] |
307 | dce9bbb3 | Iustin Pop | tagChar = ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ ".+*/:@-" |
308 | dce9bbb3 | Iustin Pop | |
309 | dce9bbb3 | Iustin Pop | instance Arbitrary TagChar where |
310 | dce9bbb3 | Iustin Pop | arbitrary = do |
311 | dce9bbb3 | Iustin Pop | c <- elements tagChar |
312 | dce9bbb3 | Iustin Pop | return (TagChar c) |
313 | dce9bbb3 | Iustin Pop | |
314 | dce9bbb3 | Iustin Pop | -- | Generates a tag |
315 | dce9bbb3 | Iustin Pop | genTag :: Gen [TagChar] |
316 | dce9bbb3 | Iustin Pop | genTag = do |
317 | dce9bbb3 | Iustin Pop | -- the correct value would be C.maxTagLen, but that's way too |
318 | dce9bbb3 | Iustin Pop | -- verbose in unittests, and at the moment I don't see any possible |
319 | dce9bbb3 | Iustin Pop | -- bugs with longer tags and the way we use tags in htools |
320 | dce9bbb3 | Iustin Pop | n <- choose (1, 10) |
321 | dce9bbb3 | Iustin Pop | vector n |
322 | dce9bbb3 | Iustin Pop | |
323 | dce9bbb3 | Iustin Pop | -- | Generates a list of tags (correctly upper bounded). |
324 | dce9bbb3 | Iustin Pop | genTags :: Gen [String] |
325 | dce9bbb3 | Iustin Pop | genTags = do |
326 | dce9bbb3 | Iustin Pop | -- the correct value would be C.maxTagsPerObj, but per the comment |
327 | dce9bbb3 | Iustin Pop | -- in genTag, we don't use tags enough in htools to warrant testing |
328 | dce9bbb3 | Iustin Pop | -- such big values |
329 | dce9bbb3 | Iustin Pop | n <- choose (0, 10::Int) |
330 | dce9bbb3 | Iustin Pop | tags <- mapM (const genTag) [1..n] |
331 | dce9bbb3 | Iustin Pop | return $ map (map tagGetChar) tags |
332 | dce9bbb3 | Iustin Pop | |
333 | 7dd14211 | Agata Murawska | instance Arbitrary Types.InstanceStatus where |
334 | e1bf27bb | Agata Murawska | arbitrary = elements [minBound..maxBound] |
335 | 7dd14211 | Agata Murawska | |
336 | 59ed268d | Iustin Pop | -- | Generates a random instance with maximum disk/mem/cpu values. |
337 | 59ed268d | Iustin Pop | genInstanceSmallerThan :: Int -> Int -> Int -> Gen Instance.Instance |
338 | 59ed268d | Iustin Pop | genInstanceSmallerThan lim_mem lim_dsk lim_cpu = do |
339 | 59ed268d | Iustin Pop | name <- getFQDN |
340 | 59ed268d | Iustin Pop | mem <- choose (0, lim_mem) |
341 | 59ed268d | Iustin Pop | dsk <- choose (0, lim_dsk) |
342 | 59ed268d | Iustin Pop | run_st <- arbitrary |
343 | 59ed268d | Iustin Pop | pn <- arbitrary |
344 | 59ed268d | Iustin Pop | sn <- arbitrary |
345 | 59ed268d | Iustin Pop | vcpus <- choose (0, lim_cpu) |
346 | 64946775 | Iustin Pop | dt <- arbitrary |
347 | 64946775 | Iustin Pop | return $ Instance.create name mem dsk vcpus run_st [] True pn sn dt 1 |
348 | 59ed268d | Iustin Pop | |
349 | 59ed268d | Iustin Pop | -- | Generates an instance smaller than a node. |
350 | 59ed268d | Iustin Pop | genInstanceSmallerThanNode :: Node.Node -> Gen Instance.Instance |
351 | 59ed268d | Iustin Pop | genInstanceSmallerThanNode node = |
352 | 59ed268d | Iustin Pop | genInstanceSmallerThan (Node.availMem node `div` 2) |
353 | 59ed268d | Iustin Pop | (Node.availDisk node `div` 2) |
354 | 59ed268d | Iustin Pop | (Node.availCpu node `div` 2) |
355 | 59ed268d | Iustin Pop | |
356 | 15f4c8ca | Iustin Pop | -- let's generate a random instance |
357 | 15f4c8ca | Iustin Pop | instance Arbitrary Instance.Instance where |
358 | 59ed268d | Iustin Pop | arbitrary = genInstanceSmallerThan maxMem maxDsk maxCpu |
359 | 15f4c8ca | Iustin Pop | |
360 | 525bfb36 | Iustin Pop | -- | Generas an arbitrary node based on sizing information. |
361 | 525bfb36 | Iustin Pop | genNode :: Maybe Int -- ^ Minimum node size in terms of units |
362 | 525bfb36 | Iustin Pop | -> Maybe Int -- ^ Maximum node size (when Nothing, bounded |
363 | 525bfb36 | Iustin Pop | -- just by the max... constants) |
364 | 525bfb36 | Iustin Pop | -> Gen Node.Node |
365 | 00c75986 | Iustin Pop | genNode min_multiplier max_multiplier = do |
366 | 00c75986 | Iustin Pop | let (base_mem, base_dsk, base_cpu) = |
367 | d5dfae0a | Iustin Pop | case min_multiplier of |
368 | d5dfae0a | Iustin Pop | Just mm -> (mm * Types.unitMem, |
369 | d5dfae0a | Iustin Pop | mm * Types.unitDsk, |
370 | d5dfae0a | Iustin Pop | mm * Types.unitCpu) |
371 | d5dfae0a | Iustin Pop | Nothing -> (0, 0, 0) |
372 | 00c75986 | Iustin Pop | (top_mem, top_dsk, top_cpu) = |
373 | d5dfae0a | Iustin Pop | case max_multiplier of |
374 | d5dfae0a | Iustin Pop | Just mm -> (mm * Types.unitMem, |
375 | d5dfae0a | Iustin Pop | mm * Types.unitDsk, |
376 | d5dfae0a | Iustin Pop | mm * Types.unitCpu) |
377 | d5dfae0a | Iustin Pop | Nothing -> (maxMem, maxDsk, maxCpu) |
378 | 00c75986 | Iustin Pop | name <- getFQDN |
379 | 00c75986 | Iustin Pop | mem_t <- choose (base_mem, top_mem) |
380 | 00c75986 | Iustin Pop | mem_f <- choose (base_mem, mem_t) |
381 | 00c75986 | Iustin Pop | mem_n <- choose (0, mem_t - mem_f) |
382 | 00c75986 | Iustin Pop | dsk_t <- choose (base_dsk, top_dsk) |
383 | 00c75986 | Iustin Pop | dsk_f <- choose (base_dsk, dsk_t) |
384 | 00c75986 | Iustin Pop | cpu_t <- choose (base_cpu, top_cpu) |
385 | 00c75986 | Iustin Pop | offl <- arbitrary |
386 | 00c75986 | Iustin Pop | let n = Node.create name (fromIntegral mem_t) mem_n mem_f |
387 | 8bc34c7b | Iustin Pop | (fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) offl 1 0 |
388 | d6eec019 | Iustin Pop | n' = Node.setPolicy nullIPolicy n |
389 | d6eec019 | Iustin Pop | return $ Node.buildPeers n' Container.empty |
390 | 00c75986 | Iustin Pop | |
391 | d6f9f5bd | Iustin Pop | -- | Helper function to generate a sane node. |
392 | d6f9f5bd | Iustin Pop | genOnlineNode :: Gen Node.Node |
393 | d6f9f5bd | Iustin Pop | genOnlineNode = do |
394 | d6f9f5bd | Iustin Pop | arbitrary `suchThat` (\n -> not (Node.offline n) && |
395 | d6f9f5bd | Iustin Pop | not (Node.failN1 n) && |
396 | d6f9f5bd | Iustin Pop | Node.availDisk n > 0 && |
397 | d6f9f5bd | Iustin Pop | Node.availMem n > 0 && |
398 | d6f9f5bd | Iustin Pop | Node.availCpu n > 0) |
399 | d6f9f5bd | Iustin Pop | |
400 | 15f4c8ca | Iustin Pop | -- and a random node |
401 | 15f4c8ca | Iustin Pop | instance Arbitrary Node.Node where |
402 | d5dfae0a | Iustin Pop | arbitrary = genNode Nothing Nothing |
403 | 15f4c8ca | Iustin Pop | |
404 | 88f25dd0 | Iustin Pop | -- replace disks |
405 | 88f25dd0 | Iustin Pop | instance Arbitrary OpCodes.ReplaceDisksMode where |
406 | e1bf27bb | Agata Murawska | arbitrary = elements [minBound..maxBound] |
407 | 88f25dd0 | Iustin Pop | |
408 | 88f25dd0 | Iustin Pop | instance Arbitrary OpCodes.OpCode where |
409 | 88f25dd0 | Iustin Pop | arbitrary = do |
410 | 88f25dd0 | Iustin Pop | op_id <- elements [ "OP_TEST_DELAY" |
411 | 88f25dd0 | Iustin Pop | , "OP_INSTANCE_REPLACE_DISKS" |
412 | 88f25dd0 | Iustin Pop | , "OP_INSTANCE_FAILOVER" |
413 | 88f25dd0 | Iustin Pop | , "OP_INSTANCE_MIGRATE" |
414 | 88f25dd0 | Iustin Pop | ] |
415 | 3603605a | Iustin Pop | case op_id of |
416 | 3603605a | Iustin Pop | "OP_TEST_DELAY" -> |
417 | 5cefb2b2 | Iustin Pop | OpCodes.OpTestDelay <$> arbitrary <*> arbitrary |
418 | 5cefb2b2 | Iustin Pop | <*> resize maxNodes (listOf getFQDN) |
419 | 3603605a | Iustin Pop | "OP_INSTANCE_REPLACE_DISKS" -> |
420 | 5cefb2b2 | Iustin Pop | OpCodes.OpInstanceReplaceDisks <$> getFQDN <*> getMaybe getFQDN <*> |
421 | 5cefb2b2 | Iustin Pop | arbitrary <*> resize C.maxDisks arbitrary <*> getMaybe getName |
422 | 3603605a | Iustin Pop | "OP_INSTANCE_FAILOVER" -> |
423 | 5cefb2b2 | Iustin Pop | OpCodes.OpInstanceFailover <$> getFQDN <*> arbitrary <*> |
424 | 5cefb2b2 | Iustin Pop | getMaybe getFQDN |
425 | 3603605a | Iustin Pop | "OP_INSTANCE_MIGRATE" -> |
426 | 5cefb2b2 | Iustin Pop | OpCodes.OpInstanceMigrate <$> getFQDN <*> arbitrary <*> |
427 | 5cefb2b2 | Iustin Pop | arbitrary <*> arbitrary <*> getMaybe getFQDN |
428 | 3603605a | Iustin Pop | _ -> fail "Wrong opcode" |
429 | 88f25dd0 | Iustin Pop | |
430 | db079755 | Iustin Pop | instance Arbitrary Jobs.OpStatus where |
431 | db079755 | Iustin Pop | arbitrary = elements [minBound..maxBound] |
432 | db079755 | Iustin Pop | |
433 | db079755 | Iustin Pop | instance Arbitrary Jobs.JobStatus where |
434 | db079755 | Iustin Pop | arbitrary = elements [minBound..maxBound] |
435 | db079755 | Iustin Pop | |
436 | 525bfb36 | Iustin Pop | newtype SmallRatio = SmallRatio Double deriving Show |
437 | 525bfb36 | Iustin Pop | instance Arbitrary SmallRatio where |
438 | d5dfae0a | Iustin Pop | arbitrary = do |
439 | d5dfae0a | Iustin Pop | v <- choose (0, 1) |
440 | d5dfae0a | Iustin Pop | return $ SmallRatio v |
441 | 525bfb36 | Iustin Pop | |
442 | 3c002a13 | Iustin Pop | instance Arbitrary Types.AllocPolicy where |
443 | 3c002a13 | Iustin Pop | arbitrary = elements [minBound..maxBound] |
444 | 3c002a13 | Iustin Pop | |
445 | 3c002a13 | Iustin Pop | instance Arbitrary Types.DiskTemplate where |
446 | 3c002a13 | Iustin Pop | arbitrary = elements [minBound..maxBound] |
447 | 3c002a13 | Iustin Pop | |
448 | 0047d4e2 | Iustin Pop | instance Arbitrary Types.FailMode where |
449 | d5dfae0a | Iustin Pop | arbitrary = elements [minBound..maxBound] |
450 | 0047d4e2 | Iustin Pop | |
451 | aa1d552d | Iustin Pop | instance Arbitrary Types.EvacMode where |
452 | aa1d552d | Iustin Pop | arbitrary = elements [minBound..maxBound] |
453 | aa1d552d | Iustin Pop | |
454 | 0047d4e2 | Iustin Pop | instance Arbitrary a => Arbitrary (Types.OpResult a) where |
455 | d5dfae0a | Iustin Pop | arbitrary = arbitrary >>= \c -> |
456 | 3603605a | Iustin Pop | if c |
457 | 5cefb2b2 | Iustin Pop | then Types.OpGood <$> arbitrary |
458 | 5cefb2b2 | Iustin Pop | else Types.OpFail <$> arbitrary |
459 | 0047d4e2 | Iustin Pop | |
460 | 00b70680 | Iustin Pop | instance Arbitrary Types.ISpec where |
461 | 00b70680 | Iustin Pop | arbitrary = do |
462 | 7806125e | Iustin Pop | mem_s <- arbitrary::Gen (NonNegative Int) |
463 | 00b70680 | Iustin Pop | dsk_c <- arbitrary::Gen (NonNegative Int) |
464 | 00b70680 | Iustin Pop | dsk_s <- arbitrary::Gen (NonNegative Int) |
465 | 7806125e | Iustin Pop | cpu_c <- arbitrary::Gen (NonNegative Int) |
466 | 7806125e | Iustin Pop | nic_c <- arbitrary::Gen (NonNegative Int) |
467 | d953a965 | Renรฉ Nussbaumer | su <- arbitrary::Gen (NonNegative Int) |
468 | 7806125e | Iustin Pop | return Types.ISpec { Types.iSpecMemorySize = fromIntegral mem_s |
469 | 7806125e | Iustin Pop | , Types.iSpecCpuCount = fromIntegral cpu_c |
470 | 00b70680 | Iustin Pop | , Types.iSpecDiskSize = fromIntegral dsk_s |
471 | 00b70680 | Iustin Pop | , Types.iSpecDiskCount = fromIntegral dsk_c |
472 | 7806125e | Iustin Pop | , Types.iSpecNicCount = fromIntegral nic_c |
473 | d953a965 | Renรฉ Nussbaumer | , Types.iSpecSpindleUse = fromIntegral su |
474 | 00b70680 | Iustin Pop | } |
475 | 00b70680 | Iustin Pop | |
476 | 7806125e | Iustin Pop | -- | Generates an ispec bigger than the given one. |
477 | 7806125e | Iustin Pop | genBiggerISpec :: Types.ISpec -> Gen Types.ISpec |
478 | 7806125e | Iustin Pop | genBiggerISpec imin = do |
479 | 7806125e | Iustin Pop | mem_s <- choose (Types.iSpecMemorySize imin, maxBound) |
480 | 7806125e | Iustin Pop | dsk_c <- choose (Types.iSpecDiskCount imin, maxBound) |
481 | 7806125e | Iustin Pop | dsk_s <- choose (Types.iSpecDiskSize imin, maxBound) |
482 | 7806125e | Iustin Pop | cpu_c <- choose (Types.iSpecCpuCount imin, maxBound) |
483 | 7806125e | Iustin Pop | nic_c <- choose (Types.iSpecNicCount imin, maxBound) |
484 | d953a965 | Renรฉ Nussbaumer | su <- choose (Types.iSpecSpindleUse imin, maxBound) |
485 | 7806125e | Iustin Pop | return Types.ISpec { Types.iSpecMemorySize = fromIntegral mem_s |
486 | 7806125e | Iustin Pop | , Types.iSpecCpuCount = fromIntegral cpu_c |
487 | 7806125e | Iustin Pop | , Types.iSpecDiskSize = fromIntegral dsk_s |
488 | 7806125e | Iustin Pop | , Types.iSpecDiskCount = fromIntegral dsk_c |
489 | 7806125e | Iustin Pop | , Types.iSpecNicCount = fromIntegral nic_c |
490 | d953a965 | Renรฉ Nussbaumer | , Types.iSpecSpindleUse = fromIntegral su |
491 | 7806125e | Iustin Pop | } |
492 | 00b70680 | Iustin Pop | |
493 | 00b70680 | Iustin Pop | instance Arbitrary Types.IPolicy where |
494 | 00b70680 | Iustin Pop | arbitrary = do |
495 | 00b70680 | Iustin Pop | imin <- arbitrary |
496 | 7806125e | Iustin Pop | istd <- genBiggerISpec imin |
497 | 7806125e | Iustin Pop | imax <- genBiggerISpec istd |
498 | 7806125e | Iustin Pop | num_tmpl <- choose (0, length allDiskTemplates) |
499 | 7806125e | Iustin Pop | dts <- genUniquesList num_tmpl |
500 | c22d4dd4 | Iustin Pop | vcpu_ratio <- choose (1.0, maxVcpuRatio) |
501 | c22d4dd4 | Iustin Pop | spindle_ratio <- choose (1.0, maxSpindleRatio) |
502 | 00b70680 | Iustin Pop | return Types.IPolicy { Types.iPolicyMinSpec = imin |
503 | 00b70680 | Iustin Pop | , Types.iPolicyStdSpec = istd |
504 | 00b70680 | Iustin Pop | , Types.iPolicyMaxSpec = imax |
505 | 00b70680 | Iustin Pop | , Types.iPolicyDiskTemplates = dts |
506 | e8fa4ff6 | Iustin Pop | , Types.iPolicyVcpuRatio = vcpu_ratio |
507 | c22d4dd4 | Iustin Pop | , Types.iPolicySpindleRatio = spindle_ratio |
508 | 00b70680 | Iustin Pop | } |
509 | 00b70680 | Iustin Pop | |
510 | 3fea6959 | Iustin Pop | -- * Actual tests |
511 | 8fcf251f | Iustin Pop | |
512 | 525bfb36 | Iustin Pop | -- ** Utils tests |
513 | 525bfb36 | Iustin Pop | |
514 | 468b828e | Iustin Pop | -- | Helper to generate a small string that doesn't contain commas. |
515 | 468b828e | Iustin Pop | genNonCommaString = do |
516 | 468b828e | Iustin Pop | size <- choose (0, 20) -- arbitrary max size |
517 | 468b828e | Iustin Pop | vectorOf size (arbitrary `suchThat` ((/=) ',')) |
518 | 468b828e | Iustin Pop | |
519 | 525bfb36 | Iustin Pop | -- | If the list is not just an empty element, and if the elements do |
520 | 525bfb36 | Iustin Pop | -- not contain commas, then join+split should be idempotent. |
521 | a1cd7c1e | Iustin Pop | prop_Utils_commaJoinSplit = |
522 | 468b828e | Iustin Pop | forAll (choose (0, 20)) $ \llen -> |
523 | 468b828e | Iustin Pop | forAll (vectorOf llen genNonCommaString `suchThat` ((/=) [""])) $ \lst -> |
524 | d5dfae0a | Iustin Pop | Utils.sepSplit ',' (Utils.commaJoin lst) ==? lst |
525 | a1cd7c1e | Iustin Pop | |
526 | 525bfb36 | Iustin Pop | -- | Split and join should always be idempotent. |
527 | 72bb6b4e | Iustin Pop | prop_Utils_commaSplitJoin s = |
528 | d5dfae0a | Iustin Pop | Utils.commaJoin (Utils.sepSplit ',' s) ==? s |
529 | 691dcd2a | Iustin Pop | |
530 | a810ad21 | Iustin Pop | -- | fromObjWithDefault, we test using the Maybe monad and an integer |
531 | 525bfb36 | Iustin Pop | -- value. |
532 | a810ad21 | Iustin Pop | prop_Utils_fromObjWithDefault def_value random_key = |
533 | d5dfae0a | Iustin Pop | -- a missing key will be returned with the default |
534 | b69be409 | Iustin Pop | JSON.fromObjWithDefault [] random_key def_value == Just def_value && |
535 | d5dfae0a | Iustin Pop | -- a found key will be returned as is, not with default |
536 | b69be409 | Iustin Pop | JSON.fromObjWithDefault [(random_key, J.showJSON def_value)] |
537 | d5dfae0a | Iustin Pop | random_key (def_value+1) == Just def_value |
538 | d5dfae0a | Iustin Pop | where _types = def_value :: Integer |
539 | a810ad21 | Iustin Pop | |
540 | bfe6c954 | Guido Trotter | -- | Test that functional if' behaves like the syntactic sugar if. |
541 | 72bb6b4e | Iustin Pop | prop_Utils_if'if :: Bool -> Int -> Int -> Gen Prop |
542 | 72bb6b4e | Iustin Pop | prop_Utils_if'if cnd a b = |
543 | d5dfae0a | Iustin Pop | Utils.if' cnd a b ==? if cnd then a else b |
544 | bfe6c954 | Guido Trotter | |
545 | 22fac87d | Guido Trotter | -- | Test basic select functionality |
546 | 72bb6b4e | Iustin Pop | prop_Utils_select :: Int -- ^ Default result |
547 | 72bb6b4e | Iustin Pop | -> [Int] -- ^ List of False values |
548 | 72bb6b4e | Iustin Pop | -> [Int] -- ^ List of True values |
549 | 72bb6b4e | Iustin Pop | -> Gen Prop -- ^ Test result |
550 | 22fac87d | Guido Trotter | prop_Utils_select def lst1 lst2 = |
551 | 3603605a | Iustin Pop | Utils.select def (flist ++ tlist) ==? expectedresult |
552 | ba1260ba | Iustin Pop | where expectedresult = Utils.if' (null lst2) def (head lst2) |
553 | ba1260ba | Iustin Pop | flist = zip (repeat False) lst1 |
554 | ba1260ba | Iustin Pop | tlist = zip (repeat True) lst2 |
555 | 22fac87d | Guido Trotter | |
556 | 22fac87d | Guido Trotter | -- | Test basic select functionality with undefined default |
557 | 72bb6b4e | Iustin Pop | prop_Utils_select_undefd :: [Int] -- ^ List of False values |
558 | 22fac87d | Guido Trotter | -> NonEmptyList Int -- ^ List of True values |
559 | 72bb6b4e | Iustin Pop | -> Gen Prop -- ^ Test result |
560 | 22fac87d | Guido Trotter | prop_Utils_select_undefd lst1 (NonEmpty lst2) = |
561 | 3603605a | Iustin Pop | Utils.select undefined (flist ++ tlist) ==? head lst2 |
562 | ba1260ba | Iustin Pop | where flist = zip (repeat False) lst1 |
563 | ba1260ba | Iustin Pop | tlist = zip (repeat True) lst2 |
564 | 22fac87d | Guido Trotter | |
565 | 22fac87d | Guido Trotter | -- | Test basic select functionality with undefined list values |
566 | 72bb6b4e | Iustin Pop | prop_Utils_select_undefv :: [Int] -- ^ List of False values |
567 | 22fac87d | Guido Trotter | -> NonEmptyList Int -- ^ List of True values |
568 | 72bb6b4e | Iustin Pop | -> Gen Prop -- ^ Test result |
569 | 22fac87d | Guido Trotter | prop_Utils_select_undefv lst1 (NonEmpty lst2) = |
570 | 72bb6b4e | Iustin Pop | Utils.select undefined cndlist ==? head lst2 |
571 | ba1260ba | Iustin Pop | where flist = zip (repeat False) lst1 |
572 | ba1260ba | Iustin Pop | tlist = zip (repeat True) lst2 |
573 | ba1260ba | Iustin Pop | cndlist = flist ++ tlist ++ [undefined] |
574 | bfe6c954 | Guido Trotter | |
575 | 1cb92fac | Iustin Pop | prop_Utils_parseUnit (NonNegative n) = |
576 | 1cdcf8f3 | Iustin Pop | Utils.parseUnit (show n) ==? Types.Ok n .&&. |
577 | 1cdcf8f3 | Iustin Pop | Utils.parseUnit (show n ++ "m") ==? Types.Ok n .&&. |
578 | 1cdcf8f3 | Iustin Pop | Utils.parseUnit (show n ++ "M") ==? Types.Ok (truncate n_mb::Int) .&&. |
579 | 1cdcf8f3 | Iustin Pop | Utils.parseUnit (show n ++ "g") ==? Types.Ok (n*1024) .&&. |
580 | 1cdcf8f3 | Iustin Pop | Utils.parseUnit (show n ++ "G") ==? Types.Ok (truncate n_gb::Int) .&&. |
581 | 1cdcf8f3 | Iustin Pop | Utils.parseUnit (show n ++ "t") ==? Types.Ok (n*1048576) .&&. |
582 | 1cdcf8f3 | Iustin Pop | Utils.parseUnit (show n ++ "T") ==? Types.Ok (truncate n_tb::Int) .&&. |
583 | 1cdcf8f3 | Iustin Pop | printTestCase "Internal error/overflow?" |
584 | 1cdcf8f3 | Iustin Pop | (n_mb >=0 && n_gb >= 0 && n_tb >= 0) .&&. |
585 | 1cdcf8f3 | Iustin Pop | property (Types.isBad (Utils.parseUnit (show n ++ "x")::Types.Result Int)) |
586 | 1cdcf8f3 | Iustin Pop | where _types = (n::Int) |
587 | 1cdcf8f3 | Iustin Pop | n_mb = (fromIntegral n::Rational) * 1000 * 1000 / 1024 / 1024 |
588 | 1cdcf8f3 | Iustin Pop | n_gb = n_mb * 1000 |
589 | 1cdcf8f3 | Iustin Pop | n_tb = n_gb * 1000 |
590 | 1cb92fac | Iustin Pop | |
591 | 525bfb36 | Iustin Pop | -- | Test list for the Utils module. |
592 | 23fe06c2 | Iustin Pop | testSuite "Utils" |
593 | d5dfae0a | Iustin Pop | [ 'prop_Utils_commaJoinSplit |
594 | d5dfae0a | Iustin Pop | , 'prop_Utils_commaSplitJoin |
595 | d5dfae0a | Iustin Pop | , 'prop_Utils_fromObjWithDefault |
596 | d5dfae0a | Iustin Pop | , 'prop_Utils_if'if |
597 | d5dfae0a | Iustin Pop | , 'prop_Utils_select |
598 | d5dfae0a | Iustin Pop | , 'prop_Utils_select_undefd |
599 | d5dfae0a | Iustin Pop | , 'prop_Utils_select_undefv |
600 | d5dfae0a | Iustin Pop | , 'prop_Utils_parseUnit |
601 | d5dfae0a | Iustin Pop | ] |
602 | 691dcd2a | Iustin Pop | |
603 | 525bfb36 | Iustin Pop | -- ** PeerMap tests |
604 | 525bfb36 | Iustin Pop | |
605 | 525bfb36 | Iustin Pop | -- | Make sure add is idempotent. |
606 | fbb95f28 | Iustin Pop | prop_PeerMap_addIdempotent pmap key em = |
607 | d5dfae0a | Iustin Pop | fn puniq ==? fn (fn puniq) |
608 | 7bc82927 | Iustin Pop | where _types = (pmap::PeerMap.PeerMap, |
609 | fbb95f28 | Iustin Pop | key::PeerMap.Key, em::PeerMap.Elem) |
610 | fbb95f28 | Iustin Pop | fn = PeerMap.add key em |
611 | 7bc82927 | Iustin Pop | puniq = PeerMap.accumArray const pmap |
612 | 15f4c8ca | Iustin Pop | |
613 | 525bfb36 | Iustin Pop | -- | Make sure remove is idempotent. |
614 | 15f4c8ca | Iustin Pop | prop_PeerMap_removeIdempotent pmap key = |
615 | d5dfae0a | Iustin Pop | fn puniq ==? fn (fn puniq) |
616 | 7bc82927 | Iustin Pop | where _types = (pmap::PeerMap.PeerMap, key::PeerMap.Key) |
617 | 7bc82927 | Iustin Pop | fn = PeerMap.remove key |
618 | 15f4c8ca | Iustin Pop | puniq = PeerMap.accumArray const pmap |
619 | 15f4c8ca | Iustin Pop | |
620 | 525bfb36 | Iustin Pop | -- | Make sure a missing item returns 0. |
621 | 15f4c8ca | Iustin Pop | prop_PeerMap_findMissing pmap key = |
622 | d5dfae0a | Iustin Pop | PeerMap.find key (PeerMap.remove key puniq) ==? 0 |
623 | 7bc82927 | Iustin Pop | where _types = (pmap::PeerMap.PeerMap, key::PeerMap.Key) |
624 | 15f4c8ca | Iustin Pop | puniq = PeerMap.accumArray const pmap |
625 | 15f4c8ca | Iustin Pop | |
626 | 525bfb36 | Iustin Pop | -- | Make sure an added item is found. |
627 | fbb95f28 | Iustin Pop | prop_PeerMap_addFind pmap key em = |
628 | d5dfae0a | Iustin Pop | PeerMap.find key (PeerMap.add key em puniq) ==? em |
629 | 7bc82927 | Iustin Pop | where _types = (pmap::PeerMap.PeerMap, |
630 | fbb95f28 | Iustin Pop | key::PeerMap.Key, em::PeerMap.Elem) |
631 | 7bc82927 | Iustin Pop | puniq = PeerMap.accumArray const pmap |
632 | 15f4c8ca | Iustin Pop | |
633 | 525bfb36 | Iustin Pop | -- | Manual check that maxElem returns the maximum indeed, or 0 for null. |
634 | 15f4c8ca | Iustin Pop | prop_PeerMap_maxElem pmap = |
635 | d5dfae0a | Iustin Pop | PeerMap.maxElem puniq ==? if null puniq then 0 |
636 | 72bb6b4e | Iustin Pop | else (maximum . snd . unzip) puniq |
637 | 7bc82927 | Iustin Pop | where _types = pmap::PeerMap.PeerMap |
638 | 15f4c8ca | Iustin Pop | puniq = PeerMap.accumArray const pmap |
639 | 15f4c8ca | Iustin Pop | |
640 | 525bfb36 | Iustin Pop | -- | List of tests for the PeerMap module. |
641 | 23fe06c2 | Iustin Pop | testSuite "PeerMap" |
642 | d5dfae0a | Iustin Pop | [ 'prop_PeerMap_addIdempotent |
643 | d5dfae0a | Iustin Pop | , 'prop_PeerMap_removeIdempotent |
644 | d5dfae0a | Iustin Pop | , 'prop_PeerMap_maxElem |
645 | d5dfae0a | Iustin Pop | , 'prop_PeerMap_addFind |
646 | d5dfae0a | Iustin Pop | , 'prop_PeerMap_findMissing |
647 | d5dfae0a | Iustin Pop | ] |
648 | 7dd5ee6c | Iustin Pop | |
649 | 525bfb36 | Iustin Pop | -- ** Container tests |
650 | 095d7ac0 | Iustin Pop | |
651 | 3603605a | Iustin Pop | -- we silence the following due to hlint bug fixed in later versions |
652 | 3603605a | Iustin Pop | {-# ANN prop_Container_addTwo "HLint: ignore Avoid lambda" #-} |
653 | 095d7ac0 | Iustin Pop | prop_Container_addTwo cdata i1 i2 = |
654 | d5dfae0a | Iustin Pop | fn i1 i2 cont == fn i2 i1 cont && |
655 | d5dfae0a | Iustin Pop | fn i1 i2 cont == fn i1 i2 (fn i1 i2 cont) |
656 | 095d7ac0 | Iustin Pop | where _types = (cdata::[Int], |
657 | 095d7ac0 | Iustin Pop | i1::Int, i2::Int) |
658 | 095d7ac0 | Iustin Pop | cont = foldl (\c x -> Container.add x x c) Container.empty cdata |
659 | 095d7ac0 | Iustin Pop | fn x1 x2 = Container.addTwo x1 x1 x2 x2 |
660 | 095d7ac0 | Iustin Pop | |
661 | 5ef78537 | Iustin Pop | prop_Container_nameOf node = |
662 | 5ef78537 | Iustin Pop | let nl = makeSmallCluster node 1 |
663 | 5ef78537 | Iustin Pop | fnode = head (Container.elems nl) |
664 | 72bb6b4e | Iustin Pop | in Container.nameOf nl (Node.idx fnode) ==? Node.name fnode |
665 | 5ef78537 | Iustin Pop | |
666 | 525bfb36 | Iustin Pop | -- | We test that in a cluster, given a random node, we can find it by |
667 | 5ef78537 | Iustin Pop | -- its name and alias, as long as all names and aliases are unique, |
668 | 525bfb36 | Iustin Pop | -- and that we fail to find a non-existing name. |
669 | a2a0bcd8 | Iustin Pop | prop_Container_findByName node = |
670 | 5ef78537 | Iustin Pop | forAll (choose (1, 20)) $ \ cnt -> |
671 | 5ef78537 | Iustin Pop | forAll (choose (0, cnt - 1)) $ \ fidx -> |
672 | a2a0bcd8 | Iustin Pop | forAll (genUniquesList (cnt * 2)) $ \ allnames -> |
673 | a2a0bcd8 | Iustin Pop | forAll (arbitrary `suchThat` (`notElem` allnames)) $ \ othername -> |
674 | a2a0bcd8 | Iustin Pop | let names = zip (take cnt allnames) (drop cnt allnames) |
675 | a2a0bcd8 | Iustin Pop | nl = makeSmallCluster node cnt |
676 | 5ef78537 | Iustin Pop | nodes = Container.elems nl |
677 | 5ef78537 | Iustin Pop | nodes' = map (\((name, alias), nn) -> (Node.idx nn, |
678 | 5ef78537 | Iustin Pop | nn { Node.name = name, |
679 | 5ef78537 | Iustin Pop | Node.alias = alias })) |
680 | 5ef78537 | Iustin Pop | $ zip names nodes |
681 | cb0c77ff | Iustin Pop | nl' = Container.fromList nodes' |
682 | 5ef78537 | Iustin Pop | target = snd (nodes' !! fidx) |
683 | 5ef78537 | Iustin Pop | in Container.findByName nl' (Node.name target) == Just target && |
684 | 5ef78537 | Iustin Pop | Container.findByName nl' (Node.alias target) == Just target && |
685 | 3603605a | Iustin Pop | isNothing (Container.findByName nl' othername) |
686 | 5ef78537 | Iustin Pop | |
687 | 23fe06c2 | Iustin Pop | testSuite "Container" |
688 | d5dfae0a | Iustin Pop | [ 'prop_Container_addTwo |
689 | d5dfae0a | Iustin Pop | , 'prop_Container_nameOf |
690 | d5dfae0a | Iustin Pop | , 'prop_Container_findByName |
691 | d5dfae0a | Iustin Pop | ] |
692 | 095d7ac0 | Iustin Pop | |
693 | 525bfb36 | Iustin Pop | -- ** Instance tests |
694 | 525bfb36 | Iustin Pop | |
695 | 7bc82927 | Iustin Pop | -- Simple instance tests, we only have setter/getters |
696 | 7bc82927 | Iustin Pop | |
697 | 39d11971 | Iustin Pop | prop_Instance_creat inst = |
698 | d5dfae0a | Iustin Pop | Instance.name inst ==? Instance.alias inst |
699 | 39d11971 | Iustin Pop | |
700 | 7bc82927 | Iustin Pop | prop_Instance_setIdx inst idx = |
701 | d5dfae0a | Iustin Pop | Instance.idx (Instance.setIdx inst idx) ==? idx |
702 | 7bc82927 | Iustin Pop | where _types = (inst::Instance.Instance, idx::Types.Idx) |
703 | 7bc82927 | Iustin Pop | |
704 | 7bc82927 | Iustin Pop | prop_Instance_setName inst name = |
705 | d5dfae0a | Iustin Pop | Instance.name newinst == name && |
706 | d5dfae0a | Iustin Pop | Instance.alias newinst == name |
707 | 39d11971 | Iustin Pop | where _types = (inst::Instance.Instance, name::String) |
708 | 39d11971 | Iustin Pop | newinst = Instance.setName inst name |
709 | 39d11971 | Iustin Pop | |
710 | 39d11971 | Iustin Pop | prop_Instance_setAlias inst name = |
711 | d5dfae0a | Iustin Pop | Instance.name newinst == Instance.name inst && |
712 | d5dfae0a | Iustin Pop | Instance.alias newinst == name |
713 | 7bc82927 | Iustin Pop | where _types = (inst::Instance.Instance, name::String) |
714 | 39d11971 | Iustin Pop | newinst = Instance.setAlias inst name |
715 | 7bc82927 | Iustin Pop | |
716 | 7bc82927 | Iustin Pop | prop_Instance_setPri inst pdx = |
717 | d5dfae0a | Iustin Pop | Instance.pNode (Instance.setPri inst pdx) ==? pdx |
718 | 7bc82927 | Iustin Pop | where _types = (inst::Instance.Instance, pdx::Types.Ndx) |
719 | 7bc82927 | Iustin Pop | |
720 | 7bc82927 | Iustin Pop | prop_Instance_setSec inst sdx = |
721 | d5dfae0a | Iustin Pop | Instance.sNode (Instance.setSec inst sdx) ==? sdx |
722 | 7bc82927 | Iustin Pop | where _types = (inst::Instance.Instance, sdx::Types.Ndx) |
723 | 7bc82927 | Iustin Pop | |
724 | 7bc82927 | Iustin Pop | prop_Instance_setBoth inst pdx sdx = |
725 | d5dfae0a | Iustin Pop | Instance.pNode si == pdx && Instance.sNode si == sdx |
726 | 7bc82927 | Iustin Pop | where _types = (inst::Instance.Instance, pdx::Types.Ndx, sdx::Types.Ndx) |
727 | 7bc82927 | Iustin Pop | si = Instance.setBoth inst pdx sdx |
728 | 7bc82927 | Iustin Pop | |
729 | 8fcf251f | Iustin Pop | prop_Instance_shrinkMG inst = |
730 | d5dfae0a | Iustin Pop | Instance.mem inst >= 2 * Types.unitMem ==> |
731 | d5dfae0a | Iustin Pop | case Instance.shrinkByType inst Types.FailMem of |
732 | d5dfae0a | Iustin Pop | Types.Ok inst' -> Instance.mem inst' == Instance.mem inst - Types.unitMem |
733 | d5dfae0a | Iustin Pop | _ -> False |
734 | 8fcf251f | Iustin Pop | |
735 | 8fcf251f | Iustin Pop | prop_Instance_shrinkMF inst = |
736 | d5dfae0a | Iustin Pop | forAll (choose (0, 2 * Types.unitMem - 1)) $ \mem -> |
737 | 41085bd3 | Iustin Pop | let inst' = inst { Instance.mem = mem} |
738 | 41085bd3 | Iustin Pop | in Types.isBad $ Instance.shrinkByType inst' Types.FailMem |
739 | 8fcf251f | Iustin Pop | |
740 | 8fcf251f | Iustin Pop | prop_Instance_shrinkCG inst = |
741 | d5dfae0a | Iustin Pop | Instance.vcpus inst >= 2 * Types.unitCpu ==> |
742 | d5dfae0a | Iustin Pop | case Instance.shrinkByType inst Types.FailCPU of |
743 | d5dfae0a | Iustin Pop | Types.Ok inst' -> |
744 | d5dfae0a | Iustin Pop | Instance.vcpus inst' == Instance.vcpus inst - Types.unitCpu |
745 | d5dfae0a | Iustin Pop | _ -> False |
746 | 8fcf251f | Iustin Pop | |
747 | 8fcf251f | Iustin Pop | prop_Instance_shrinkCF inst = |
748 | d5dfae0a | Iustin Pop | forAll (choose (0, 2 * Types.unitCpu - 1)) $ \vcpus -> |
749 | 41085bd3 | Iustin Pop | let inst' = inst { Instance.vcpus = vcpus } |
750 | 41085bd3 | Iustin Pop | in Types.isBad $ Instance.shrinkByType inst' Types.FailCPU |
751 | 8fcf251f | Iustin Pop | |
752 | 8fcf251f | Iustin Pop | prop_Instance_shrinkDG inst = |
753 | d5dfae0a | Iustin Pop | Instance.dsk inst >= 2 * Types.unitDsk ==> |
754 | d5dfae0a | Iustin Pop | case Instance.shrinkByType inst Types.FailDisk of |
755 | d5dfae0a | Iustin Pop | Types.Ok inst' -> |
756 | d5dfae0a | Iustin Pop | Instance.dsk inst' == Instance.dsk inst - Types.unitDsk |
757 | d5dfae0a | Iustin Pop | _ -> False |
758 | 8fcf251f | Iustin Pop | |
759 | 8fcf251f | Iustin Pop | prop_Instance_shrinkDF inst = |
760 | d5dfae0a | Iustin Pop | forAll (choose (0, 2 * Types.unitDsk - 1)) $ \dsk -> |
761 | 41085bd3 | Iustin Pop | let inst' = inst { Instance.dsk = dsk } |
762 | 41085bd3 | Iustin Pop | in Types.isBad $ Instance.shrinkByType inst' Types.FailDisk |
763 | 8fcf251f | Iustin Pop | |
764 | 8fcf251f | Iustin Pop | prop_Instance_setMovable inst m = |
765 | d5dfae0a | Iustin Pop | Instance.movable inst' ==? m |
766 | 4a007641 | Iustin Pop | where inst' = Instance.setMovable inst m |
767 | 8fcf251f | Iustin Pop | |
768 | 23fe06c2 | Iustin Pop | testSuite "Instance" |
769 | d5dfae0a | Iustin Pop | [ 'prop_Instance_creat |
770 | d5dfae0a | Iustin Pop | , 'prop_Instance_setIdx |
771 | d5dfae0a | Iustin Pop | , 'prop_Instance_setName |
772 | d5dfae0a | Iustin Pop | , 'prop_Instance_setAlias |
773 | d5dfae0a | Iustin Pop | , 'prop_Instance_setPri |
774 | d5dfae0a | Iustin Pop | , 'prop_Instance_setSec |
775 | d5dfae0a | Iustin Pop | , 'prop_Instance_setBoth |
776 | d5dfae0a | Iustin Pop | , 'prop_Instance_shrinkMG |
777 | d5dfae0a | Iustin Pop | , 'prop_Instance_shrinkMF |
778 | d5dfae0a | Iustin Pop | , 'prop_Instance_shrinkCG |
779 | d5dfae0a | Iustin Pop | , 'prop_Instance_shrinkCF |
780 | d5dfae0a | Iustin Pop | , 'prop_Instance_shrinkDG |
781 | d5dfae0a | Iustin Pop | , 'prop_Instance_shrinkDF |
782 | d5dfae0a | Iustin Pop | , 'prop_Instance_setMovable |
783 | d5dfae0a | Iustin Pop | ] |
784 | 1ae7a904 | Iustin Pop | |
785 | e1dde6ad | Iustin Pop | -- ** Backends |
786 | e1dde6ad | Iustin Pop | |
787 | e1dde6ad | Iustin Pop | -- *** Text backend tests |
788 | 525bfb36 | Iustin Pop | |
789 | 1ae7a904 | Iustin Pop | -- Instance text loader tests |
790 | 1ae7a904 | Iustin Pop | |
791 | a1cd7c1e | Iustin Pop | prop_Text_Load_Instance name mem dsk vcpus status |
792 | a1cd7c1e | Iustin Pop | (NonEmpty pnode) snode |
793 | 52cc1370 | Renรฉ Nussbaumer | (NonNegative pdx) (NonNegative sdx) autobal dt su = |
794 | d5dfae0a | Iustin Pop | pnode /= snode && pdx /= sdx ==> |
795 | d5dfae0a | Iustin Pop | let vcpus_s = show vcpus |
796 | d5dfae0a | Iustin Pop | dsk_s = show dsk |
797 | d5dfae0a | Iustin Pop | mem_s = show mem |
798 | 52cc1370 | Renรฉ Nussbaumer | su_s = show su |
799 | d5dfae0a | Iustin Pop | status_s = Types.instanceStatusToRaw status |
800 | d5dfae0a | Iustin Pop | ndx = if null snode |
801 | 39d11971 | Iustin Pop | then [(pnode, pdx)] |
802 | 309e7c9a | Iustin Pop | else [(pnode, pdx), (snode, sdx)] |
803 | d5dfae0a | Iustin Pop | nl = Data.Map.fromList ndx |
804 | d5dfae0a | Iustin Pop | tags = "" |
805 | d5dfae0a | Iustin Pop | sbal = if autobal then "Y" else "N" |
806 | d5dfae0a | Iustin Pop | sdt = Types.diskTemplateToRaw dt |
807 | d5dfae0a | Iustin Pop | inst = Text.loadInst nl |
808 | d5dfae0a | Iustin Pop | [name, mem_s, dsk_s, vcpus_s, status_s, |
809 | 52cc1370 | Renรฉ Nussbaumer | sbal, pnode, snode, sdt, tags, su_s] |
810 | d5dfae0a | Iustin Pop | fail1 = Text.loadInst nl |
811 | d5dfae0a | Iustin Pop | [name, mem_s, dsk_s, vcpus_s, status_s, |
812 | d5dfae0a | Iustin Pop | sbal, pnode, pnode, tags] |
813 | d5dfae0a | Iustin Pop | _types = ( name::String, mem::Int, dsk::Int |
814 | d5dfae0a | Iustin Pop | , vcpus::Int, status::Types.InstanceStatus |
815 | d5dfae0a | Iustin Pop | , snode::String |
816 | d5dfae0a | Iustin Pop | , autobal::Bool) |
817 | d5dfae0a | Iustin Pop | in case inst of |
818 | 96bc2003 | Iustin Pop | Types.Bad msg -> failTest $ "Failed to load instance: " ++ msg |
819 | d5dfae0a | Iustin Pop | Types.Ok (_, i) -> printTestCase "Mismatch in some field while\ |
820 | d5dfae0a | Iustin Pop | \ loading the instance" $ |
821 | d5dfae0a | Iustin Pop | Instance.name i == name && |
822 | d5dfae0a | Iustin Pop | Instance.vcpus i == vcpus && |
823 | d5dfae0a | Iustin Pop | Instance.mem i == mem && |
824 | d5dfae0a | Iustin Pop | Instance.pNode i == pdx && |
825 | d5dfae0a | Iustin Pop | Instance.sNode i == (if null snode |
826 | d5dfae0a | Iustin Pop | then Node.noSecondary |
827 | d5dfae0a | Iustin Pop | else sdx) && |
828 | d5dfae0a | Iustin Pop | Instance.autoBalance i == autobal && |
829 | ec629280 | Renรฉ Nussbaumer | Instance.spindleUse i == su && |
830 | d5dfae0a | Iustin Pop | Types.isBad fail1 |
831 | 39d11971 | Iustin Pop | |
832 | 39d11971 | Iustin Pop | prop_Text_Load_InstanceFail ktn fields = |
833 | 52cc1370 | Renรฉ Nussbaumer | length fields /= 10 && length fields /= 11 ==> |
834 | bc782180 | Iustin Pop | case Text.loadInst nl fields of |
835 | 96bc2003 | Iustin Pop | Types.Ok _ -> failTest "Managed to load instance from invalid data" |
836 | 6429e8d8 | Iustin Pop | Types.Bad msg -> printTestCase ("Unrecognised error message: " ++ msg) $ |
837 | 6429e8d8 | Iustin Pop | "Invalid/incomplete instance data: '" `isPrefixOf` msg |
838 | 99b63608 | Iustin Pop | where nl = Data.Map.fromList ktn |
839 | 39d11971 | Iustin Pop | |
840 | 39d11971 | Iustin Pop | prop_Text_Load_Node name tm nm fm td fd tc fo = |
841 | d5dfae0a | Iustin Pop | let conv v = if v < 0 |
842 | d5dfae0a | Iustin Pop | then "?" |
843 | d5dfae0a | Iustin Pop | else show v |
844 | d5dfae0a | Iustin Pop | tm_s = conv tm |
845 | d5dfae0a | Iustin Pop | nm_s = conv nm |
846 | d5dfae0a | Iustin Pop | fm_s = conv fm |
847 | d5dfae0a | Iustin Pop | td_s = conv td |
848 | d5dfae0a | Iustin Pop | fd_s = conv fd |
849 | d5dfae0a | Iustin Pop | tc_s = conv tc |
850 | d5dfae0a | Iustin Pop | fo_s = if fo |
851 | 39d11971 | Iustin Pop | then "Y" |
852 | 39d11971 | Iustin Pop | else "N" |
853 | d5dfae0a | Iustin Pop | any_broken = any (< 0) [tm, nm, fm, td, fd, tc] |
854 | d5dfae0a | Iustin Pop | gid = Group.uuid defGroup |
855 | d5dfae0a | Iustin Pop | in case Text.loadNode defGroupAssoc |
856 | d5dfae0a | Iustin Pop | [name, tm_s, nm_s, fm_s, td_s, fd_s, tc_s, fo_s, gid] of |
857 | d5dfae0a | Iustin Pop | Nothing -> False |
858 | d5dfae0a | Iustin Pop | Just (name', node) -> |
859 | d5dfae0a | Iustin Pop | if fo || any_broken |
860 | d5dfae0a | Iustin Pop | then Node.offline node |
861 | d5dfae0a | Iustin Pop | else Node.name node == name' && name' == name && |
862 | d5dfae0a | Iustin Pop | Node.alias node == name && |
863 | d5dfae0a | Iustin Pop | Node.tMem node == fromIntegral tm && |
864 | d5dfae0a | Iustin Pop | Node.nMem node == nm && |
865 | d5dfae0a | Iustin Pop | Node.fMem node == fm && |
866 | d5dfae0a | Iustin Pop | Node.tDsk node == fromIntegral td && |
867 | d5dfae0a | Iustin Pop | Node.fDsk node == fd && |
868 | d5dfae0a | Iustin Pop | Node.tCpu node == fromIntegral tc |
869 | 39d11971 | Iustin Pop | |
870 | 39d11971 | Iustin Pop | prop_Text_Load_NodeFail fields = |
871 | d5dfae0a | Iustin Pop | length fields /= 8 ==> isNothing $ Text.loadNode Data.Map.empty fields |
872 | 1ae7a904 | Iustin Pop | |
873 | 50811e2c | Iustin Pop | prop_Text_NodeLSIdempotent node = |
874 | d5dfae0a | Iustin Pop | (Text.loadNode defGroupAssoc. |
875 | 487e1962 | Iustin Pop | Utils.sepSplit '|' . Text.serializeNode defGroupList) n ==? |
876 | d5dfae0a | Iustin Pop | Just (Node.name n, n) |
877 | 50811e2c | Iustin Pop | -- override failN1 to what loadNode returns by default |
878 | 487e1962 | Iustin Pop | where n = Node.setPolicy Types.defIPolicy $ |
879 | 487e1962 | Iustin Pop | node { Node.failN1 = True, Node.offline = False } |
880 | 50811e2c | Iustin Pop | |
881 | bcd17bf0 | Iustin Pop | prop_Text_ISpecIdempotent ispec = |
882 | bcd17bf0 | Iustin Pop | case Text.loadISpec "dummy" . Utils.sepSplit ',' . |
883 | bcd17bf0 | Iustin Pop | Text.serializeISpec $ ispec of |
884 | 96bc2003 | Iustin Pop | Types.Bad msg -> failTest $ "Failed to load ispec: " ++ msg |
885 | bcd17bf0 | Iustin Pop | Types.Ok ispec' -> ispec ==? ispec' |
886 | bcd17bf0 | Iustin Pop | |
887 | bcd17bf0 | Iustin Pop | prop_Text_IPolicyIdempotent ipol = |
888 | bcd17bf0 | Iustin Pop | case Text.loadIPolicy . Utils.sepSplit '|' $ |
889 | bcd17bf0 | Iustin Pop | Text.serializeIPolicy owner ipol of |
890 | 96bc2003 | Iustin Pop | Types.Bad msg -> failTest $ "Failed to load ispec: " ++ msg |
891 | bcd17bf0 | Iustin Pop | Types.Ok res -> (owner, ipol) ==? res |
892 | bcd17bf0 | Iustin Pop | where owner = "dummy" |
893 | bcd17bf0 | Iustin Pop | |
894 | dce9bbb3 | Iustin Pop | -- | This property, while being in the text tests, does more than just |
895 | dce9bbb3 | Iustin Pop | -- test end-to-end the serialisation and loading back workflow; it |
896 | dce9bbb3 | Iustin Pop | -- also tests the Loader.mergeData and the actuall |
897 | dce9bbb3 | Iustin Pop | -- Cluster.iterateAlloc (for well-behaving w.r.t. instance |
898 | dce9bbb3 | Iustin Pop | -- allocations, not for the business logic). As such, it's a quite |
899 | dce9bbb3 | Iustin Pop | -- complex and slow test, and that's the reason we restrict it to |
900 | dce9bbb3 | Iustin Pop | -- small cluster sizes. |
901 | dce9bbb3 | Iustin Pop | prop_Text_CreateSerialise = |
902 | dce9bbb3 | Iustin Pop | forAll genTags $ \ctags -> |
903 | dce9bbb3 | Iustin Pop | forAll (choose (1, 20)) $ \maxiter -> |
904 | dce9bbb3 | Iustin Pop | forAll (choose (2, 10)) $ \count -> |
905 | dce9bbb3 | Iustin Pop | forAll genOnlineNode $ \node -> |
906 | 59ed268d | Iustin Pop | forAll (genInstanceSmallerThanNode node) $ \inst -> |
907 | a7667ba6 | Iustin Pop | let nl = makeSmallCluster node count |
908 | c6e8fb9c | Iustin Pop | reqnodes = Instance.requiredNodes $ Instance.diskTemplate inst |
909 | dce9bbb3 | Iustin Pop | in case Cluster.genAllocNodes defGroupList nl reqnodes True >>= \allocn -> |
910 | a7667ba6 | Iustin Pop | Cluster.iterateAlloc nl Container.empty (Just maxiter) inst allocn [] [] |
911 | dce9bbb3 | Iustin Pop | of |
912 | 96bc2003 | Iustin Pop | Types.Bad msg -> failTest $ "Failed to allocate: " ++ msg |
913 | dce9bbb3 | Iustin Pop | Types.Ok (_, _, _, [], _) -> printTestCase |
914 | dce9bbb3 | Iustin Pop | "Failed to allocate: no allocations" False |
915 | dce9bbb3 | Iustin Pop | Types.Ok (_, nl', il', _, _) -> |
916 | dce9bbb3 | Iustin Pop | let cdata = Loader.ClusterData defGroupList nl' il' ctags |
917 | dce9bbb3 | Iustin Pop | Types.defIPolicy |
918 | dce9bbb3 | Iustin Pop | saved = Text.serializeCluster cdata |
919 | dce9bbb3 | Iustin Pop | in case Text.parseData saved >>= Loader.mergeData [] [] [] [] of |
920 | 96bc2003 | Iustin Pop | Types.Bad msg -> failTest $ "Failed to load/merge: " ++ msg |
921 | dce9bbb3 | Iustin Pop | Types.Ok (Loader.ClusterData gl2 nl2 il2 ctags2 cpol2) -> |
922 | dce9bbb3 | Iustin Pop | ctags ==? ctags2 .&&. |
923 | dce9bbb3 | Iustin Pop | Types.defIPolicy ==? cpol2 .&&. |
924 | dce9bbb3 | Iustin Pop | il' ==? il2 .&&. |
925 | b37f4a76 | Iustin Pop | defGroupList ==? gl2 .&&. |
926 | b37f4a76 | Iustin Pop | nl' ==? nl2 |
927 | dce9bbb3 | Iustin Pop | |
928 | 23fe06c2 | Iustin Pop | testSuite "Text" |
929 | d5dfae0a | Iustin Pop | [ 'prop_Text_Load_Instance |
930 | d5dfae0a | Iustin Pop | , 'prop_Text_Load_InstanceFail |
931 | d5dfae0a | Iustin Pop | , 'prop_Text_Load_Node |
932 | d5dfae0a | Iustin Pop | , 'prop_Text_Load_NodeFail |
933 | d5dfae0a | Iustin Pop | , 'prop_Text_NodeLSIdempotent |
934 | bcd17bf0 | Iustin Pop | , 'prop_Text_ISpecIdempotent |
935 | bcd17bf0 | Iustin Pop | , 'prop_Text_IPolicyIdempotent |
936 | dce9bbb3 | Iustin Pop | , 'prop_Text_CreateSerialise |
937 | d5dfae0a | Iustin Pop | ] |
938 | 7dd5ee6c | Iustin Pop | |
939 | e1dde6ad | Iustin Pop | -- *** Simu backend |
940 | e1dde6ad | Iustin Pop | |
941 | e1dde6ad | Iustin Pop | -- | Generates a tuple of specs for simulation. |
942 | e1dde6ad | Iustin Pop | genSimuSpec :: Gen (String, Int, Int, Int, Int) |
943 | e1dde6ad | Iustin Pop | genSimuSpec = do |
944 | e1dde6ad | Iustin Pop | pol <- elements [C.allocPolicyPreferred, |
945 | e1dde6ad | Iustin Pop | C.allocPolicyLastResort, C.allocPolicyUnallocable, |
946 | e1dde6ad | Iustin Pop | "p", "a", "u"] |
947 | e1dde6ad | Iustin Pop | -- should be reasonable (nodes/group), bigger values only complicate |
948 | e1dde6ad | Iustin Pop | -- the display of failed tests, and we don't care (in this particular |
949 | e1dde6ad | Iustin Pop | -- test) about big node groups |
950 | e1dde6ad | Iustin Pop | nodes <- choose (0, 20) |
951 | e1dde6ad | Iustin Pop | dsk <- choose (0, maxDsk) |
952 | e1dde6ad | Iustin Pop | mem <- choose (0, maxMem) |
953 | e1dde6ad | Iustin Pop | cpu <- choose (0, maxCpu) |
954 | e1dde6ad | Iustin Pop | return (pol, nodes, dsk, mem, cpu) |
955 | e1dde6ad | Iustin Pop | |
956 | e1dde6ad | Iustin Pop | -- | Checks that given a set of corrects specs, we can load them |
957 | e1dde6ad | Iustin Pop | -- successfully, and that at high-level the values look right. |
958 | e1dde6ad | Iustin Pop | prop_SimuLoad = |
959 | e1dde6ad | Iustin Pop | forAll (choose (0, 10)) $ \ngroups -> |
960 | e1dde6ad | Iustin Pop | forAll (replicateM ngroups genSimuSpec) $ \specs -> |
961 | e1dde6ad | Iustin Pop | let strspecs = map (\(p, n, d, m, c) -> printf "%s,%d,%d,%d,%d" |
962 | e1dde6ad | Iustin Pop | p n d m c::String) specs |
963 | e1dde6ad | Iustin Pop | totnodes = sum $ map (\(_, n, _, _, _) -> n) specs |
964 | e1dde6ad | Iustin Pop | mdc_in = concatMap (\(_, n, d, m, c) -> |
965 | e1dde6ad | Iustin Pop | replicate n (fromIntegral m, fromIntegral d, |
966 | e1dde6ad | Iustin Pop | fromIntegral c, |
967 | e1dde6ad | Iustin Pop | fromIntegral m, fromIntegral d)) specs |
968 | e1dde6ad | Iustin Pop | in case Simu.parseData strspecs of |
969 | e1dde6ad | Iustin Pop | Types.Bad msg -> failTest $ "Failed to load specs: " ++ msg |
970 | e1dde6ad | Iustin Pop | Types.Ok (Loader.ClusterData gl nl il tags ipol) -> |
971 | e1dde6ad | Iustin Pop | let nodes = map snd $ IntMap.toAscList nl |
972 | e1dde6ad | Iustin Pop | nidx = map Node.idx nodes |
973 | e1dde6ad | Iustin Pop | mdc_out = map (\n -> (Node.tMem n, Node.tDsk n, Node.tCpu n, |
974 | e1dde6ad | Iustin Pop | Node.fMem n, Node.fDsk n)) nodes |
975 | e1dde6ad | Iustin Pop | in |
976 | e1dde6ad | Iustin Pop | Container.size gl ==? ngroups .&&. |
977 | e1dde6ad | Iustin Pop | Container.size nl ==? totnodes .&&. |
978 | e1dde6ad | Iustin Pop | Container.size il ==? 0 .&&. |
979 | e1dde6ad | Iustin Pop | length tags ==? 0 .&&. |
980 | e1dde6ad | Iustin Pop | ipol ==? Types.defIPolicy .&&. |
981 | e1dde6ad | Iustin Pop | nidx ==? [1..totnodes] .&&. |
982 | e1dde6ad | Iustin Pop | mdc_in ==? mdc_out .&&. |
983 | e1dde6ad | Iustin Pop | map Group.iPolicy (Container.elems gl) ==? |
984 | e1dde6ad | Iustin Pop | replicate ngroups Types.defIPolicy |
985 | e1dde6ad | Iustin Pop | |
986 | e1dde6ad | Iustin Pop | testSuite "Simu" |
987 | e1dde6ad | Iustin Pop | [ 'prop_SimuLoad |
988 | e1dde6ad | Iustin Pop | ] |
989 | e1dde6ad | Iustin Pop | |
990 | 525bfb36 | Iustin Pop | -- ** Node tests |
991 | 7dd5ee6c | Iustin Pop | |
992 | 82ea2874 | Iustin Pop | prop_Node_setAlias node name = |
993 | d5dfae0a | Iustin Pop | Node.name newnode == Node.name node && |
994 | d5dfae0a | Iustin Pop | Node.alias newnode == name |
995 | 82ea2874 | Iustin Pop | where _types = (node::Node.Node, name::String) |
996 | 82ea2874 | Iustin Pop | newnode = Node.setAlias node name |
997 | 82ea2874 | Iustin Pop | |
998 | 82ea2874 | Iustin Pop | prop_Node_setOffline node status = |
999 | d5dfae0a | Iustin Pop | Node.offline newnode ==? status |
1000 | 82ea2874 | Iustin Pop | where newnode = Node.setOffline node status |
1001 | 82ea2874 | Iustin Pop | |
1002 | 82ea2874 | Iustin Pop | prop_Node_setXmem node xm = |
1003 | d5dfae0a | Iustin Pop | Node.xMem newnode ==? xm |
1004 | 82ea2874 | Iustin Pop | where newnode = Node.setXmem node xm |
1005 | 82ea2874 | Iustin Pop | |
1006 | 82ea2874 | Iustin Pop | prop_Node_setMcpu node mc = |
1007 | 487e1962 | Iustin Pop | Types.iPolicyVcpuRatio (Node.iPolicy newnode) ==? mc |
1008 | 82ea2874 | Iustin Pop | where newnode = Node.setMcpu node mc |
1009 | 82ea2874 | Iustin Pop | |
1010 | 525bfb36 | Iustin Pop | -- | Check that an instance add with too high memory or disk will be |
1011 | 525bfb36 | Iustin Pop | -- rejected. |
1012 | d5dfae0a | Iustin Pop | prop_Node_addPriFM node inst = |
1013 | d5dfae0a | Iustin Pop | Instance.mem inst >= Node.fMem node && not (Node.failN1 node) && |
1014 | 7959cbb9 | Iustin Pop | not (Instance.isOffline inst) ==> |
1015 | d5dfae0a | Iustin Pop | case Node.addPri node inst'' of |
1016 | d5dfae0a | Iustin Pop | Types.OpFail Types.FailMem -> True |
1017 | d5dfae0a | Iustin Pop | _ -> False |
1018 | d5dfae0a | Iustin Pop | where _types = (node::Node.Node, inst::Instance.Instance) |
1019 | d5dfae0a | Iustin Pop | inst' = setInstanceSmallerThanNode node inst |
1020 | d5dfae0a | Iustin Pop | inst'' = inst' { Instance.mem = Instance.mem inst } |
1021 | d5dfae0a | Iustin Pop | |
1022 | 53bddadd | Iustin Pop | -- | Check that adding a primary instance with too much disk fails |
1023 | 53bddadd | Iustin Pop | -- with type FailDisk. |
1024 | d5dfae0a | Iustin Pop | prop_Node_addPriFD node inst = |
1025 | 53bddadd | Iustin Pop | forAll (elements Instance.localStorageTemplates) $ \dt -> |
1026 | d5dfae0a | Iustin Pop | Instance.dsk inst >= Node.fDsk node && not (Node.failN1 node) ==> |
1027 | 53bddadd | Iustin Pop | let inst' = setInstanceSmallerThanNode node inst |
1028 | 53bddadd | Iustin Pop | inst'' = inst' { Instance.dsk = Instance.dsk inst |
1029 | 53bddadd | Iustin Pop | , Instance.diskTemplate = dt } |
1030 | 53bddadd | Iustin Pop | in case Node.addPri node inst'' of |
1031 | 53bddadd | Iustin Pop | Types.OpFail Types.FailDisk -> True |
1032 | 53bddadd | Iustin Pop | _ -> False |
1033 | 53bddadd | Iustin Pop | |
1034 | 53bddadd | Iustin Pop | -- | Check that adding a primary instance with too many VCPUs fails |
1035 | 53bddadd | Iustin Pop | -- with type FailCPU. |
1036 | 3c1e4af0 | Iustin Pop | prop_Node_addPriFC = |
1037 | 3c1e4af0 | Iustin Pop | forAll (choose (1, maxCpu)) $ \extra -> |
1038 | 746b7aa6 | Iustin Pop | forAll genOnlineNode $ \node -> |
1039 | 7959cbb9 | Iustin Pop | forAll (arbitrary `suchThat` Instance.notOffline) $ \inst -> |
1040 | 746b7aa6 | Iustin Pop | let inst' = setInstanceSmallerThanNode node inst |
1041 | 746b7aa6 | Iustin Pop | inst'' = inst' { Instance.vcpus = Node.availCpu node + extra } |
1042 | 746b7aa6 | Iustin Pop | in case Node.addPri node inst'' of |
1043 | 746b7aa6 | Iustin Pop | Types.OpFail Types.FailCPU -> property True |
1044 | 746b7aa6 | Iustin Pop | v -> failTest $ "Expected OpFail FailCPU, but got " ++ show v |
1045 | 7bc82927 | Iustin Pop | |
1046 | 525bfb36 | Iustin Pop | -- | Check that an instance add with too high memory or disk will be |
1047 | 525bfb36 | Iustin Pop | -- rejected. |
1048 | 15f4c8ca | Iustin Pop | prop_Node_addSec node inst pdx = |
1049 | d5dfae0a | Iustin Pop | ((Instance.mem inst >= (Node.fMem node - Node.rMem node) && |
1050 | 7959cbb9 | Iustin Pop | not (Instance.isOffline inst)) || |
1051 | d5dfae0a | Iustin Pop | Instance.dsk inst >= Node.fDsk node) && |
1052 | d5dfae0a | Iustin Pop | not (Node.failN1 node) ==> |
1053 | d5dfae0a | Iustin Pop | isFailure (Node.addSec node inst pdx) |
1054 | 15f4c8ca | Iustin Pop | where _types = (node::Node.Node, inst::Instance.Instance, pdx::Int) |
1055 | 7dd5ee6c | Iustin Pop | |
1056 | 45c4d54d | Iustin Pop | -- | Check that an offline instance with reasonable disk size but |
1057 | 45c4d54d | Iustin Pop | -- extra mem/cpu can always be added. |
1058 | c6b7e804 | Iustin Pop | prop_Node_addOfflinePri (NonNegative extra_mem) (NonNegative extra_cpu) = |
1059 | a2a0bcd8 | Iustin Pop | forAll genOnlineNode $ \node -> |
1060 | 45c4d54d | Iustin Pop | forAll (genInstanceSmallerThanNode node) $ \inst -> |
1061 | 45c4d54d | Iustin Pop | let inst' = inst { Instance.runSt = Types.AdminOffline |
1062 | 45c4d54d | Iustin Pop | , Instance.mem = Node.availMem node + extra_mem |
1063 | 45c4d54d | Iustin Pop | , Instance.vcpus = Node.availCpu node + extra_cpu } |
1064 | c6b7e804 | Iustin Pop | in case Node.addPri node inst' of |
1065 | c6b7e804 | Iustin Pop | Types.OpGood _ -> property True |
1066 | c6b7e804 | Iustin Pop | v -> failTest $ "Expected OpGood, but got: " ++ show v |
1067 | c6b7e804 | Iustin Pop | |
1068 | c6b7e804 | Iustin Pop | -- | Check that an offline instance with reasonable disk size but |
1069 | c6b7e804 | Iustin Pop | -- extra mem/cpu can always be added. |
1070 | c6b7e804 | Iustin Pop | prop_Node_addOfflineSec (NonNegative extra_mem) (NonNegative extra_cpu) pdx = |
1071 | c6b7e804 | Iustin Pop | forAll genOnlineNode $ \node -> |
1072 | c6b7e804 | Iustin Pop | forAll (genInstanceSmallerThanNode node) $ \inst -> |
1073 | c6b7e804 | Iustin Pop | let inst' = inst { Instance.runSt = Types.AdminOffline |
1074 | c6b7e804 | Iustin Pop | , Instance.mem = Node.availMem node + extra_mem |
1075 | c6b7e804 | Iustin Pop | , Instance.vcpus = Node.availCpu node + extra_cpu |
1076 | c6b7e804 | Iustin Pop | , Instance.diskTemplate = Types.DTDrbd8 } |
1077 | c6b7e804 | Iustin Pop | in case Node.addSec node inst' pdx of |
1078 | c6b7e804 | Iustin Pop | Types.OpGood _ -> property True |
1079 | 45c4d54d | Iustin Pop | v -> failTest $ "Expected OpGood/OpGood, but got: " ++ show v |
1080 | 61bbbed7 | Agata Murawska | |
1081 | 525bfb36 | Iustin Pop | -- | Checks for memory reservation changes. |
1082 | 752635d3 | Iustin Pop | prop_Node_rMem inst = |
1083 | 7959cbb9 | Iustin Pop | not (Instance.isOffline inst) ==> |
1084 | 5c52dae6 | Iustin Pop | forAll (genOnlineNode `suchThat` ((> Types.unitMem) . Node.fMem)) $ \node -> |
1085 | d5dfae0a | Iustin Pop | -- ab = auto_balance, nb = non-auto_balance |
1086 | d5dfae0a | Iustin Pop | -- we use -1 as the primary node of the instance |
1087 | e7b4d0e1 | Iustin Pop | let inst' = inst { Instance.pNode = -1, Instance.autoBalance = True |
1088 | e7b4d0e1 | Iustin Pop | , Instance.diskTemplate = Types.DTDrbd8 } |
1089 | d5dfae0a | Iustin Pop | inst_ab = setInstanceSmallerThanNode node inst' |
1090 | d5dfae0a | Iustin Pop | inst_nb = inst_ab { Instance.autoBalance = False } |
1091 | d5dfae0a | Iustin Pop | -- now we have the two instances, identical except the |
1092 | d5dfae0a | Iustin Pop | -- autoBalance attribute |
1093 | d5dfae0a | Iustin Pop | orig_rmem = Node.rMem node |
1094 | d5dfae0a | Iustin Pop | inst_idx = Instance.idx inst_ab |
1095 | d5dfae0a | Iustin Pop | node_add_ab = Node.addSec node inst_ab (-1) |
1096 | d5dfae0a | Iustin Pop | node_add_nb = Node.addSec node inst_nb (-1) |
1097 | d5dfae0a | Iustin Pop | node_del_ab = liftM (`Node.removeSec` inst_ab) node_add_ab |
1098 | d5dfae0a | Iustin Pop | node_del_nb = liftM (`Node.removeSec` inst_nb) node_add_nb |
1099 | d5dfae0a | Iustin Pop | in case (node_add_ab, node_add_nb, node_del_ab, node_del_nb) of |
1100 | d5dfae0a | Iustin Pop | (Types.OpGood a_ab, Types.OpGood a_nb, |
1101 | d5dfae0a | Iustin Pop | Types.OpGood d_ab, Types.OpGood d_nb) -> |
1102 | d5dfae0a | Iustin Pop | printTestCase "Consistency checks failed" $ |
1103 | d5dfae0a | Iustin Pop | Node.rMem a_ab > orig_rmem && |
1104 | d5dfae0a | Iustin Pop | Node.rMem a_ab - orig_rmem == Instance.mem inst_ab && |
1105 | d5dfae0a | Iustin Pop | Node.rMem a_nb == orig_rmem && |
1106 | d5dfae0a | Iustin Pop | Node.rMem d_ab == orig_rmem && |
1107 | d5dfae0a | Iustin Pop | Node.rMem d_nb == orig_rmem && |
1108 | d5dfae0a | Iustin Pop | -- this is not related to rMem, but as good a place to |
1109 | d5dfae0a | Iustin Pop | -- test as any |
1110 | d5dfae0a | Iustin Pop | inst_idx `elem` Node.sList a_ab && |
1111 | 3603605a | Iustin Pop | inst_idx `notElem` Node.sList d_ab |
1112 | 96bc2003 | Iustin Pop | x -> failTest $ "Failed to add/remove instances: " ++ show x |
1113 | 9cbc1edb | Iustin Pop | |
1114 | 525bfb36 | Iustin Pop | -- | Check mdsk setting. |
1115 | 8fcf251f | Iustin Pop | prop_Node_setMdsk node mx = |
1116 | d5dfae0a | Iustin Pop | Node.loDsk node' >= 0 && |
1117 | d5dfae0a | Iustin Pop | fromIntegral (Node.loDsk node') <= Node.tDsk node && |
1118 | d5dfae0a | Iustin Pop | Node.availDisk node' >= 0 && |
1119 | d5dfae0a | Iustin Pop | Node.availDisk node' <= Node.fDsk node' && |
1120 | d5dfae0a | Iustin Pop | fromIntegral (Node.availDisk node') <= Node.tDsk node' && |
1121 | d5dfae0a | Iustin Pop | Node.mDsk node' == mx' |
1122 | 8fcf251f | Iustin Pop | where _types = (node::Node.Node, mx::SmallRatio) |
1123 | 8fcf251f | Iustin Pop | node' = Node.setMdsk node mx' |
1124 | 8fcf251f | Iustin Pop | SmallRatio mx' = mx |
1125 | 8fcf251f | Iustin Pop | |
1126 | 8fcf251f | Iustin Pop | -- Check tag maps |
1127 | 15e3d31c | Iustin Pop | prop_Node_tagMaps_idempotent = |
1128 | 15e3d31c | Iustin Pop | forAll genTags $ \tags -> |
1129 | d5dfae0a | Iustin Pop | Node.delTags (Node.addTags m tags) tags ==? m |
1130 | 4a007641 | Iustin Pop | where m = Data.Map.empty |
1131 | 8fcf251f | Iustin Pop | |
1132 | 15e3d31c | Iustin Pop | prop_Node_tagMaps_reject = |
1133 | 15e3d31c | Iustin Pop | forAll (genTags `suchThat` (not . null)) $ \tags -> |
1134 | 15e3d31c | Iustin Pop | let m = Node.addTags Data.Map.empty tags |
1135 | 15e3d31c | Iustin Pop | in all (\t -> Node.rejectAddTags m [t]) tags |
1136 | 8fcf251f | Iustin Pop | |
1137 | 82ea2874 | Iustin Pop | prop_Node_showField node = |
1138 | 82ea2874 | Iustin Pop | forAll (elements Node.defaultFields) $ \ field -> |
1139 | 82ea2874 | Iustin Pop | fst (Node.showHeader field) /= Types.unknownField && |
1140 | 82ea2874 | Iustin Pop | Node.showField node field /= Types.unknownField |
1141 | 82ea2874 | Iustin Pop | |
1142 | d8bcd0a8 | Iustin Pop | prop_Node_computeGroups nodes = |
1143 | d8bcd0a8 | Iustin Pop | let ng = Node.computeGroups nodes |
1144 | d8bcd0a8 | Iustin Pop | onlyuuid = map fst ng |
1145 | d8bcd0a8 | Iustin Pop | in length nodes == sum (map (length . snd) ng) && |
1146 | d8bcd0a8 | Iustin Pop | all (\(guuid, ns) -> all ((== guuid) . Node.group) ns) ng && |
1147 | d8bcd0a8 | Iustin Pop | length (nub onlyuuid) == length onlyuuid && |
1148 | cc532bdd | Iustin Pop | (null nodes || not (null ng)) |
1149 | d8bcd0a8 | Iustin Pop | |
1150 | eae69eee | Iustin Pop | -- Check idempotence of add/remove operations |
1151 | eae69eee | Iustin Pop | prop_Node_addPri_idempotent = |
1152 | eae69eee | Iustin Pop | forAll genOnlineNode $ \node -> |
1153 | eae69eee | Iustin Pop | forAll (genInstanceSmallerThanNode node) $ \inst -> |
1154 | eae69eee | Iustin Pop | case Node.addPri node inst of |
1155 | eae69eee | Iustin Pop | Types.OpGood node' -> Node.removePri node' inst ==? node |
1156 | eae69eee | Iustin Pop | _ -> failTest "Can't add instance" |
1157 | eae69eee | Iustin Pop | |
1158 | eae69eee | Iustin Pop | prop_Node_addSec_idempotent = |
1159 | eae69eee | Iustin Pop | forAll genOnlineNode $ \node -> |
1160 | eae69eee | Iustin Pop | forAll (genInstanceSmallerThanNode node) $ \inst -> |
1161 | eae69eee | Iustin Pop | let pdx = Node.idx node + 1 |
1162 | eae69eee | Iustin Pop | inst' = Instance.setPri inst pdx |
1163 | 90669369 | Iustin Pop | inst'' = inst' { Instance.diskTemplate = Types.DTDrbd8 } |
1164 | 90669369 | Iustin Pop | in case Node.addSec node inst'' pdx of |
1165 | 90669369 | Iustin Pop | Types.OpGood node' -> Node.removeSec node' inst'' ==? node |
1166 | eae69eee | Iustin Pop | _ -> failTest "Can't add instance" |
1167 | eae69eee | Iustin Pop | |
1168 | 23fe06c2 | Iustin Pop | testSuite "Node" |
1169 | d5dfae0a | Iustin Pop | [ 'prop_Node_setAlias |
1170 | d5dfae0a | Iustin Pop | , 'prop_Node_setOffline |
1171 | d5dfae0a | Iustin Pop | , 'prop_Node_setMcpu |
1172 | d5dfae0a | Iustin Pop | , 'prop_Node_setXmem |
1173 | d5dfae0a | Iustin Pop | , 'prop_Node_addPriFM |
1174 | d5dfae0a | Iustin Pop | , 'prop_Node_addPriFD |
1175 | d5dfae0a | Iustin Pop | , 'prop_Node_addPriFC |
1176 | d5dfae0a | Iustin Pop | , 'prop_Node_addSec |
1177 | c6b7e804 | Iustin Pop | , 'prop_Node_addOfflinePri |
1178 | c6b7e804 | Iustin Pop | , 'prop_Node_addOfflineSec |
1179 | d5dfae0a | Iustin Pop | , 'prop_Node_rMem |
1180 | d5dfae0a | Iustin Pop | , 'prop_Node_setMdsk |
1181 | d5dfae0a | Iustin Pop | , 'prop_Node_tagMaps_idempotent |
1182 | d5dfae0a | Iustin Pop | , 'prop_Node_tagMaps_reject |
1183 | d5dfae0a | Iustin Pop | , 'prop_Node_showField |
1184 | d5dfae0a | Iustin Pop | , 'prop_Node_computeGroups |
1185 | eae69eee | Iustin Pop | , 'prop_Node_addPri_idempotent |
1186 | eae69eee | Iustin Pop | , 'prop_Node_addSec_idempotent |
1187 | d5dfae0a | Iustin Pop | ] |
1188 | cf35a869 | Iustin Pop | |
1189 | 525bfb36 | Iustin Pop | -- ** Cluster tests |
1190 | cf35a869 | Iustin Pop | |
1191 | 525bfb36 | Iustin Pop | -- | Check that the cluster score is close to zero for a homogeneous |
1192 | 525bfb36 | Iustin Pop | -- cluster. |
1193 | 8e4f6d56 | Iustin Pop | prop_Score_Zero node = |
1194 | d5dfae0a | Iustin Pop | forAll (choose (1, 1024)) $ \count -> |
1195 | 3a3c1eb4 | Iustin Pop | (not (Node.offline node) && not (Node.failN1 node) && (count > 0) && |
1196 | 2060348b | Iustin Pop | (Node.tDsk node > 0) && (Node.tMem node > 0)) ==> |
1197 | d5dfae0a | Iustin Pop | let fn = Node.buildPeers node Container.empty |
1198 | d5dfae0a | Iustin Pop | nlst = replicate count fn |
1199 | d5dfae0a | Iustin Pop | score = Cluster.compCVNodes nlst |
1200 | d5dfae0a | Iustin Pop | -- we can't say == 0 here as the floating point errors accumulate; |
1201 | d5dfae0a | Iustin Pop | -- this should be much lower than the default score in CLI.hs |
1202 | d5dfae0a | Iustin Pop | in score <= 1e-12 |
1203 | cf35a869 | Iustin Pop | |
1204 | 525bfb36 | Iustin Pop | -- | Check that cluster stats are sane. |
1205 | d6f9f5bd | Iustin Pop | prop_CStats_sane = |
1206 | d5dfae0a | Iustin Pop | forAll (choose (1, 1024)) $ \count -> |
1207 | d6f9f5bd | Iustin Pop | forAll genOnlineNode $ \node -> |
1208 | d5dfae0a | Iustin Pop | let fn = Node.buildPeers node Container.empty |
1209 | d5dfae0a | Iustin Pop | nlst = zip [1..] $ replicate count fn::[(Types.Ndx, Node.Node)] |
1210 | d5dfae0a | Iustin Pop | nl = Container.fromList nlst |
1211 | d5dfae0a | Iustin Pop | cstats = Cluster.totalResources nl |
1212 | d5dfae0a | Iustin Pop | in Cluster.csAdsk cstats >= 0 && |
1213 | d5dfae0a | Iustin Pop | Cluster.csAdsk cstats <= Cluster.csFdsk cstats |
1214 | 8fcf251f | Iustin Pop | |
1215 | 3fea6959 | Iustin Pop | -- | Check that one instance is allocated correctly, without |
1216 | 525bfb36 | Iustin Pop | -- rebalances needed. |
1217 | d6f9f5bd | Iustin Pop | prop_ClusterAlloc_sane inst = |
1218 | d5dfae0a | Iustin Pop | forAll (choose (5, 20)) $ \count -> |
1219 | d6f9f5bd | Iustin Pop | forAll genOnlineNode $ \node -> |
1220 | 3603605a | Iustin Pop | let (nl, il, inst') = makeSmallEmptyCluster node count inst |
1221 | c6e8fb9c | Iustin Pop | reqnodes = Instance.requiredNodes $ Instance.diskTemplate inst |
1222 | c6e8fb9c | Iustin Pop | in case Cluster.genAllocNodes defGroupList nl reqnodes True >>= |
1223 | d5dfae0a | Iustin Pop | Cluster.tryAlloc nl il inst' of |
1224 | d5dfae0a | Iustin Pop | Types.Bad _ -> False |
1225 | d5dfae0a | Iustin Pop | Types.Ok as -> |
1226 | d5dfae0a | Iustin Pop | case Cluster.asSolution as of |
1227 | d5dfae0a | Iustin Pop | Nothing -> False |
1228 | d5dfae0a | Iustin Pop | Just (xnl, xi, _, cv) -> |
1229 | d5dfae0a | Iustin Pop | let il' = Container.add (Instance.idx xi) xi il |
1230 | d5dfae0a | Iustin Pop | tbl = Cluster.Table xnl il' cv [] |
1231 | d5dfae0a | Iustin Pop | in not (canBalance tbl True True False) |
1232 | 3fea6959 | Iustin Pop | |
1233 | 3fea6959 | Iustin Pop | -- | Checks that on a 2-5 node cluster, we can allocate a random |
1234 | 3fea6959 | Iustin Pop | -- instance spec via tiered allocation (whatever the original instance |
1235 | 37483aa5 | Iustin Pop | -- spec), on either one or two nodes. Furthermore, we test that |
1236 | 37483aa5 | Iustin Pop | -- computed allocation statistics are correct. |
1237 | d6f9f5bd | Iustin Pop | prop_ClusterCanTieredAlloc inst = |
1238 | d5dfae0a | Iustin Pop | forAll (choose (2, 5)) $ \count -> |
1239 | d6f9f5bd | Iustin Pop | forAll (genOnlineNode `suchThat` (isNodeBig 4)) $ \node -> |
1240 | d5dfae0a | Iustin Pop | let nl = makeSmallCluster node count |
1241 | d5dfae0a | Iustin Pop | il = Container.empty |
1242 | c6e8fb9c | Iustin Pop | rqnodes = Instance.requiredNodes $ Instance.diskTemplate inst |
1243 | d5dfae0a | Iustin Pop | allocnodes = Cluster.genAllocNodes defGroupList nl rqnodes True |
1244 | d5dfae0a | Iustin Pop | in case allocnodes >>= \allocnodes' -> |
1245 | d5dfae0a | Iustin Pop | Cluster.tieredAlloc nl il (Just 1) inst allocnodes' [] [] of |
1246 | 37483aa5 | Iustin Pop | Types.Bad msg -> failTest $ "Failed to tiered alloc: " ++ msg |
1247 | 37483aa5 | Iustin Pop | Types.Ok (_, nl', il', ixes, cstats) -> |
1248 | 37483aa5 | Iustin Pop | let (ai_alloc, ai_pool, ai_unav) = |
1249 | 37483aa5 | Iustin Pop | Cluster.computeAllocationDelta |
1250 | 37483aa5 | Iustin Pop | (Cluster.totalResources nl) |
1251 | 37483aa5 | Iustin Pop | (Cluster.totalResources nl') |
1252 | 37483aa5 | Iustin Pop | all_nodes = Container.elems nl |
1253 | 37483aa5 | Iustin Pop | in property (not (null ixes)) .&&. |
1254 | 37483aa5 | Iustin Pop | IntMap.size il' ==? length ixes .&&. |
1255 | 37483aa5 | Iustin Pop | length ixes ==? length cstats .&&. |
1256 | 37483aa5 | Iustin Pop | sum (map Types.allocInfoVCpus [ai_alloc, ai_pool, ai_unav]) ==? |
1257 | 37483aa5 | Iustin Pop | sum (map Node.hiCpu all_nodes) .&&. |
1258 | 37483aa5 | Iustin Pop | sum (map Types.allocInfoNCpus [ai_alloc, ai_pool, ai_unav]) ==? |
1259 | 37483aa5 | Iustin Pop | sum (map Node.tCpu all_nodes) .&&. |
1260 | 37483aa5 | Iustin Pop | sum (map Types.allocInfoMem [ai_alloc, ai_pool, ai_unav]) ==? |
1261 | 37483aa5 | Iustin Pop | truncate (sum (map Node.tMem all_nodes)) .&&. |
1262 | 37483aa5 | Iustin Pop | sum (map Types.allocInfoDisk [ai_alloc, ai_pool, ai_unav]) ==? |
1263 | 37483aa5 | Iustin Pop | truncate (sum (map Node.tDsk all_nodes)) |
1264 | 3fea6959 | Iustin Pop | |
1265 | 6a855aaa | Iustin Pop | -- | Helper function to create a cluster with the given range of nodes |
1266 | 6a855aaa | Iustin Pop | -- and allocate an instance on it. |
1267 | 6a855aaa | Iustin Pop | genClusterAlloc count node inst = |
1268 | 6a855aaa | Iustin Pop | let nl = makeSmallCluster node count |
1269 | c6e8fb9c | Iustin Pop | reqnodes = Instance.requiredNodes $ Instance.diskTemplate inst |
1270 | c6e8fb9c | Iustin Pop | in case Cluster.genAllocNodes defGroupList nl reqnodes True >>= |
1271 | 6a855aaa | Iustin Pop | Cluster.tryAlloc nl Container.empty inst of |
1272 | 6a855aaa | Iustin Pop | Types.Bad _ -> Types.Bad "Can't allocate" |
1273 | d5dfae0a | Iustin Pop | Types.Ok as -> |
1274 | d5dfae0a | Iustin Pop | case Cluster.asSolution as of |
1275 | 6a855aaa | Iustin Pop | Nothing -> Types.Bad "Empty solution?" |
1276 | d5dfae0a | Iustin Pop | Just (xnl, xi, _, _) -> |
1277 | 6a855aaa | Iustin Pop | let xil = Container.add (Instance.idx xi) xi Container.empty |
1278 | 6a855aaa | Iustin Pop | in Types.Ok (xnl, xil, xi) |
1279 | 6a855aaa | Iustin Pop | |
1280 | 6a855aaa | Iustin Pop | -- | Checks that on a 4-8 node cluster, once we allocate an instance, |
1281 | 6a855aaa | Iustin Pop | -- we can also relocate it. |
1282 | 6a855aaa | Iustin Pop | prop_ClusterAllocRelocate = |
1283 | 6a855aaa | Iustin Pop | forAll (choose (4, 8)) $ \count -> |
1284 | 6a855aaa | Iustin Pop | forAll (genOnlineNode `suchThat` (isNodeBig 4)) $ \node -> |
1285 | 7018af9c | Iustin Pop | forAll (genInstanceSmallerThanNode node `suchThat` isMirrored) $ \inst -> |
1286 | 6a855aaa | Iustin Pop | case genClusterAlloc count node inst of |
1287 | 6a855aaa | Iustin Pop | Types.Bad msg -> failTest msg |
1288 | 6a855aaa | Iustin Pop | Types.Ok (nl, il, inst') -> |
1289 | 6a855aaa | Iustin Pop | case IAlloc.processRelocate defGroupList nl il |
1290 | 7018af9c | Iustin Pop | (Instance.idx inst) 1 |
1291 | 7018af9c | Iustin Pop | [(if Instance.diskTemplate inst' == Types.DTDrbd8 |
1292 | 7018af9c | Iustin Pop | then Instance.sNode |
1293 | 7018af9c | Iustin Pop | else Instance.pNode) inst'] of |
1294 | 7018af9c | Iustin Pop | Types.Ok _ -> property True |
1295 | 6a855aaa | Iustin Pop | Types.Bad msg -> failTest $ "Failed to relocate: " ++ msg |
1296 | 6a855aaa | Iustin Pop | |
1297 | 6a855aaa | Iustin Pop | -- | Helper property checker for the result of a nodeEvac or |
1298 | 6a855aaa | Iustin Pop | -- changeGroup operation. |
1299 | 6a855aaa | Iustin Pop | check_EvacMode grp inst result = |
1300 | 6a855aaa | Iustin Pop | case result of |
1301 | 6a855aaa | Iustin Pop | Types.Bad msg -> failTest $ "Couldn't evacuate/change group:" ++ msg |
1302 | 6a855aaa | Iustin Pop | Types.Ok (_, _, es) -> |
1303 | 6a855aaa | Iustin Pop | let moved = Cluster.esMoved es |
1304 | 6a855aaa | Iustin Pop | failed = Cluster.esFailed es |
1305 | 6a855aaa | Iustin Pop | opcodes = not . null $ Cluster.esOpCodes es |
1306 | 6a855aaa | Iustin Pop | in failmsg ("'failed' not empty: " ++ show failed) (null failed) .&&. |
1307 | 6a855aaa | Iustin Pop | failmsg "'opcodes' is null" opcodes .&&. |
1308 | 6a855aaa | Iustin Pop | case moved of |
1309 | 6a855aaa | Iustin Pop | [(idx', gdx, _)] -> failmsg "invalid instance moved" (idx == idx') |
1310 | 6a855aaa | Iustin Pop | .&&. |
1311 | 6a855aaa | Iustin Pop | failmsg "wrong target group" |
1312 | 6a855aaa | Iustin Pop | (gdx == Group.idx grp) |
1313 | 6a855aaa | Iustin Pop | v -> failmsg ("invalid solution: " ++ show v) False |
1314 | 6a855aaa | Iustin Pop | where failmsg = \msg -> printTestCase ("Failed to evacuate: " ++ msg) |
1315 | 6a855aaa | Iustin Pop | idx = Instance.idx inst |
1316 | 6a855aaa | Iustin Pop | |
1317 | 6a855aaa | Iustin Pop | -- | Checks that on a 4-8 node cluster, once we allocate an instance, |
1318 | 6a855aaa | Iustin Pop | -- we can also node-evacuate it. |
1319 | 6a855aaa | Iustin Pop | prop_ClusterAllocEvacuate = |
1320 | 6a855aaa | Iustin Pop | forAll (choose (4, 8)) $ \count -> |
1321 | 6a855aaa | Iustin Pop | forAll (genOnlineNode `suchThat` (isNodeBig 4)) $ \node -> |
1322 | ac1c0a07 | Iustin Pop | forAll (genInstanceSmallerThanNode node `suchThat` isMirrored) $ \inst -> |
1323 | 6a855aaa | Iustin Pop | case genClusterAlloc count node inst of |
1324 | 6a855aaa | Iustin Pop | Types.Bad msg -> failTest msg |
1325 | 6a855aaa | Iustin Pop | Types.Ok (nl, il, inst') -> |
1326 | 6a855aaa | Iustin Pop | conjoin $ map (\mode -> check_EvacMode defGroup inst' $ |
1327 | 6a855aaa | Iustin Pop | Cluster.tryNodeEvac defGroupList nl il mode |
1328 | ac1c0a07 | Iustin Pop | [Instance.idx inst']) . |
1329 | fafd0773 | Iustin Pop | evacModeOptions . |
1330 | fafd0773 | Iustin Pop | Instance.mirrorType $ inst' |
1331 | 6a855aaa | Iustin Pop | |
1332 | 6a855aaa | Iustin Pop | -- | Checks that on a 4-8 node cluster with two node groups, once we |
1333 | 6a855aaa | Iustin Pop | -- allocate an instance on the first node group, we can also change |
1334 | 6a855aaa | Iustin Pop | -- its group. |
1335 | 6a855aaa | Iustin Pop | prop_ClusterAllocChangeGroup = |
1336 | 6a855aaa | Iustin Pop | forAll (choose (4, 8)) $ \count -> |
1337 | 6a855aaa | Iustin Pop | forAll (genOnlineNode `suchThat` (isNodeBig 4)) $ \node -> |
1338 | ac1c0a07 | Iustin Pop | forAll (genInstanceSmallerThanNode node `suchThat` isMirrored) $ \inst -> |
1339 | 6a855aaa | Iustin Pop | case genClusterAlloc count node inst of |
1340 | 6a855aaa | Iustin Pop | Types.Bad msg -> failTest msg |
1341 | 6a855aaa | Iustin Pop | Types.Ok (nl, il, inst') -> |
1342 | 6a855aaa | Iustin Pop | -- we need to add a second node group and nodes to the cluster |
1343 | 6a855aaa | Iustin Pop | let nl2 = Container.elems $ makeSmallCluster node count |
1344 | 6a855aaa | Iustin Pop | grp2 = Group.setIdx defGroup (Group.idx defGroup + 1) |
1345 | 6a855aaa | Iustin Pop | maxndx = maximum . map Node.idx $ nl2 |
1346 | 6a855aaa | Iustin Pop | nl3 = map (\n -> n { Node.group = Group.idx grp2 |
1347 | 6a855aaa | Iustin Pop | , Node.idx = Node.idx n + maxndx }) nl2 |
1348 | 6a855aaa | Iustin Pop | nl4 = Container.fromList . map (\n -> (Node.idx n, n)) $ nl3 |
1349 | 6a855aaa | Iustin Pop | gl' = Container.add (Group.idx grp2) grp2 defGroupList |
1350 | 6a855aaa | Iustin Pop | nl' = IntMap.union nl nl4 |
1351 | 6a855aaa | Iustin Pop | in check_EvacMode grp2 inst' $ |
1352 | 6a855aaa | Iustin Pop | Cluster.tryChangeGroup gl' nl' il [] [Instance.idx inst'] |
1353 | 3fea6959 | Iustin Pop | |
1354 | 3fea6959 | Iustin Pop | -- | Check that allocating multiple instances on a cluster, then |
1355 | 525bfb36 | Iustin Pop | -- adding an empty node, results in a valid rebalance. |
1356 | 00c75986 | Iustin Pop | prop_ClusterAllocBalance = |
1357 | d5dfae0a | Iustin Pop | forAll (genNode (Just 5) (Just 128)) $ \node -> |
1358 | d5dfae0a | Iustin Pop | forAll (choose (3, 5)) $ \count -> |
1359 | d5dfae0a | Iustin Pop | not (Node.offline node) && not (Node.failN1 node) ==> |
1360 | d5dfae0a | Iustin Pop | let nl = makeSmallCluster node count |
1361 | d5dfae0a | Iustin Pop | (hnode, nl') = IntMap.deleteFindMax nl |
1362 | d5dfae0a | Iustin Pop | il = Container.empty |
1363 | d5dfae0a | Iustin Pop | allocnodes = Cluster.genAllocNodes defGroupList nl' 2 True |
1364 | d5dfae0a | Iustin Pop | i_templ = createInstance Types.unitMem Types.unitDsk Types.unitCpu |
1365 | d5dfae0a | Iustin Pop | in case allocnodes >>= \allocnodes' -> |
1366 | d5dfae0a | Iustin Pop | Cluster.iterateAlloc nl' il (Just 5) i_templ allocnodes' [] [] of |
1367 | 96bc2003 | Iustin Pop | Types.Bad msg -> failTest $ "Failed to allocate: " ++ msg |
1368 | 96bc2003 | Iustin Pop | Types.Ok (_, _, _, [], _) -> failTest "Failed to allocate: no instances" |
1369 | d5dfae0a | Iustin Pop | Types.Ok (_, xnl, il', _, _) -> |
1370 | d5dfae0a | Iustin Pop | let ynl = Container.add (Node.idx hnode) hnode xnl |
1371 | d5dfae0a | Iustin Pop | cv = Cluster.compCV ynl |
1372 | d5dfae0a | Iustin Pop | tbl = Cluster.Table ynl il' cv [] |
1373 | 6cff91f5 | Iustin Pop | in printTestCase "Failed to rebalance" $ |
1374 | 6cff91f5 | Iustin Pop | canBalance tbl True True False |
1375 | 3fea6959 | Iustin Pop | |
1376 | 525bfb36 | Iustin Pop | -- | Checks consistency. |
1377 | 32b8d9c0 | Iustin Pop | prop_ClusterCheckConsistency node inst = |
1378 | 32b8d9c0 | Iustin Pop | let nl = makeSmallCluster node 3 |
1379 | 32b8d9c0 | Iustin Pop | [node1, node2, node3] = Container.elems nl |
1380 | 10ef6b4e | Iustin Pop | node3' = node3 { Node.group = 1 } |
1381 | 32b8d9c0 | Iustin Pop | nl' = Container.add (Node.idx node3') node3' nl |
1382 | 32b8d9c0 | Iustin Pop | inst1 = Instance.setBoth inst (Node.idx node1) (Node.idx node2) |
1383 | 32b8d9c0 | Iustin Pop | inst2 = Instance.setBoth inst (Node.idx node1) Node.noSecondary |
1384 | 32b8d9c0 | Iustin Pop | inst3 = Instance.setBoth inst (Node.idx node1) (Node.idx node3) |
1385 | cb0c77ff | Iustin Pop | ccheck = Cluster.findSplitInstances nl' . Container.fromList |
1386 | 32b8d9c0 | Iustin Pop | in null (ccheck [(0, inst1)]) && |
1387 | 32b8d9c0 | Iustin Pop | null (ccheck [(0, inst2)]) && |
1388 | 32b8d9c0 | Iustin Pop | (not . null $ ccheck [(0, inst3)]) |
1389 | 32b8d9c0 | Iustin Pop | |
1390 | 525bfb36 | Iustin Pop | -- | For now, we only test that we don't lose instances during the split. |
1391 | f4161783 | Iustin Pop | prop_ClusterSplitCluster node inst = |
1392 | f4161783 | Iustin Pop | forAll (choose (0, 100)) $ \icnt -> |
1393 | f4161783 | Iustin Pop | let nl = makeSmallCluster node 2 |
1394 | f4161783 | Iustin Pop | (nl', il') = foldl (\(ns, is) _ -> assignInstance ns is inst 0 1) |
1395 | f4161783 | Iustin Pop | (nl, Container.empty) [1..icnt] |
1396 | f4161783 | Iustin Pop | gni = Cluster.splitCluster nl' il' |
1397 | f4161783 | Iustin Pop | in sum (map (Container.size . snd . snd) gni) == icnt && |
1398 | f4161783 | Iustin Pop | all (\(guuid, (nl'', _)) -> all ((== guuid) . Node.group) |
1399 | f4161783 | Iustin Pop | (Container.elems nl'')) gni |
1400 | 32b8d9c0 | Iustin Pop | |
1401 | 00b70680 | Iustin Pop | -- | Helper function to check if we can allocate an instance on a |
1402 | 00b70680 | Iustin Pop | -- given node list. |
1403 | 00b70680 | Iustin Pop | canAllocOn :: Node.List -> Int -> Instance.Instance -> Bool |
1404 | 00b70680 | Iustin Pop | canAllocOn nl reqnodes inst = |
1405 | 00b70680 | Iustin Pop | case Cluster.genAllocNodes defGroupList nl reqnodes True >>= |
1406 | 00b70680 | Iustin Pop | Cluster.tryAlloc nl (Container.empty) inst of |
1407 | 00b70680 | Iustin Pop | Types.Bad _ -> False |
1408 | 00b70680 | Iustin Pop | Types.Ok as -> |
1409 | 00b70680 | Iustin Pop | case Cluster.asSolution as of |
1410 | 00b70680 | Iustin Pop | Nothing -> False |
1411 | 00b70680 | Iustin Pop | Just _ -> True |
1412 | 00b70680 | Iustin Pop | |
1413 | 00b70680 | Iustin Pop | -- | Checks that allocation obeys minimum and maximum instance |
1414 | 00b70680 | Iustin Pop | -- policies. The unittest generates a random node, duplicates it count |
1415 | 00b70680 | Iustin Pop | -- times, and generates a random instance that can be allocated on |
1416 | 00b70680 | Iustin Pop | -- this mini-cluster; it then checks that after applying a policy that |
1417 | 00b70680 | Iustin Pop | -- the instance doesn't fits, the allocation fails. |
1418 | 00b70680 | Iustin Pop | prop_ClusterAllocPolicy node = |
1419 | 00b70680 | Iustin Pop | -- rqn is the required nodes (1 or 2) |
1420 | 00b70680 | Iustin Pop | forAll (choose (1, 2)) $ \rqn -> |
1421 | 00b70680 | Iustin Pop | forAll (choose (5, 20)) $ \count -> |
1422 | 00b70680 | Iustin Pop | forAll (arbitrary `suchThat` (canAllocOn (makeSmallCluster node count) rqn)) |
1423 | 00b70680 | Iustin Pop | $ \inst -> |
1424 | 00b70680 | Iustin Pop | forAll (arbitrary `suchThat` (isFailure . |
1425 | 00b70680 | Iustin Pop | Instance.instMatchesPolicy inst)) $ \ipol -> |
1426 | 00b70680 | Iustin Pop | let node' = Node.setPolicy ipol node |
1427 | 00b70680 | Iustin Pop | nl = makeSmallCluster node' count |
1428 | 00b70680 | Iustin Pop | in not $ canAllocOn nl rqn inst |
1429 | 00b70680 | Iustin Pop | |
1430 | 23fe06c2 | Iustin Pop | testSuite "Cluster" |
1431 | d5dfae0a | Iustin Pop | [ 'prop_Score_Zero |
1432 | d5dfae0a | Iustin Pop | , 'prop_CStats_sane |
1433 | d5dfae0a | Iustin Pop | , 'prop_ClusterAlloc_sane |
1434 | d5dfae0a | Iustin Pop | , 'prop_ClusterCanTieredAlloc |
1435 | 6a855aaa | Iustin Pop | , 'prop_ClusterAllocRelocate |
1436 | 6a855aaa | Iustin Pop | , 'prop_ClusterAllocEvacuate |
1437 | 6a855aaa | Iustin Pop | , 'prop_ClusterAllocChangeGroup |
1438 | d5dfae0a | Iustin Pop | , 'prop_ClusterAllocBalance |
1439 | d5dfae0a | Iustin Pop | , 'prop_ClusterCheckConsistency |
1440 | d5dfae0a | Iustin Pop | , 'prop_ClusterSplitCluster |
1441 | 00b70680 | Iustin Pop | , 'prop_ClusterAllocPolicy |
1442 | d5dfae0a | Iustin Pop | ] |
1443 | 88f25dd0 | Iustin Pop | |
1444 | 525bfb36 | Iustin Pop | -- ** OpCodes tests |
1445 | 88f25dd0 | Iustin Pop | |
1446 | 525bfb36 | Iustin Pop | -- | Check that opcode serialization is idempotent. |
1447 | 88f25dd0 | Iustin Pop | prop_OpCodes_serialization op = |
1448 | 88f25dd0 | Iustin Pop | case J.readJSON (J.showJSON op) of |
1449 | 96bc2003 | Iustin Pop | J.Error e -> failTest $ "Cannot deserialise: " ++ e |
1450 | 72bb6b4e | Iustin Pop | J.Ok op' -> op ==? op' |
1451 | 4a007641 | Iustin Pop | where _types = op::OpCodes.OpCode |
1452 | 88f25dd0 | Iustin Pop | |
1453 | 23fe06c2 | Iustin Pop | testSuite "OpCodes" |
1454 | d5dfae0a | Iustin Pop | [ 'prop_OpCodes_serialization ] |
1455 | c088674b | Iustin Pop | |
1456 | 525bfb36 | Iustin Pop | -- ** Jobs tests |
1457 | 525bfb36 | Iustin Pop | |
1458 | 525bfb36 | Iustin Pop | -- | Check that (queued) job\/opcode status serialization is idempotent. |
1459 | db079755 | Iustin Pop | prop_OpStatus_serialization os = |
1460 | db079755 | Iustin Pop | case J.readJSON (J.showJSON os) of |
1461 | 96bc2003 | Iustin Pop | J.Error e -> failTest $ "Cannot deserialise: " ++ e |
1462 | 72bb6b4e | Iustin Pop | J.Ok os' -> os ==? os' |
1463 | db079755 | Iustin Pop | where _types = os::Jobs.OpStatus |
1464 | db079755 | Iustin Pop | |
1465 | db079755 | Iustin Pop | prop_JobStatus_serialization js = |
1466 | db079755 | Iustin Pop | case J.readJSON (J.showJSON js) of |
1467 | 96bc2003 | Iustin Pop | J.Error e -> failTest $ "Cannot deserialise: " ++ e |
1468 | 72bb6b4e | Iustin Pop | J.Ok js' -> js ==? js' |
1469 | db079755 | Iustin Pop | where _types = js::Jobs.JobStatus |
1470 | db079755 | Iustin Pop | |
1471 | 23fe06c2 | Iustin Pop | testSuite "Jobs" |
1472 | d5dfae0a | Iustin Pop | [ 'prop_OpStatus_serialization |
1473 | d5dfae0a | Iustin Pop | , 'prop_JobStatus_serialization |
1474 | d5dfae0a | Iustin Pop | ] |
1475 | db079755 | Iustin Pop | |
1476 | 525bfb36 | Iustin Pop | -- ** Loader tests |
1477 | c088674b | Iustin Pop | |
1478 | c088674b | Iustin Pop | prop_Loader_lookupNode ktn inst node = |
1479 | 72bb6b4e | Iustin Pop | Loader.lookupNode nl inst node ==? Data.Map.lookup node nl |
1480 | d5dfae0a | Iustin Pop | where nl = Data.Map.fromList ktn |
1481 | c088674b | Iustin Pop | |
1482 | c088674b | Iustin Pop | prop_Loader_lookupInstance kti inst = |
1483 | 72bb6b4e | Iustin Pop | Loader.lookupInstance il inst ==? Data.Map.lookup inst il |
1484 | d5dfae0a | Iustin Pop | where il = Data.Map.fromList kti |
1485 | 99b63608 | Iustin Pop | |
1486 | 3074ccaf | Iustin Pop | prop_Loader_assignIndices = |
1487 | 3074ccaf | Iustin Pop | -- generate nodes with unique names |
1488 | 3074ccaf | Iustin Pop | forAll (arbitrary `suchThat` |
1489 | 3074ccaf | Iustin Pop | (\nodes -> |
1490 | 3074ccaf | Iustin Pop | let names = map Node.name nodes |
1491 | 3074ccaf | Iustin Pop | in length names == length (nub names))) $ \nodes -> |
1492 | 3074ccaf | Iustin Pop | let (nassoc, kt) = |
1493 | 3074ccaf | Iustin Pop | Loader.assignIndices (map (\n -> (Node.name n, n)) nodes) |
1494 | 3074ccaf | Iustin Pop | in Data.Map.size nassoc == length nodes && |
1495 | 3074ccaf | Iustin Pop | Container.size kt == length nodes && |
1496 | 3074ccaf | Iustin Pop | if not (null nodes) |
1497 | 3074ccaf | Iustin Pop | then maximum (IntMap.keys kt) == length nodes - 1 |
1498 | 3074ccaf | Iustin Pop | else True |
1499 | c088674b | Iustin Pop | |
1500 | c088674b | Iustin Pop | -- | Checks that the number of primary instances recorded on the nodes |
1501 | 525bfb36 | Iustin Pop | -- is zero. |
1502 | c088674b | Iustin Pop | prop_Loader_mergeData ns = |
1503 | cb0c77ff | Iustin Pop | let na = Container.fromList $ map (\n -> (Node.idx n, n)) ns |
1504 | 2d1708e0 | Guido Trotter | in case Loader.mergeData [] [] [] [] |
1505 | f4f6eb0b | Iustin Pop | (Loader.emptyCluster {Loader.cdNodes = na}) of |
1506 | c088674b | Iustin Pop | Types.Bad _ -> False |
1507 | 71375ef7 | Iustin Pop | Types.Ok (Loader.ClusterData _ nl il _ _) -> |
1508 | c088674b | Iustin Pop | let nodes = Container.elems nl |
1509 | c088674b | Iustin Pop | instances = Container.elems il |
1510 | c088674b | Iustin Pop | in (sum . map (length . Node.pList)) nodes == 0 && |
1511 | 4a007641 | Iustin Pop | null instances |
1512 | c088674b | Iustin Pop | |
1513 | efe98965 | Guido Trotter | -- | Check that compareNameComponent on equal strings works. |
1514 | efe98965 | Guido Trotter | prop_Loader_compareNameComponent_equal :: String -> Bool |
1515 | efe98965 | Guido Trotter | prop_Loader_compareNameComponent_equal s = |
1516 | efe98965 | Guido Trotter | Loader.compareNameComponent s s == |
1517 | efe98965 | Guido Trotter | Loader.LookupResult Loader.ExactMatch s |
1518 | efe98965 | Guido Trotter | |
1519 | efe98965 | Guido Trotter | -- | Check that compareNameComponent on prefix strings works. |
1520 | efe98965 | Guido Trotter | prop_Loader_compareNameComponent_prefix :: NonEmptyList Char -> String -> Bool |
1521 | efe98965 | Guido Trotter | prop_Loader_compareNameComponent_prefix (NonEmpty s1) s2 = |
1522 | efe98965 | Guido Trotter | Loader.compareNameComponent (s1 ++ "." ++ s2) s1 == |
1523 | efe98965 | Guido Trotter | Loader.LookupResult Loader.PartialMatch s1 |
1524 | efe98965 | Guido Trotter | |
1525 | 23fe06c2 | Iustin Pop | testSuite "Loader" |
1526 | d5dfae0a | Iustin Pop | [ 'prop_Loader_lookupNode |
1527 | d5dfae0a | Iustin Pop | , 'prop_Loader_lookupInstance |
1528 | d5dfae0a | Iustin Pop | , 'prop_Loader_assignIndices |
1529 | d5dfae0a | Iustin Pop | , 'prop_Loader_mergeData |
1530 | d5dfae0a | Iustin Pop | , 'prop_Loader_compareNameComponent_equal |
1531 | d5dfae0a | Iustin Pop | , 'prop_Loader_compareNameComponent_prefix |
1532 | d5dfae0a | Iustin Pop | ] |
1533 | 3c002a13 | Iustin Pop | |
1534 | 3c002a13 | Iustin Pop | -- ** Types tests |
1535 | 3c002a13 | Iustin Pop | |
1536 | 0047d4e2 | Iustin Pop | prop_Types_AllocPolicy_serialisation apol = |
1537 | d5dfae0a | Iustin Pop | case J.readJSON (J.showJSON apol) of |
1538 | aa1d552d | Iustin Pop | J.Ok p -> p ==? apol |
1539 | 96bc2003 | Iustin Pop | J.Error s -> failTest $ "Failed to deserialise: " ++ s |
1540 | d5dfae0a | Iustin Pop | where _types = apol::Types.AllocPolicy |
1541 | 0047d4e2 | Iustin Pop | |
1542 | 0047d4e2 | Iustin Pop | prop_Types_DiskTemplate_serialisation dt = |
1543 | d5dfae0a | Iustin Pop | case J.readJSON (J.showJSON dt) of |
1544 | aa1d552d | Iustin Pop | J.Ok p -> p ==? dt |
1545 | 96bc2003 | Iustin Pop | J.Error s -> failTest $ "Failed to deserialise: " ++ s |
1546 | d5dfae0a | Iustin Pop | where _types = dt::Types.DiskTemplate |
1547 | 0047d4e2 | Iustin Pop | |
1548 | aa1d552d | Iustin Pop | prop_Types_ISpec_serialisation ispec = |
1549 | aa1d552d | Iustin Pop | case J.readJSON (J.showJSON ispec) of |
1550 | aa1d552d | Iustin Pop | J.Ok p -> p ==? ispec |
1551 | 96bc2003 | Iustin Pop | J.Error s -> failTest $ "Failed to deserialise: " ++ s |
1552 | aa1d552d | Iustin Pop | where _types = ispec::Types.ISpec |
1553 | aa1d552d | Iustin Pop | |
1554 | aa1d552d | Iustin Pop | prop_Types_IPolicy_serialisation ipol = |
1555 | aa1d552d | Iustin Pop | case J.readJSON (J.showJSON ipol) of |
1556 | aa1d552d | Iustin Pop | J.Ok p -> p ==? ipol |
1557 | 96bc2003 | Iustin Pop | J.Error s -> failTest $ "Failed to deserialise: " ++ s |
1558 | aa1d552d | Iustin Pop | where _types = ipol::Types.IPolicy |
1559 | aa1d552d | Iustin Pop | |
1560 | aa1d552d | Iustin Pop | prop_Types_EvacMode_serialisation em = |
1561 | aa1d552d | Iustin Pop | case J.readJSON (J.showJSON em) of |
1562 | aa1d552d | Iustin Pop | J.Ok p -> p ==? em |
1563 | 96bc2003 | Iustin Pop | J.Error s -> failTest $ "Failed to deserialise: " ++ s |
1564 | aa1d552d | Iustin Pop | where _types = em::Types.EvacMode |
1565 | aa1d552d | Iustin Pop | |
1566 | 0047d4e2 | Iustin Pop | prop_Types_opToResult op = |
1567 | d5dfae0a | Iustin Pop | case op of |
1568 | d5dfae0a | Iustin Pop | Types.OpFail _ -> Types.isBad r |
1569 | d5dfae0a | Iustin Pop | Types.OpGood v -> case r of |
1570 | d5dfae0a | Iustin Pop | Types.Bad _ -> False |
1571 | d5dfae0a | Iustin Pop | Types.Ok v' -> v == v' |
1572 | d5dfae0a | Iustin Pop | where r = Types.opToResult op |
1573 | d5dfae0a | Iustin Pop | _types = op::Types.OpResult Int |
1574 | 0047d4e2 | Iustin Pop | |
1575 | 0047d4e2 | Iustin Pop | prop_Types_eitherToResult ei = |
1576 | d5dfae0a | Iustin Pop | case ei of |
1577 | d5dfae0a | Iustin Pop | Left _ -> Types.isBad r |
1578 | d5dfae0a | Iustin Pop | Right v -> case r of |
1579 | d5dfae0a | Iustin Pop | Types.Bad _ -> False |
1580 | d5dfae0a | Iustin Pop | Types.Ok v' -> v == v' |
1581 | 0047d4e2 | Iustin Pop | where r = Types.eitherToResult ei |
1582 | 0047d4e2 | Iustin Pop | _types = ei::Either String Int |
1583 | 3c002a13 | Iustin Pop | |
1584 | 23fe06c2 | Iustin Pop | testSuite "Types" |
1585 | d5dfae0a | Iustin Pop | [ 'prop_Types_AllocPolicy_serialisation |
1586 | d5dfae0a | Iustin Pop | , 'prop_Types_DiskTemplate_serialisation |
1587 | aa1d552d | Iustin Pop | , 'prop_Types_ISpec_serialisation |
1588 | aa1d552d | Iustin Pop | , 'prop_Types_IPolicy_serialisation |
1589 | aa1d552d | Iustin Pop | , 'prop_Types_EvacMode_serialisation |
1590 | d5dfae0a | Iustin Pop | , 'prop_Types_opToResult |
1591 | d5dfae0a | Iustin Pop | , 'prop_Types_eitherToResult |
1592 | d5dfae0a | Iustin Pop | ] |
1593 | 8b5a517a | Iustin Pop | |
1594 | 8b5a517a | Iustin Pop | -- ** CLI tests |
1595 | 8b5a517a | Iustin Pop | |
1596 | 8b5a517a | Iustin Pop | -- | Test correct parsing. |
1597 | 8b5a517a | Iustin Pop | prop_CLI_parseISpec descr dsk mem cpu = |
1598 | 8b5a517a | Iustin Pop | let str = printf "%d,%d,%d" dsk mem cpu |
1599 | 8b5a517a | Iustin Pop | in CLI.parseISpecString descr str ==? Types.Ok (Types.RSpec cpu mem dsk) |
1600 | 8b5a517a | Iustin Pop | |
1601 | 8b5a517a | Iustin Pop | -- | Test parsing failure due to wrong section count. |
1602 | 8b5a517a | Iustin Pop | prop_CLI_parseISpecFail descr = |
1603 | 8b5a517a | Iustin Pop | forAll (choose (0,100) `suchThat` ((/=) 3)) $ \nelems -> |
1604 | 8b5a517a | Iustin Pop | forAll (replicateM nelems arbitrary) $ \values -> |
1605 | 8b5a517a | Iustin Pop | let str = intercalate "," $ map show (values::[Int]) |
1606 | 8b5a517a | Iustin Pop | in case CLI.parseISpecString descr str of |
1607 | 8b5a517a | Iustin Pop | Types.Ok v -> failTest $ "Expected failure, got " ++ show v |
1608 | 8b5a517a | Iustin Pop | _ -> property True |
1609 | 8b5a517a | Iustin Pop | |
1610 | a7ea861a | Iustin Pop | -- | Test parseYesNo. |
1611 | a7ea861a | Iustin Pop | prop_CLI_parseYesNo def testval val = |
1612 | a7ea861a | Iustin Pop | forAll (elements [val, "yes", "no"]) $ \actual_val -> |
1613 | a7ea861a | Iustin Pop | if testval |
1614 | a7ea861a | Iustin Pop | then CLI.parseYesNo def Nothing ==? Types.Ok def |
1615 | a7ea861a | Iustin Pop | else let result = CLI.parseYesNo def (Just actual_val) |
1616 | a7ea861a | Iustin Pop | in if actual_val `elem` ["yes", "no"] |
1617 | a7ea861a | Iustin Pop | then result ==? Types.Ok (actual_val == "yes") |
1618 | a7ea861a | Iustin Pop | else property $ Types.isBad result |
1619 | a7ea861a | Iustin Pop | |
1620 | 89298c04 | Iustin Pop | -- | Helper to check for correct parsing of string arg. |
1621 | 89298c04 | Iustin Pop | checkStringArg val (opt, fn) = |
1622 | 89298c04 | Iustin Pop | let GetOpt.Option _ longs _ _ = opt |
1623 | 89298c04 | Iustin Pop | in case longs of |
1624 | 89298c04 | Iustin Pop | [] -> failTest "no long options?" |
1625 | 89298c04 | Iustin Pop | cmdarg:_ -> |
1626 | 89298c04 | Iustin Pop | case CLI.parseOptsInner ["--" ++ cmdarg ++ "=" ++ val] "prog" [opt] of |
1627 | 89298c04 | Iustin Pop | Left e -> failTest $ "Failed to parse option: " ++ show e |
1628 | 89298c04 | Iustin Pop | Right (options, _) -> fn options ==? Just val |
1629 | 89298c04 | Iustin Pop | |
1630 | 89298c04 | Iustin Pop | -- | Test a few string arguments. |
1631 | 89298c04 | Iustin Pop | prop_CLI_StringArg argument = |
1632 | 89298c04 | Iustin Pop | let args = [ (CLI.oDataFile, CLI.optDataFile) |
1633 | 89298c04 | Iustin Pop | , (CLI.oDynuFile, CLI.optDynuFile) |
1634 | 89298c04 | Iustin Pop | , (CLI.oSaveCluster, CLI.optSaveCluster) |
1635 | 89298c04 | Iustin Pop | , (CLI.oReplay, CLI.optReplay) |
1636 | 89298c04 | Iustin Pop | , (CLI.oPrintCommands, CLI.optShowCmds) |
1637 | 89298c04 | Iustin Pop | , (CLI.oLuxiSocket, CLI.optLuxi) |
1638 | 89298c04 | Iustin Pop | ] |
1639 | 89298c04 | Iustin Pop | in conjoin $ map (checkStringArg argument) args |
1640 | 89298c04 | Iustin Pop | |
1641 | a292b4e0 | Iustin Pop | -- | Helper to test that a given option is accepted OK with quick exit. |
1642 | a292b4e0 | Iustin Pop | checkEarlyExit name options param = |
1643 | a292b4e0 | Iustin Pop | case CLI.parseOptsInner [param] name options of |
1644 | a292b4e0 | Iustin Pop | Left (code, _) -> if code == 0 |
1645 | a292b4e0 | Iustin Pop | then property True |
1646 | a292b4e0 | Iustin Pop | else failTest $ "Program " ++ name ++ |
1647 | a292b4e0 | Iustin Pop | " returns invalid code " ++ show code ++ |
1648 | a292b4e0 | Iustin Pop | " for option " ++ param |
1649 | a292b4e0 | Iustin Pop | _ -> failTest $ "Program " ++ name ++ " doesn't consider option " ++ |
1650 | a292b4e0 | Iustin Pop | param ++ " as early exit one" |
1651 | a292b4e0 | Iustin Pop | |
1652 | a292b4e0 | Iustin Pop | -- | Test that all binaries support some common options. There is |
1653 | a292b4e0 | Iustin Pop | -- nothing actually random about this test... |
1654 | a292b4e0 | Iustin Pop | prop_CLI_stdopts = |
1655 | a292b4e0 | Iustin Pop | let params = ["-h", "--help", "-V", "--version"] |
1656 | a292b4e0 | Iustin Pop | opts = map (\(name, (_, o)) -> (name, o)) Program.personalities |
1657 | a292b4e0 | Iustin Pop | -- apply checkEarlyExit across the cartesian product of params and opts |
1658 | a292b4e0 | Iustin Pop | in conjoin [checkEarlyExit n o p | p <- params, (n, o) <- opts] |
1659 | a292b4e0 | Iustin Pop | |
1660 | 8b5a517a | Iustin Pop | testSuite "CLI" |
1661 | 8b5a517a | Iustin Pop | [ 'prop_CLI_parseISpec |
1662 | 8b5a517a | Iustin Pop | , 'prop_CLI_parseISpecFail |
1663 | a7ea861a | Iustin Pop | , 'prop_CLI_parseYesNo |
1664 | 89298c04 | Iustin Pop | , 'prop_CLI_StringArg |
1665 | a292b4e0 | Iustin Pop | , 'prop_CLI_stdopts |
1666 | 8b5a517a | Iustin Pop | ] |
1667 | 3ad57194 | Iustin Pop | |
1668 | 3ad57194 | Iustin Pop | -- * JSON tests |
1669 | 3ad57194 | Iustin Pop | |
1670 | 3ad57194 | Iustin Pop | prop_JSON_toArray :: [Int] -> Property |
1671 | 3ad57194 | Iustin Pop | prop_JSON_toArray intarr = |
1672 | 3ad57194 | Iustin Pop | let arr = map J.showJSON intarr in |
1673 | 3ad57194 | Iustin Pop | case JSON.toArray (J.JSArray arr) of |
1674 | 3ad57194 | Iustin Pop | Types.Ok arr' -> arr ==? arr' |
1675 | 3ad57194 | Iustin Pop | Types.Bad err -> failTest $ "Failed to parse array: " ++ err |
1676 | 3ad57194 | Iustin Pop | |
1677 | 3ad57194 | Iustin Pop | prop_JSON_toArrayFail :: Int -> String -> Bool -> Property |
1678 | 3ad57194 | Iustin Pop | prop_JSON_toArrayFail i s b = |
1679 | 3ad57194 | Iustin Pop | -- poor man's instance Arbitrary JSValue |
1680 | 3ad57194 | Iustin Pop | forAll (elements [J.showJSON i, J.showJSON s, J.showJSON b]) $ \item -> |
1681 | 3ad57194 | Iustin Pop | case JSON.toArray item of |
1682 | 3ad57194 | Iustin Pop | Types.Bad _ -> property True |
1683 | 3ad57194 | Iustin Pop | Types.Ok result -> failTest $ "Unexpected parse, got " ++ show result |
1684 | 3ad57194 | Iustin Pop | |
1685 | 3ad57194 | Iustin Pop | testSuite "JSON" |
1686 | 3ad57194 | Iustin Pop | [ 'prop_JSON_toArray |
1687 | 3ad57194 | Iustin Pop | , 'prop_JSON_toArrayFail |
1688 | 3ad57194 | Iustin Pop | ] |
1689 | cdd495ae | Iustin Pop | |
1690 | cdd495ae | Iustin Pop | -- * Luxi tests |
1691 | cdd495ae | Iustin Pop | |
1692 | cdd495ae | Iustin Pop | instance Arbitrary Luxi.LuxiReq where |
1693 | cdd495ae | Iustin Pop | arbitrary = elements [minBound..maxBound] |
1694 | cdd495ae | Iustin Pop | |
1695 | cdd495ae | Iustin Pop | instance Arbitrary Luxi.QrViaLuxi where |
1696 | cdd495ae | Iustin Pop | arbitrary = elements [minBound..maxBound] |
1697 | cdd495ae | Iustin Pop | |
1698 | cdd495ae | Iustin Pop | instance Arbitrary Luxi.LuxiOp where |
1699 | cdd495ae | Iustin Pop | arbitrary = do |
1700 | cdd495ae | Iustin Pop | lreq <- arbitrary |
1701 | cdd495ae | Iustin Pop | case lreq of |
1702 | cdd495ae | Iustin Pop | Luxi.ReqQuery -> Luxi.Query <$> arbitrary <*> getFields <*> arbitrary |
1703 | cdd495ae | Iustin Pop | Luxi.ReqQueryNodes -> Luxi.QueryNodes <$> (listOf getFQDN) <*> |
1704 | cdd495ae | Iustin Pop | getFields <*> arbitrary |
1705 | cdd495ae | Iustin Pop | Luxi.ReqQueryGroups -> Luxi.QueryGroups <$> arbitrary <*> |
1706 | cdd495ae | Iustin Pop | arbitrary <*> arbitrary |
1707 | cdd495ae | Iustin Pop | Luxi.ReqQueryInstances -> Luxi.QueryInstances <$> (listOf getFQDN) <*> |
1708 | cdd495ae | Iustin Pop | getFields <*> arbitrary |
1709 | cdd495ae | Iustin Pop | Luxi.ReqQueryJobs -> Luxi.QueryJobs <$> arbitrary <*> getFields |
1710 | cdd495ae | Iustin Pop | Luxi.ReqQueryExports -> Luxi.QueryExports <$> |
1711 | cdd495ae | Iustin Pop | (listOf getFQDN) <*> arbitrary |
1712 | cdd495ae | Iustin Pop | Luxi.ReqQueryConfigValues -> Luxi.QueryConfigValues <$> getFields |
1713 | cdd495ae | Iustin Pop | Luxi.ReqQueryClusterInfo -> pure Luxi.QueryClusterInfo |
1714 | cdd495ae | Iustin Pop | Luxi.ReqQueryTags -> Luxi.QueryTags <$> getName <*> getFQDN |
1715 | cdd495ae | Iustin Pop | Luxi.ReqSubmitJob -> Luxi.SubmitJob <$> (resize maxOpCodes arbitrary) |
1716 | cdd495ae | Iustin Pop | Luxi.ReqSubmitManyJobs -> Luxi.SubmitManyJobs <$> |
1717 | cdd495ae | Iustin Pop | (resize maxOpCodes arbitrary) |
1718 | cdd495ae | Iustin Pop | Luxi.ReqWaitForJobChange -> Luxi.WaitForJobChange <$> arbitrary <*> |
1719 | cdd495ae | Iustin Pop | getFields <*> pure J.JSNull <*> |
1720 | cdd495ae | Iustin Pop | pure J.JSNull <*> arbitrary |
1721 | cdd495ae | Iustin Pop | Luxi.ReqArchiveJob -> Luxi.ArchiveJob <$> arbitrary |
1722 | cdd495ae | Iustin Pop | Luxi.ReqAutoArchiveJobs -> Luxi.AutoArchiveJobs <$> arbitrary <*> |
1723 | cdd495ae | Iustin Pop | arbitrary |
1724 | cdd495ae | Iustin Pop | Luxi.ReqCancelJob -> Luxi.CancelJob <$> arbitrary |
1725 | cdd495ae | Iustin Pop | Luxi.ReqSetDrainFlag -> Luxi.SetDrainFlag <$> arbitrary |
1726 | cdd495ae | Iustin Pop | Luxi.ReqSetWatcherPause -> Luxi.SetWatcherPause <$> arbitrary |
1727 | cdd495ae | Iustin Pop | |
1728 | cdd495ae | Iustin Pop | -- | Simple check that encoding/decoding of LuxiOp works. |
1729 | cdd495ae | Iustin Pop | prop_Luxi_CallEncoding :: Luxi.LuxiOp -> Property |
1730 | cdd495ae | Iustin Pop | prop_Luxi_CallEncoding op = |
1731 | cdd495ae | Iustin Pop | (Luxi.validateCall (Luxi.buildCall op) >>= Luxi.decodeCall) ==? Types.Ok op |
1732 | cdd495ae | Iustin Pop | |
1733 | cdd495ae | Iustin Pop | testSuite "LUXI" |
1734 | cdd495ae | Iustin Pop | [ 'prop_Luxi_CallEncoding |
1735 | cdd495ae | Iustin Pop | ] |
1736 | c5b4a186 | Iustin Pop | |
1737 | c5b4a186 | Iustin Pop | -- * Ssconf tests |
1738 | c5b4a186 | Iustin Pop | |
1739 | c5b4a186 | Iustin Pop | instance Arbitrary Ssconf.SSKey where |
1740 | c5b4a186 | Iustin Pop | arbitrary = elements [minBound..maxBound] |
1741 | c5b4a186 | Iustin Pop | |
1742 | c5b4a186 | Iustin Pop | prop_Ssconf_filename key = |
1743 | c5b4a186 | Iustin Pop | printTestCase "Key doesn't start with correct prefix" $ |
1744 | c5b4a186 | Iustin Pop | Ssconf.sSFilePrefix `isPrefixOf` Ssconf.keyToFilename (Just "") key |
1745 | c5b4a186 | Iustin Pop | |
1746 | c5b4a186 | Iustin Pop | testSuite "Ssconf" |
1747 | c5b4a186 | Iustin Pop | [ 'prop_Ssconf_filename |
1748 | c5b4a186 | Iustin Pop | ] |