QC.hs 76.9 KB
Newer Older
1
{-# LANGUAGE TemplateHaskell #-}
2
3
4
5
6
7
{-# OPTIONS_GHC -fno-warn-orphans -fno-warn-unused-imports #-}

-- FIXME: should remove the no-warn-unused-imports option, once we get
-- around to testing function from all modules; until then, we keep
-- the (unused) imports here to generate correct coverage (0 for
-- modules we don't use)
8

9
{-| Unittests for ganeti-htools.
Iustin Pop's avatar
Iustin Pop committed
10
11
12
13
14

-}

{-

Iustin Pop's avatar
Iustin Pop committed
15
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
Iustin Pop's avatar
Iustin Pop committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.

-}

34
module Ganeti.HTools.QC
Iustin Pop's avatar
Iustin Pop committed
35
36
37
38
39
40
  ( testUtils
  , testPeerMap
  , testContainer
  , testInstance
  , testNode
  , testText
41
  , testSimu
Iustin Pop's avatar
Iustin Pop committed
42
43
44
45
46
  , testOpCodes
  , testJobs
  , testCluster
  , testLoader
  , testTypes
47
  , testCLI
Iustin Pop's avatar
Iustin Pop committed
48
  , testJSON
49
  , testLUXI
50
  , testSsconf
Agata Murawska's avatar
Agata Murawska committed
51
  , testRpc
Iustin Pop's avatar
Iustin Pop committed
52
  , testQlang
Iustin Pop's avatar
Iustin Pop committed
53
  ) where
54
55

import Test.QuickCheck
Agata Murawska's avatar
Agata Murawska committed
56
import Test.QuickCheck.Monadic (assert, monadicIO, run, stop)
57
import Text.Printf (printf)
58
import Data.List (intercalate, nub, isPrefixOf)
59
import Data.Maybe
60
import qualified Data.Set as Set
Iustin Pop's avatar
Iustin Pop committed
61
import Control.Monad
Iustin Pop's avatar
Iustin Pop committed
62
import Control.Applicative
Iustin Pop's avatar
Iustin Pop committed
63
import qualified System.Console.GetOpt as GetOpt
Iustin Pop's avatar
Iustin Pop committed
64
import qualified Text.JSON as J
Iustin Pop's avatar
Iustin Pop committed
65
import qualified Data.Map
66
import qualified Data.IntMap as IntMap
67
68
69
70
71
import Control.Concurrent (forkIO)
import Control.Exception (bracket, catchJust)
import System.Directory (getTemporaryDirectory, removeFile)
import System.IO (hClose, openTempFile)
import System.IO.Error (isEOFErrorType, ioeGetErrorType)
Iustin Pop's avatar
Iustin Pop committed
72

Iustin Pop's avatar
Iustin Pop committed
73
74
75
76
import qualified Ganeti.Confd as Confd
import qualified Ganeti.Config as Config
import qualified Ganeti.Daemon as Daemon
import qualified Ganeti.Hash as Hash
Iustin Pop's avatar
Iustin Pop committed
77
import qualified Ganeti.BasicTypes as BasicTypes
78
import qualified Ganeti.Jobs as Jobs
Iustin Pop's avatar
Iustin Pop committed
79
import qualified Ganeti.Logging as Logging
80
import qualified Ganeti.Luxi as Luxi
Iustin Pop's avatar
Iustin Pop committed
81
82
import qualified Ganeti.Objects as Objects
import qualified Ganeti.OpCodes as OpCodes
Iustin Pop's avatar
Iustin Pop committed
83
import qualified Ganeti.Qlang as Qlang
84
import qualified Ganeti.Rpc as Rpc
Iustin Pop's avatar
Iustin Pop committed
85
import qualified Ganeti.Runtime as Runtime
86
import qualified Ganeti.Ssconf as Ssconf
87
88
89
import qualified Ganeti.HTools.CLI as CLI
import qualified Ganeti.HTools.Cluster as Cluster
import qualified Ganeti.HTools.Container as Container
Iustin Pop's avatar
Iustin Pop committed
90
import qualified Ganeti.HTools.ExtLoader
Iustin Pop's avatar
Iustin Pop committed
91
import qualified Ganeti.HTools.Group as Group
92
93
import qualified Ganeti.HTools.IAlloc as IAlloc
import qualified Ganeti.HTools.Instance as Instance
94
import qualified Ganeti.HTools.JSON as JSON
95
import qualified Ganeti.HTools.Loader as Loader
96
import qualified Ganeti.HTools.Luxi as HTools.Luxi
97
98
import qualified Ganeti.HTools.Node as Node
import qualified Ganeti.HTools.PeerMap as PeerMap
99
import qualified Ganeti.HTools.Rapi
100
import qualified Ganeti.HTools.Simu as Simu
101
102
103
import qualified Ganeti.HTools.Text as Text
import qualified Ganeti.HTools.Types as Types
import qualified Ganeti.HTools.Utils as Utils
Iustin Pop's avatar
Iustin Pop committed
104
import qualified Ganeti.HTools.Version
105
import qualified Ganeti.Constants as C
106

107
import qualified Ganeti.HTools.Program as Program
108
109
110
111
112
import qualified Ganeti.HTools.Program.Hail
import qualified Ganeti.HTools.Program.Hbal
import qualified Ganeti.HTools.Program.Hscan
import qualified Ganeti.HTools.Program.Hspace

113
import Ganeti.HTools.QCHelper (testSuite)
Iustin Pop's avatar
Iustin Pop committed
114

115
116
-- * Constants

117
-- | Maximum memory (1TiB, somewhat random value).
Iustin Pop's avatar
Iustin Pop committed
118
119
120
maxMem :: Int
maxMem = 1024 * 1024

121
-- | Maximum disk (8TiB, somewhat random value).
Iustin Pop's avatar
Iustin Pop committed
122
maxDsk :: Int
Iustin Pop's avatar
Iustin Pop committed
123
maxDsk = 1024 * 1024 * 8
Iustin Pop's avatar
Iustin Pop committed
124

125
-- | Max CPUs (1024, somewhat random value).
Iustin Pop's avatar
Iustin Pop committed
126
127
128
maxCpu :: Int
maxCpu = 1024

129
130
131
132
133
134
135
136
-- | Max vcpu ratio (random value).
maxVcpuRatio :: Double
maxVcpuRatio = 1024.0

-- | Max spindle ratio (random value).
maxSpindleRatio :: Double
maxSpindleRatio = 1024.0

Iustin Pop's avatar
Iustin Pop committed
137
138
139
140
141
142
143
144
145
-- | Max nodes, used just to limit arbitrary instances for smaller
-- opcode definitions (e.g. list of nodes in OpTestDelay).
maxNodes :: Int
maxNodes = 32

-- | Max opcodes or jobs in a submit job and submit many jobs.
maxOpCodes :: Int
maxOpCodes = 16

146
147
148
149
-- | All disk templates (used later)
allDiskTemplates :: [Types.DiskTemplate]
allDiskTemplates = [minBound..maxBound]

150
-- | Null iPolicy, and by null we mean very liberal.
151
nullIPolicy :: Types.IPolicy
152
153
154
155
156
157
nullIPolicy = Types.IPolicy
  { Types.iPolicyMinSpec = Types.ISpec { Types.iSpecMemorySize = 0
                                       , Types.iSpecCpuCount   = 0
                                       , Types.iSpecDiskSize   = 0
                                       , Types.iSpecDiskCount  = 0
                                       , Types.iSpecNicCount   = 0
158
                                       , Types.iSpecSpindleUse = 0
159
160
161
162
163
164
                                       }
  , Types.iPolicyMaxSpec = Types.ISpec { Types.iSpecMemorySize = maxBound
                                       , Types.iSpecCpuCount   = maxBound
                                       , Types.iSpecDiskSize   = maxBound
                                       , Types.iSpecDiskCount  = C.maxDisks
                                       , Types.iSpecNicCount   = C.maxNics
165
                                       , Types.iSpecSpindleUse = maxBound
166
167
168
169
170
171
                                       }
  , Types.iPolicyStdSpec = Types.ISpec { Types.iSpecMemorySize = Types.unitMem
                                       , Types.iSpecCpuCount   = Types.unitCpu
                                       , Types.iSpecDiskSize   = Types.unitDsk
                                       , Types.iSpecDiskCount  = 1
                                       , Types.iSpecNicCount   = 1
172
                                       , Types.iSpecSpindleUse = 1
173
                                       }
174
  , Types.iPolicyDiskTemplates = [minBound..maxBound]
175
176
177
  , Types.iPolicyVcpuRatio = maxVcpuRatio -- somewhat random value, high
                                          -- enough to not impact us
  , Types.iPolicySpindleRatio = maxSpindleRatio
178
179
180
  }


Iustin Pop's avatar
Iustin Pop committed
181
182
defGroup :: Group.Group
defGroup = flip Group.setIdx 0 $
Iustin Pop's avatar
Iustin Pop committed
183
             Group.create "default" Types.defaultGroupID Types.AllocPreferred
184
                  nullIPolicy
Iustin Pop's avatar
Iustin Pop committed
185
186

defGroupList :: Group.List
Iustin Pop's avatar
Iustin Pop committed
187
defGroupList = Container.fromList [(Group.idx defGroup, defGroup)]
Iustin Pop's avatar
Iustin Pop committed
188
189
190
191

defGroupAssoc :: Data.Map.Map String Types.Gdx
defGroupAssoc = Data.Map.singleton (Group.uuid defGroup) (Group.idx defGroup)

192
193
-- * Helper functions

194
-- | Simple checker for whether OpResult is fail or pass.
Iustin Pop's avatar
Iustin Pop committed
195
196
197
198
isFailure :: Types.OpResult a -> Bool
isFailure (Types.OpFail _) = True
isFailure _ = False

Iustin Pop's avatar
Iustin Pop committed
199
200
201
202
203
204
205
-- | Checks for equality with proper annotation.
(==?) :: (Show a, Eq a) => a -> a -> Property
(==?) x y = printTestCase
            ("Expected equality, but '" ++
             show x ++ "' /= '" ++ show y ++ "'") (x == y)
infix 3 ==?

Iustin Pop's avatar
Iustin Pop committed
206
207
208
209
-- | Show a message and fail the test.
failTest :: String -> Property
failTest msg = printTestCase msg False

210
-- | Update an instance to be smaller than a node.
211
212
setInstanceSmallerThanNode :: Node.Node
                           -> Instance.Instance -> Instance.Instance
213
setInstanceSmallerThanNode node inst =
Iustin Pop's avatar
Iustin Pop committed
214
215
216
217
  inst { Instance.mem = Node.availMem node `div` 2
       , Instance.dsk = Node.availDisk node `div` 2
       , Instance.vcpus = Node.availCpu node `div` 2
       }
218

219
-- | Create an instance given its spec.
220
createInstance :: Int -> Int -> Int -> Instance.Instance
221
createInstance mem dsk vcpus =
Iustin Pop's avatar
Iustin Pop committed
222
  Instance.create "inst-unnamed" mem dsk vcpus Types.Running [] True (-1) (-1)
223
    Types.DTDrbd8 1
224

225
-- | Create a small cluster by repeating a node spec.
226
227
makeSmallCluster :: Node.Node -> Int -> Node.List
makeSmallCluster node count =
228
229
230
231
232
233
234
  let origname = Node.name node
      origalias = Node.alias node
      nodes = map (\idx -> node { Node.name = origname ++ "-" ++ show idx
                                , Node.alias = origalias ++ "-" ++ show idx })
              [1..count]
      fn = flip Node.buildPeers Container.empty
      namelst = map (\n -> (Node.name n, fn n)) nodes
Iustin Pop's avatar
Iustin Pop committed
235
236
      (_, nlst) = Loader.assignIndices namelst
  in nlst
237

Iustin Pop's avatar
Iustin Pop committed
238
239
240
241
242
243
244
-- | Make a small cluster, both nodes and instances.
makeSmallEmptyCluster :: Node.Node -> Int -> Instance.Instance
                      -> (Node.List, Instance.List, Instance.Instance)
makeSmallEmptyCluster node count inst =
  (makeSmallCluster node count, Container.empty,
   setInstanceSmallerThanNode node inst)

245
-- | Checks if a node is "big" enough.
246
247
isNodeBig :: Int -> Node.Node -> Bool
isNodeBig size node = Node.availDisk node > size * Types.unitDsk
248
249
250
                      && Node.availMem node > size * Types.unitMem
                      && Node.availCpu node > size * Types.unitCpu

251
252
canBalance :: Cluster.Table -> Bool -> Bool -> Bool -> Bool
canBalance tbl dm im evac = isJust $ Cluster.tryBalance tbl dm im evac 0 0
253

254
-- | Assigns a new fresh instance to a cluster; this is not
255
-- allocation, so no resource checks are done.
256
257
258
259
260
261
262
assignInstance :: Node.List -> Instance.List -> Instance.Instance ->
                  Types.Idx -> Types.Idx ->
                  (Node.List, Instance.List)
assignInstance nl il inst pdx sdx =
  let pnode = Container.find pdx nl
      snode = Container.find sdx nl
      maxiidx = if Container.null il
Iustin Pop's avatar
Iustin Pop committed
263
264
                  then 0
                  else fst (Container.findMax il) + 1
265
266
267
268
269
270
271
272
      inst' = inst { Instance.idx = maxiidx,
                     Instance.pNode = pdx, Instance.sNode = sdx }
      pnode' = Node.setPri pnode inst'
      snode' = Node.setSec snode inst'
      nl' = Container.addTwo pdx pnode' sdx snode' nl
      il' = Container.add maxiidx inst' il
  in (nl', il')

273
274
275
276
277
278
279
-- | Generates a list of a given size with non-duplicate elements.
genUniquesList :: (Eq a, Arbitrary a) => Int -> Gen [a]
genUniquesList cnt =
  foldM (\lst _ -> do
           newelem <- arbitrary `suchThat` (`notElem` lst)
           return (newelem:lst)) [] [1..cnt]

280
281
-- | Checks if an instance is mirrored.
isMirrored :: Instance.Instance -> Bool
282
isMirrored = (/= Types.MirrorNone) . Instance.mirrorType
283
284
285
286
287
288
289

-- | Returns the possible change node types for a disk template.
evacModeOptions :: Types.MirrorType -> [Types.EvacMode]
evacModeOptions Types.MirrorNone     = []
evacModeOptions Types.MirrorInternal = [minBound..maxBound] -- DRBD can do all
evacModeOptions Types.MirrorExternal = [Types.ChangePrimary, Types.ChangeAll]

290
291
-- * Arbitrary instances

292
-- | Defines a DNS name.
293
newtype DNSChar = DNSChar { dnsGetChar::Char }
294

295
instance Arbitrary DNSChar where
Iustin Pop's avatar
Iustin Pop committed
296
297
298
  arbitrary = do
    x <- elements (['a'..'z'] ++ ['0'..'9'] ++ "_-")
    return (DNSChar x)
299

300
301
302
instance Show DNSChar where
  show = show . dnsGetChar

303
-- | Generates a single name component.
304
305
306
getName :: Gen String
getName = do
  n <- choose (1, 64)
Iustin Pop's avatar
Iustin Pop committed
307
  dn <- vector n
308
309
  return (map dnsGetChar dn)

310
-- | Generates an entire FQDN.
311
312
313
getFQDN :: Gen String
getFQDN = do
  ncomps <- choose (1, 4)
Iustin Pop's avatar
Iustin Pop committed
314
  names <- vectorOf ncomps getName
315
  return $ intercalate "." names
316

Iustin Pop's avatar
Iustin Pop committed
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
-- | Combinator that generates a 'Maybe' using a sub-combinator.
getMaybe :: Gen a -> Gen (Maybe a)
getMaybe subgen = do
  bool <- arbitrary
  if bool
    then Just <$> subgen
    else return Nothing

-- | Generates a fields list. This uses the same character set as a
-- DNS name (just for simplicity).
getFields :: Gen [String]
getFields = do
  n <- choose (1, 32)
  vectorOf n getName

332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
-- | Defines a tag type.
newtype TagChar = TagChar { tagGetChar :: Char }

-- | All valid tag chars. This doesn't need to match _exactly_
-- Ganeti's own tag regex, just enough for it to be close.
tagChar :: [Char]
tagChar = ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ ".+*/:@-"

instance Arbitrary TagChar where
  arbitrary = do
    c <- elements tagChar
    return (TagChar c)

-- | Generates a tag
genTag :: Gen [TagChar]
genTag = do
  -- the correct value would be C.maxTagLen, but that's way too
  -- verbose in unittests, and at the moment I don't see any possible
  -- bugs with longer tags and the way we use tags in htools
  n <- choose (1, 10)
  vector n

-- | Generates a list of tags (correctly upper bounded).
genTags :: Gen [String]
genTags = do
  -- the correct value would be C.maxTagsPerObj, but per the comment
  -- in genTag, we don't use tags enough in htools to warrant testing
  -- such big values
  n <- choose (0, 10::Int)
  tags <- mapM (const genTag) [1..n]
  return $ map (map tagGetChar) tags

364
instance Arbitrary Types.InstanceStatus where
365
    arbitrary = elements [minBound..maxBound]
366

367
368
369
370
371
372
373
374
375
376
-- | Generates a random instance with maximum disk/mem/cpu values.
genInstanceSmallerThan :: Int -> Int -> Int -> Gen Instance.Instance
genInstanceSmallerThan lim_mem lim_dsk lim_cpu = do
  name <- getFQDN
  mem <- choose (0, lim_mem)
  dsk <- choose (0, lim_dsk)
  run_st <- arbitrary
  pn <- arbitrary
  sn <- arbitrary
  vcpus <- choose (0, lim_cpu)
377
378
  dt <- arbitrary
  return $ Instance.create name mem dsk vcpus run_st [] True pn sn dt 1
379
380
381
382
383
384
385
386

-- | Generates an instance smaller than a node.
genInstanceSmallerThanNode :: Node.Node -> Gen Instance.Instance
genInstanceSmallerThanNode node =
  genInstanceSmallerThan (Node.availMem node `div` 2)
                         (Node.availDisk node `div` 2)
                         (Node.availCpu node `div` 2)

387
388
-- let's generate a random instance
instance Arbitrary Instance.Instance where
389
  arbitrary = genInstanceSmallerThan maxMem maxDsk maxCpu
390

391
392
393
394
395
-- | Generas an arbitrary node based on sizing information.
genNode :: Maybe Int -- ^ Minimum node size in terms of units
        -> Maybe Int -- ^ Maximum node size (when Nothing, bounded
                     -- just by the max... constants)
        -> Gen Node.Node
396
397
genNode min_multiplier max_multiplier = do
  let (base_mem, base_dsk, base_cpu) =
Iustin Pop's avatar
Iustin Pop committed
398
399
400
401
402
        case min_multiplier of
          Just mm -> (mm * Types.unitMem,
                      mm * Types.unitDsk,
                      mm * Types.unitCpu)
          Nothing -> (0, 0, 0)
403
      (top_mem, top_dsk, top_cpu)  =
Iustin Pop's avatar
Iustin Pop committed
404
405
406
407
408
        case max_multiplier of
          Just mm -> (mm * Types.unitMem,
                      mm * Types.unitDsk,
                      mm * Types.unitCpu)
          Nothing -> (maxMem, maxDsk, maxCpu)
409
410
411
412
413
414
415
416
417
  name  <- getFQDN
  mem_t <- choose (base_mem, top_mem)
  mem_f <- choose (base_mem, mem_t)
  mem_n <- choose (0, mem_t - mem_f)
  dsk_t <- choose (base_dsk, top_dsk)
  dsk_f <- choose (base_dsk, dsk_t)
  cpu_t <- choose (base_cpu, top_cpu)
  offl  <- arbitrary
  let n = Node.create name (fromIntegral mem_t) mem_n mem_f
418
          (fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) offl 1 0
Iustin Pop's avatar
Iustin Pop committed
419
420
      n' = Node.setPolicy nullIPolicy n
  return $ Node.buildPeers n' Container.empty
421

422
423
424
425
426
427
428
429
430
-- | Helper function to generate a sane node.
genOnlineNode :: Gen Node.Node
genOnlineNode = do
  arbitrary `suchThat` (\n -> not (Node.offline n) &&
                              not (Node.failN1 n) &&
                              Node.availDisk n > 0 &&
                              Node.availMem n > 0 &&
                              Node.availCpu n > 0)

431
432
-- and a random node
instance Arbitrary Node.Node where
Iustin Pop's avatar
Iustin Pop committed
433
  arbitrary = genNode Nothing Nothing
434

Iustin Pop's avatar
Iustin Pop committed
435
436
-- replace disks
instance Arbitrary OpCodes.ReplaceDisksMode where
437
  arbitrary = elements [minBound..maxBound]
Iustin Pop's avatar
Iustin Pop committed
438
439
440

instance Arbitrary OpCodes.OpCode where
  arbitrary = do
441
    op_id <- elements OpCodes.allOpIDs
Iustin Pop's avatar
Iustin Pop committed
442
443
    case op_id of
      "OP_TEST_DELAY" ->
Iustin Pop's avatar
Iustin Pop committed
444
445
        OpCodes.OpTestDelay <$> arbitrary <*> arbitrary
                 <*> resize maxNodes (listOf getFQDN)
Iustin Pop's avatar
Iustin Pop committed
446
      "OP_INSTANCE_REPLACE_DISKS" ->
Iustin Pop's avatar
Iustin Pop committed
447
448
        OpCodes.OpInstanceReplaceDisks <$> getFQDN <*> getMaybe getFQDN <*>
          arbitrary <*> resize C.maxDisks arbitrary <*> getMaybe getName
Iustin Pop's avatar
Iustin Pop committed
449
      "OP_INSTANCE_FAILOVER" ->
Iustin Pop's avatar
Iustin Pop committed
450
451
        OpCodes.OpInstanceFailover <$> getFQDN <*> arbitrary <*>
          getMaybe getFQDN
Iustin Pop's avatar
Iustin Pop committed
452
      "OP_INSTANCE_MIGRATE" ->
Iustin Pop's avatar
Iustin Pop committed
453
454
        OpCodes.OpInstanceMigrate <$> getFQDN <*> arbitrary <*>
          arbitrary <*> arbitrary <*> getMaybe getFQDN
Iustin Pop's avatar
Iustin Pop committed
455
      _ -> fail "Wrong opcode"
Iustin Pop's avatar
Iustin Pop committed
456

457
458
459
460
461
462
instance Arbitrary Jobs.OpStatus where
  arbitrary = elements [minBound..maxBound]

instance Arbitrary Jobs.JobStatus where
  arbitrary = elements [minBound..maxBound]

463
464
newtype SmallRatio = SmallRatio Double deriving Show
instance Arbitrary SmallRatio where
Iustin Pop's avatar
Iustin Pop committed
465
466
467
  arbitrary = do
    v <- choose (0, 1)
    return $ SmallRatio v
468

469
470
471
472
473
474
instance Arbitrary Types.AllocPolicy where
  arbitrary = elements [minBound..maxBound]

instance Arbitrary Types.DiskTemplate where
  arbitrary = elements [minBound..maxBound]

475
instance Arbitrary Types.FailMode where
Iustin Pop's avatar
Iustin Pop committed
476
  arbitrary = elements [minBound..maxBound]
477

478
479
480
instance Arbitrary Types.EvacMode where
  arbitrary = elements [minBound..maxBound]

481
instance Arbitrary a => Arbitrary (Types.OpResult a) where
Iustin Pop's avatar
Iustin Pop committed
482
  arbitrary = arbitrary >>= \c ->
Iustin Pop's avatar
Iustin Pop committed
483
              if c
Iustin Pop's avatar
Iustin Pop committed
484
485
                then Types.OpGood <$> arbitrary
                else Types.OpFail <$> arbitrary
486

487
488
instance Arbitrary Types.ISpec where
  arbitrary = do
489
    mem_s <- arbitrary::Gen (NonNegative Int)
490
491
    dsk_c <- arbitrary::Gen (NonNegative Int)
    dsk_s <- arbitrary::Gen (NonNegative Int)
492
493
    cpu_c <- arbitrary::Gen (NonNegative Int)
    nic_c <- arbitrary::Gen (NonNegative Int)
494
    su    <- arbitrary::Gen (NonNegative Int)
495
496
    return Types.ISpec { Types.iSpecMemorySize = fromIntegral mem_s
                       , Types.iSpecCpuCount   = fromIntegral cpu_c
497
498
                       , Types.iSpecDiskSize   = fromIntegral dsk_s
                       , Types.iSpecDiskCount  = fromIntegral dsk_c
499
                       , Types.iSpecNicCount   = fromIntegral nic_c
500
                       , Types.iSpecSpindleUse = fromIntegral su
501
502
                       }

503
504
505
506
507
508
509
510
-- | Generates an ispec bigger than the given one.
genBiggerISpec :: Types.ISpec -> Gen Types.ISpec
genBiggerISpec imin = do
  mem_s <- choose (Types.iSpecMemorySize imin, maxBound)
  dsk_c <- choose (Types.iSpecDiskCount imin, maxBound)
  dsk_s <- choose (Types.iSpecDiskSize imin, maxBound)
  cpu_c <- choose (Types.iSpecCpuCount imin, maxBound)
  nic_c <- choose (Types.iSpecNicCount imin, maxBound)
511
  su    <- choose (Types.iSpecSpindleUse imin, maxBound)
512
513
514
515
516
  return Types.ISpec { Types.iSpecMemorySize = fromIntegral mem_s
                     , Types.iSpecCpuCount   = fromIntegral cpu_c
                     , Types.iSpecDiskSize   = fromIntegral dsk_s
                     , Types.iSpecDiskCount  = fromIntegral dsk_c
                     , Types.iSpecNicCount   = fromIntegral nic_c
517
                     , Types.iSpecSpindleUse = fromIntegral su
518
                     }
519
520
521
522

instance Arbitrary Types.IPolicy where
  arbitrary = do
    imin <- arbitrary
523
524
525
526
    istd <- genBiggerISpec imin
    imax <- genBiggerISpec istd
    num_tmpl <- choose (0, length allDiskTemplates)
    dts  <- genUniquesList num_tmpl
527
528
    vcpu_ratio <- choose (1.0, maxVcpuRatio)
    spindle_ratio <- choose (1.0, maxSpindleRatio)
529
530
531
532
    return Types.IPolicy { Types.iPolicyMinSpec = imin
                         , Types.iPolicyStdSpec = istd
                         , Types.iPolicyMaxSpec = imax
                         , Types.iPolicyDiskTemplates = dts
533
                         , Types.iPolicyVcpuRatio = vcpu_ratio
534
                         , Types.iPolicySpindleRatio = spindle_ratio
535
536
                         }

Agata Murawska's avatar
Agata Murawska committed
537
538
539
instance Arbitrary Objects.Hypervisor where
  arbitrary = elements [minBound..maxBound]

Iustin Pop's avatar
Iustin Pop committed
540
instance Arbitrary Objects.PartialNDParams where
541
  arbitrary = Objects.PartialNDParams <$> arbitrary <*> arbitrary
Iustin Pop's avatar
Iustin Pop committed
542

Agata Murawska's avatar
Agata Murawska committed
543
544
545
546
instance Arbitrary Objects.Node where
  arbitrary = Objects.Node <$> getFQDN <*> getFQDN <*> getFQDN
              <*> arbitrary <*> arbitrary <*> arbitrary <*> getFQDN
              <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
Iustin Pop's avatar
Iustin Pop committed
547
              <*> arbitrary <*> arbitrary <*> getFQDN <*> arbitrary
548
              <*> (Set.fromList <$> genTags)
Agata Murawska's avatar
Agata Murawska committed
549
550
551
552
553
554
555
556
557
558

instance Arbitrary Rpc.RpcCallAllInstancesInfo where
  arbitrary = Rpc.RpcCallAllInstancesInfo <$> arbitrary

instance Arbitrary Rpc.RpcCallInstanceList where
  arbitrary = Rpc.RpcCallInstanceList <$> arbitrary

instance Arbitrary Rpc.RpcCallNodeInfo where
  arbitrary = Rpc.RpcCallNodeInfo <$> arbitrary <*> arbitrary

Iustin Pop's avatar
Iustin Pop committed
559
-- | Custom 'Qlang.Filter' generator (top-level), which enforces a
560
-- (sane) limit on the depth of the generated filters.
Iustin Pop's avatar
Iustin Pop committed
561
genFilter :: Gen Qlang.Filter
562
563
564
565
566
genFilter = choose (0, 10) >>= genFilter'

-- | Custom generator for filters that correctly halves the state of
-- the generators at each recursive step, per the QuickCheck
-- documentation, in order not to run out of memory.
Iustin Pop's avatar
Iustin Pop committed
567
genFilter' :: Int -> Gen Qlang.Filter
568
genFilter' 0 =
Iustin Pop's avatar
Iustin Pop committed
569
570
571
572
573
574
575
576
577
  oneof [ return Qlang.EmptyFilter
        , Qlang.TrueFilter     <$> getName
        , Qlang.EQFilter       <$> getName <*> value
        , Qlang.LTFilter       <$> getName <*> value
        , Qlang.GTFilter       <$> getName <*> value
        , Qlang.LEFilter       <$> getName <*> value
        , Qlang.GEFilter       <$> getName <*> value
        , Qlang.RegexpFilter   <$> getName <*> getName
        , Qlang.ContainsFilter <$> getName <*> value
578
        ]
Iustin Pop's avatar
Iustin Pop committed
579
580
    where value = oneof [ Qlang.QuotedString <$> getName
                        , Qlang.NumericValue <$> arbitrary
581
582
                        ]
genFilter' n = do
Iustin Pop's avatar
Iustin Pop committed
583
584
585
  oneof [ Qlang.AndFilter  <$> vectorOf n'' (genFilter' n')
        , Qlang.OrFilter   <$> vectorOf n'' (genFilter' n')
        , Qlang.NotFilter  <$> genFilter' n'
586
587
588
589
590
        ]
  where n' = n `div` 2 -- sub-filter generator size
        n'' = max n' 2 -- but we don't want empty or 1-element lists,
                       -- so use this for and/or filter list length

Iustin Pop's avatar
Iustin Pop committed
591
592
593
instance Arbitrary Qlang.ItemType where
  arbitrary = elements [minBound..maxBound]

594
-- * Actual tests
Iustin Pop's avatar
Iustin Pop committed
595

596
597
-- ** Utils tests

598
-- | Helper to generate a small string that doesn't contain commas.
599
genNonCommaString :: Gen [Char]
600
601
602
603
genNonCommaString = do
  size <- choose (0, 20) -- arbitrary max size
  vectorOf size (arbitrary `suchThat` ((/=) ','))

604
605
-- | If the list is not just an empty element, and if the elements do
-- not contain commas, then join+split should be idempotent.
606
prop_Utils_commaJoinSplit :: Property
Iustin Pop's avatar
Iustin Pop committed
607
prop_Utils_commaJoinSplit =
608
609
  forAll (choose (0, 20)) $ \llen ->
  forAll (vectorOf llen genNonCommaString `suchThat` ((/=) [""])) $ \lst ->
Iustin Pop's avatar
Iustin Pop committed
610
  Utils.sepSplit ',' (Utils.commaJoin lst) ==? lst
Iustin Pop's avatar
Iustin Pop committed
611

612
-- | Split and join should always be idempotent.
613
prop_Utils_commaSplitJoin :: [Char] -> Property
Iustin Pop's avatar
Iustin Pop committed
614
prop_Utils_commaSplitJoin s =
Iustin Pop's avatar
Iustin Pop committed
615
  Utils.commaJoin (Utils.sepSplit ',' s) ==? s
616

617
-- | fromObjWithDefault, we test using the Maybe monad and an integer
618
-- value.
619
prop_Utils_fromObjWithDefault :: Integer -> String -> Bool
620
prop_Utils_fromObjWithDefault def_value random_key =
Iustin Pop's avatar
Iustin Pop committed
621
  -- a missing key will be returned with the default
622
  JSON.fromObjWithDefault [] random_key def_value == Just def_value &&
Iustin Pop's avatar
Iustin Pop committed
623
  -- a found key will be returned as is, not with default
624
  JSON.fromObjWithDefault [(random_key, J.showJSON def_value)]
Iustin Pop's avatar
Iustin Pop committed
625
       random_key (def_value+1) == Just def_value
626

627
-- | Test that functional if' behaves like the syntactic sugar if.
Iustin Pop's avatar
Iustin Pop committed
628
629
prop_Utils_if'if :: Bool -> Int -> Int -> Gen Prop
prop_Utils_if'if cnd a b =
Iustin Pop's avatar
Iustin Pop committed
630
  Utils.if' cnd a b ==? if cnd then a else b
631

Guido Trotter's avatar
Guido Trotter committed
632
-- | Test basic select functionality
Iustin Pop's avatar
Iustin Pop committed
633
634
635
636
prop_Utils_select :: Int      -- ^ Default result
                  -> [Int]    -- ^ List of False values
                  -> [Int]    -- ^ List of True values
                  -> Gen Prop -- ^ Test result
Guido Trotter's avatar
Guido Trotter committed
637
prop_Utils_select def lst1 lst2 =
Iustin Pop's avatar
Iustin Pop committed
638
  Utils.select def (flist ++ tlist) ==? expectedresult
Iustin Pop's avatar
Iustin Pop committed
639
640
641
    where expectedresult = Utils.if' (null lst2) def (head lst2)
          flist = zip (repeat False) lst1
          tlist = zip (repeat True)  lst2
Guido Trotter's avatar
Guido Trotter committed
642
643

-- | Test basic select functionality with undefined default
Iustin Pop's avatar
Iustin Pop committed
644
prop_Utils_select_undefd :: [Int]            -- ^ List of False values
Guido Trotter's avatar
Guido Trotter committed
645
                         -> NonEmptyList Int -- ^ List of True values
Iustin Pop's avatar
Iustin Pop committed
646
                         -> Gen Prop         -- ^ Test result
Guido Trotter's avatar
Guido Trotter committed
647
prop_Utils_select_undefd lst1 (NonEmpty lst2) =
Iustin Pop's avatar
Iustin Pop committed
648
  Utils.select undefined (flist ++ tlist) ==? head lst2
Iustin Pop's avatar
Iustin Pop committed
649
650
    where flist = zip (repeat False) lst1
          tlist = zip (repeat True)  lst2
Guido Trotter's avatar
Guido Trotter committed
651
652

-- | Test basic select functionality with undefined list values
Iustin Pop's avatar
Iustin Pop committed
653
prop_Utils_select_undefv :: [Int]            -- ^ List of False values
Guido Trotter's avatar
Guido Trotter committed
654
                         -> NonEmptyList Int -- ^ List of True values
Iustin Pop's avatar
Iustin Pop committed
655
                         -> Gen Prop         -- ^ Test result
Guido Trotter's avatar
Guido Trotter committed
656
prop_Utils_select_undefv lst1 (NonEmpty lst2) =
Iustin Pop's avatar
Iustin Pop committed
657
  Utils.select undefined cndlist ==? head lst2
Iustin Pop's avatar
Iustin Pop committed
658
659
660
    where flist = zip (repeat False) lst1
          tlist = zip (repeat True)  lst2
          cndlist = flist ++ tlist ++ [undefined]
661

662
prop_Utils_parseUnit :: NonNegative Int -> Property
Iustin Pop's avatar
Iustin Pop committed
663
prop_Utils_parseUnit (NonNegative n) =
Iustin Pop's avatar
Iustin Pop committed
664
665
666
667
668
669
670
671
672
673
  Utils.parseUnit (show n) ==? Types.Ok n .&&.
  Utils.parseUnit (show n ++ "m") ==? Types.Ok n .&&.
  Utils.parseUnit (show n ++ "M") ==? Types.Ok (truncate n_mb::Int) .&&.
  Utils.parseUnit (show n ++ "g") ==? Types.Ok (n*1024) .&&.
  Utils.parseUnit (show n ++ "G") ==? Types.Ok (truncate n_gb::Int) .&&.
  Utils.parseUnit (show n ++ "t") ==? Types.Ok (n*1048576) .&&.
  Utils.parseUnit (show n ++ "T") ==? Types.Ok (truncate n_tb::Int) .&&.
  printTestCase "Internal error/overflow?"
    (n_mb >=0 && n_gb >= 0 && n_tb >= 0) .&&.
  property (Types.isBad (Utils.parseUnit (show n ++ "x")::Types.Result Int))
674
  where n_mb = (fromIntegral n::Rational) * 1000 * 1000 / 1024 / 1024
Iustin Pop's avatar
Iustin Pop committed
675
676
        n_gb = n_mb * 1000
        n_tb = n_gb * 1000
Iustin Pop's avatar
Iustin Pop committed
677

678
-- | Test list for the Utils module.
679
testSuite "Utils"
Iustin Pop's avatar
Iustin Pop committed
680
681
682
683
684
685
686
687
688
            [ 'prop_Utils_commaJoinSplit
            , 'prop_Utils_commaSplitJoin
            , 'prop_Utils_fromObjWithDefault
            , 'prop_Utils_if'if
            , 'prop_Utils_select
            , 'prop_Utils_select_undefd
            , 'prop_Utils_select_undefv
            , 'prop_Utils_parseUnit
            ]
689

690
691
692
-- ** PeerMap tests

-- | Make sure add is idempotent.
693
694
prop_PeerMap_addIdempotent :: PeerMap.PeerMap
                           -> PeerMap.Key -> PeerMap.Elem -> Property
Iustin Pop's avatar
Iustin Pop committed
695
prop_PeerMap_addIdempotent pmap key em =
Iustin Pop's avatar
Iustin Pop committed
696
  fn puniq ==? fn (fn puniq)
697
    where fn = PeerMap.add key em
698
          puniq = PeerMap.accumArray const pmap
699

700
-- | Make sure remove is idempotent.
701
prop_PeerMap_removeIdempotent :: PeerMap.PeerMap -> PeerMap.Key -> Property
702
prop_PeerMap_removeIdempotent pmap key =
Iustin Pop's avatar
Iustin Pop committed
703
  fn puniq ==? fn (fn puniq)
704
    where fn = PeerMap.remove key
705
706
          puniq = PeerMap.accumArray const pmap

707
-- | Make sure a missing item returns 0.
708
prop_PeerMap_findMissing :: PeerMap.PeerMap -> PeerMap.Key -> Property
709
prop_PeerMap_findMissing pmap key =
Iustin Pop's avatar
Iustin Pop committed
710
  PeerMap.find key (PeerMap.remove key puniq) ==? 0
711
    where puniq = PeerMap.accumArray const pmap
712

713
-- | Make sure an added item is found.
714
715
prop_PeerMap_addFind :: PeerMap.PeerMap
                     -> PeerMap.Key -> PeerMap.Elem -> Property
Iustin Pop's avatar
Iustin Pop committed
716
prop_PeerMap_addFind pmap key em =
Iustin Pop's avatar
Iustin Pop committed
717
  PeerMap.find key (PeerMap.add key em puniq) ==? em
718
    where puniq = PeerMap.accumArray const pmap
719

720
-- | Manual check that maxElem returns the maximum indeed, or 0 for null.
721
prop_PeerMap_maxElem :: PeerMap.PeerMap -> Property
722
prop_PeerMap_maxElem pmap =
Iustin Pop's avatar
Iustin Pop committed
723
  PeerMap.maxElem puniq ==? if null puniq then 0
Iustin Pop's avatar
Iustin Pop committed
724
                              else (maximum . snd . unzip) puniq
725
    where puniq = PeerMap.accumArray const pmap
726

727
-- | List of tests for the PeerMap module.
728
testSuite "PeerMap"
Iustin Pop's avatar
Iustin Pop committed
729
730
731
732
733
734
            [ 'prop_PeerMap_addIdempotent
            , 'prop_PeerMap_removeIdempotent
            , 'prop_PeerMap_maxElem
            , 'prop_PeerMap_addFind
            , 'prop_PeerMap_findMissing
            ]
735

736
-- ** Container tests
737

Iustin Pop's avatar
Iustin Pop committed
738
739
-- we silence the following due to hlint bug fixed in later versions
{-# ANN prop_Container_addTwo "HLint: ignore Avoid lambda" #-}
740
prop_Container_addTwo :: [Container.Key] -> Int -> Int -> Bool
741
prop_Container_addTwo cdata i1 i2 =
Iustin Pop's avatar
Iustin Pop committed
742
743
  fn i1 i2 cont == fn i2 i1 cont &&
  fn i1 i2 cont == fn i1 i2 (fn i1 i2 cont)
744
    where cont = foldl (\c x -> Container.add x x c) Container.empty cdata
745
746
          fn x1 x2 = Container.addTwo x1 x1 x2 x2

747
prop_Container_nameOf :: Node.Node -> Property
748
749
750
prop_Container_nameOf node =
  let nl = makeSmallCluster node 1
      fnode = head (Container.elems nl)
Iustin Pop's avatar
Iustin Pop committed
751
  in Container.nameOf nl (Node.idx fnode) ==? Node.name fnode
752

753
-- | We test that in a cluster, given a random node, we can find it by
754
-- its name and alias, as long as all names and aliases are unique,
755
-- and that we fail to find a non-existing name.
Iustin Pop's avatar
Iustin Pop committed
756
prop_Container_findByName :: Property
757
758
prop_Container_findByName =
  forAll (genNode (Just 1) Nothing) $ \node ->
759
760
  forAll (choose (1, 20)) $ \ cnt ->
  forAll (choose (0, cnt - 1)) $ \ fidx ->
761
762
763
764
  forAll (genUniquesList (cnt * 2)) $ \ allnames ->
  forAll (arbitrary `suchThat` (`notElem` allnames)) $ \ othername ->
  let names = zip (take cnt allnames) (drop cnt allnames)
      nl = makeSmallCluster node cnt
765
766
767
768
769
      nodes = Container.elems nl
      nodes' = map (\((name, alias), nn) -> (Node.idx nn,
                                             nn { Node.name = name,
                                                  Node.alias = alias }))
               $ zip names nodes
Iustin Pop's avatar
Iustin Pop committed
770
      nl' = Container.fromList nodes'
771
      target = snd (nodes' !! fidx)
772
773
774
775
  in Container.findByName nl' (Node.name target) ==? Just target .&&.
     Container.findByName nl' (Node.alias target) ==? Just target .&&.
     printTestCase "Found non-existing name"
       (isNothing (Container.findByName nl' othername))
776

777
testSuite "Container"
Iustin Pop's avatar
Iustin Pop committed
778
779
780
781
            [ 'prop_Container_addTwo
            , 'prop_Container_nameOf
            , 'prop_Container_findByName
            ]
782

783
784
-- ** Instance tests

785
786
-- Simple instance tests, we only have setter/getters

787
prop_Instance_creat :: Instance.Instance -> Property
Iustin Pop's avatar
Iustin Pop committed
788
prop_Instance_creat inst =
Iustin Pop's avatar
Iustin Pop committed
789
  Instance.name inst ==? Instance.alias inst
Iustin Pop's avatar
Iustin Pop committed
790

791
prop_Instance_setIdx :: Instance.Instance -> Types.Idx -> Property
792
prop_Instance_setIdx inst idx =
Iustin Pop's avatar
Iustin Pop committed
793
  Instance.idx (Instance.setIdx inst idx) ==? idx
794

795
prop_Instance_setName :: Instance.Instance -> String -> Bool
796
prop_Instance_setName inst name =
Iustin Pop's avatar
Iustin Pop committed
797
798
  Instance.name newinst == name &&
  Instance.alias newinst == name
799
    where newinst = Instance.setName inst name
Iustin Pop's avatar
Iustin Pop committed
800

801
prop_Instance_setAlias :: Instance.Instance -> String -> Bool
Iustin Pop's avatar
Iustin Pop committed
802
prop_Instance_setAlias inst name =
Iustin Pop's avatar
Iustin Pop committed
803
804
  Instance.name newinst == Instance.name inst &&
  Instance.alias newinst == name
805
    where newinst = Instance.setAlias inst name
806

807
prop_Instance_setPri :: Instance.Instance -> Types.Ndx -> Property
808
prop_Instance_setPri inst pdx =
Iustin Pop's avatar
Iustin Pop committed
809
  Instance.pNode (Instance.setPri inst pdx) ==? pdx
810

811
prop_Instance_setSec :: Instance.Instance -> Types.Ndx -> Property
812
prop_Instance_setSec inst sdx =
Iustin Pop's avatar
Iustin Pop committed
813
  Instance.sNode (Instance.setSec inst sdx) ==? sdx
814

815
prop_Instance_setBoth :: Instance.Instance -> Types.Ndx -> Types.Ndx -> Bool
816
prop_Instance_setBoth inst pdx sdx =
Iustin Pop's avatar
Iustin Pop committed
817
  Instance.pNode si == pdx && Instance.sNode si == sdx
818
    where si = Instance.setBoth inst pdx sdx
819

820
prop_Instance_shrinkMG :: Instance.Instance -> Property
Iustin Pop's avatar
Iustin Pop committed
821
prop_Instance_shrinkMG inst =
Iustin Pop's avatar
Iustin Pop committed
822
823
824
825
  Instance.mem inst >= 2 * Types.unitMem ==>
    case Instance.shrinkByType inst Types.FailMem of
      Types.Ok inst' -> Instance.mem inst' == Instance.mem inst - Types.unitMem
      _ -> False
Iustin Pop's avatar
Iustin Pop committed
826

827
prop_Instance_shrinkMF :: Instance.Instance -> Property
Iustin Pop's avatar
Iustin Pop committed
828
prop_Instance_shrinkMF inst =
Iustin Pop's avatar
Iustin Pop committed
829
  forAll (choose (0, 2 * Types.unitMem - 1)) $ \mem ->
Iustin Pop's avatar
Iustin Pop committed
830
831
    let inst' = inst { Instance.mem = mem}
    in Types.isBad $ Instance.shrinkByType inst' Types.FailMem
Iustin Pop's avatar
Iustin Pop committed
832

833
prop_Instance_shrinkCG :: Instance.Instance -> Property
Iustin Pop's avatar
Iustin Pop committed
834
prop_Instance_shrinkCG inst =
Iustin Pop's avatar
Iustin Pop committed
835
836
837
838
839
  Instance.vcpus inst >= 2 * Types.unitCpu ==>
    case Instance.shrinkByType inst Types.FailCPU of
      Types.Ok inst' ->
        Instance.vcpus inst' == Instance.vcpus inst - Types.unitCpu
      _ -> False
Iustin Pop's avatar
Iustin Pop committed
840

841
prop_Instance_shrinkCF :: Instance.Instance -> Property
Iustin Pop's avatar
Iustin Pop committed
842
prop_Instance_shrinkCF inst =
Iustin Pop's avatar
Iustin Pop committed
843
  forAll (choose (0, 2 * Types.unitCpu - 1)) $ \vcpus ->
Iustin Pop's avatar
Iustin Pop committed
844
845
    let inst' = inst { Instance.vcpus = vcpus }
    in Types.isBad $ Instance.shrinkByType inst' Types.FailCPU
Iustin Pop's avatar
Iustin Pop committed
846

847
prop_Instance_shrinkDG :: Instance.Instance -> Property
Iustin Pop's avatar
Iustin Pop committed
848
prop_Instance_shrinkDG inst =
Iustin Pop's avatar
Iustin Pop committed
849
850
851
852
853
  Instance.dsk inst >= 2 * Types.unitDsk ==>
    case Instance.shrinkByType inst Types.FailDisk of
      Types.Ok inst' ->
        Instance.dsk inst' == Instance.dsk inst - Types.unitDsk
      _ -> False
Iustin Pop's avatar
Iustin Pop committed
854

855
prop_Instance_shrinkDF :: Instance.Instance -> Property
Iustin Pop's avatar
Iustin Pop committed
856
prop_Instance_shrinkDF inst =
Iustin Pop's avatar
Iustin Pop committed
857
  forAll (choose (0, 2 * Types.unitDsk - 1)) $ \dsk ->
Iustin Pop's avatar
Iustin Pop committed
858
859
    let inst' = inst { Instance.dsk = dsk }
    in Types.isBad $ Instance.shrinkByType inst' Types.FailDisk
Iustin Pop's avatar
Iustin Pop committed
860

861
prop_Instance_setMovable :: Instance.Instance -> Bool -> Property
Iustin Pop's avatar
Iustin Pop committed
862
prop_Instance_setMovable inst m =
Iustin Pop's avatar
Iustin Pop committed
863
  Instance.movable inst' ==? m
864
    where inst' = Instance.setMovable inst m
Iustin Pop's avatar
Iustin Pop committed
865

866
testSuite "Instance"
Iustin Pop's avatar
Iustin Pop committed
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
            [ 'prop_Instance_creat
            , 'prop_Instance_setIdx
            , 'prop_Instance_setName
            , 'prop_Instance_setAlias
            , 'prop_Instance_setPri
            , 'prop_Instance_setSec
            , 'prop_Instance_setBoth
            , 'prop_Instance_shrinkMG
            , 'prop_Instance_shrinkMF
            , 'prop_Instance_shrinkCG
            , 'prop_Instance_shrinkCF
            , 'prop_Instance_shrinkDG
            , 'prop_Instance_shrinkDF
            , 'prop_Instance_setMovable
            ]
Iustin Pop's avatar
Iustin Pop committed
882

883
884
885
-- ** Backends

-- *** Text backend tests
886

Iustin Pop's avatar
Iustin Pop committed
887
888
-- Instance text loader tests

889
890
891
892
prop_Text_Load_Instance :: String -> Int -> Int -> Int -> Types.InstanceStatus
                        -> NonEmptyList Char -> [Char]
                        -> NonNegative Int -> NonNegative Int -> Bool
                        -> Types.DiskTemplate -> Int -> Property
Iustin Pop's avatar
Iustin Pop committed
893
894
prop_Text_Load_Instance name mem dsk vcpus status
                        (NonEmpty pnode) snode
895
                        (NonNegative pdx) (NonNegative sdx) autobal dt su =
Iustin Pop's avatar
Iustin Pop committed
896
897
898
899
  pnode /= snode && pdx /= sdx ==>
  let vcpus_s = show vcpus
      dsk_s = show dsk
      mem_s = show mem