Revision 3603605a htools/Ganeti/HTools/QC.hs

b/htools/Ganeti/HTools/QC.hs
133 133
      (_, nlst) = Loader.assignIndices namelst
134 134
  in nlst
135 135

  
136
-- | Make a small cluster, both nodes and instances.
137
makeSmallEmptyCluster :: Node.Node -> Int -> Instance.Instance
138
                      -> (Node.List, Instance.List, Instance.Instance)
139
makeSmallEmptyCluster node count inst =
140
  (makeSmallCluster node count, Container.empty,
141
   setInstanceSmallerThanNode node inst)
142

  
136 143
-- | Checks if a node is "big" enough.
137 144
isNodeBig :: Node.Node -> Int -> Bool
138 145
isNodeBig node size = Node.availDisk node > size * Types.unitDsk
......
246 253
                      , "OP_INSTANCE_FAILOVER"
247 254
                      , "OP_INSTANCE_MIGRATE"
248 255
                      ]
249
    (case op_id of
250
       "OP_TEST_DELAY" ->
251
         liftM3 OpCodes.OpTestDelay arbitrary arbitrary arbitrary
252
       "OP_INSTANCE_REPLACE_DISKS" ->
253
         liftM5 OpCodes.OpInstanceReplaceDisks arbitrary arbitrary
254
         arbitrary arbitrary arbitrary
255
       "OP_INSTANCE_FAILOVER" ->
256
         liftM3 OpCodes.OpInstanceFailover arbitrary arbitrary
257
                arbitrary
258
       "OP_INSTANCE_MIGRATE" ->
259
         liftM5 OpCodes.OpInstanceMigrate arbitrary arbitrary
260
                arbitrary arbitrary arbitrary
261
       _ -> fail "Wrong opcode")
256
    case op_id of
257
      "OP_TEST_DELAY" ->
258
        liftM3 OpCodes.OpTestDelay arbitrary arbitrary arbitrary
259
      "OP_INSTANCE_REPLACE_DISKS" ->
260
        liftM5 OpCodes.OpInstanceReplaceDisks arbitrary arbitrary
261
          arbitrary arbitrary arbitrary
262
      "OP_INSTANCE_FAILOVER" ->
263
        liftM3 OpCodes.OpInstanceFailover arbitrary arbitrary
264
          arbitrary
265
      "OP_INSTANCE_MIGRATE" ->
266
        liftM5 OpCodes.OpInstanceMigrate arbitrary arbitrary
267
          arbitrary arbitrary arbitrary
268
      _ -> fail "Wrong opcode"
262 269

  
263 270
instance Arbitrary Jobs.OpStatus where
264 271
  arbitrary = elements [minBound..maxBound]
......
283 290

  
284 291
instance Arbitrary a => Arbitrary (Types.OpResult a) where
285 292
  arbitrary = arbitrary >>= \c ->
286
              case c of
287
                False -> liftM Types.OpFail arbitrary
288
                True -> liftM Types.OpGood arbitrary
293
              if c
294
                then liftM Types.OpGood arbitrary
295
                else liftM Types.OpFail arbitrary
289 296

  
290 297
-- * Actual tests
291 298

  
......
295 302
-- not contain commas, then join+split should be idempotent.
296 303
prop_Utils_commaJoinSplit =
297 304
  forAll (arbitrary `suchThat`
298
          (\l -> l /= [""] && all (not . elem ',') l )) $ \lst ->
305
          (\l -> l /= [""] && all (notElem ',') l )) $ \lst ->
299 306
  Utils.sepSplit ',' (Utils.commaJoin lst) ==? lst
300 307

  
301 308
-- | Split and join should always be idempotent.
......
323 330
                  -> [Int]    -- ^ List of True values
324 331
                  -> Gen Prop -- ^ Test result
325 332
prop_Utils_select def lst1 lst2 =
326
  Utils.select def cndlist ==? expectedresult
333
  Utils.select def (flist ++ tlist) ==? expectedresult
327 334
  where expectedresult = Utils.if' (null lst2) def (head lst2)
328 335
        flist = map (\e -> (False, e)) lst1
329 336
        tlist = map (\e -> (True, e)) lst2
330
        cndlist = flist ++ tlist
331 337

  
332 338
-- | Test basic select functionality with undefined default
333 339
prop_Utils_select_undefd :: [Int]            -- ^ List of False values
334 340
                         -> NonEmptyList Int -- ^ List of True values
335 341
                         -> Gen Prop         -- ^ Test result
336 342
prop_Utils_select_undefd lst1 (NonEmpty lst2) =
337
  Utils.select undefined cndlist ==? head lst2
343
  Utils.select undefined (flist ++ tlist) ==? head lst2
338 344
  where flist = map (\e -> (False, e)) lst1
339 345
        tlist = map (\e -> (True, e)) lst2
340
        cndlist = flist ++ tlist
341 346

  
342 347
-- | Test basic select functionality with undefined list values
343 348
prop_Utils_select_undefv :: [Int]            -- ^ List of False values
......
422 427

  
423 428
-- ** Container tests
424 429

  
430
-- we silence the following due to hlint bug fixed in later versions
431
{-# ANN prop_Container_addTwo "HLint: ignore Avoid lambda" #-}
425 432
prop_Container_addTwo cdata i1 i2 =
426 433
  fn i1 i2 cont == fn i2 i1 cont &&
427 434
  fn i1 i2 cont == fn i1 i2 (fn i1 i2 cont)
......
444 451
  forAll (vector cnt) $ \ names ->
445 452
  (length . nub) (map fst names ++ map snd names) ==
446 453
  length names * 2 &&
447
  not (othername `elem` (map fst names ++ map snd names)) ==>
454
  othername `notElem` (map fst names ++ map snd names) ==>
448 455
  let nl = makeSmallCluster node cnt
449 456
      nodes = Container.elems nl
450 457
      nodes' = map (\((name, alias), nn) -> (Node.idx nn,
......
455 462
      target = snd (nodes' !! fidx)
456 463
  in Container.findByName nl' (Node.name target) == Just target &&
457 464
     Container.findByName nl' (Node.alias target) == Just target &&
458
     Container.findByName nl' othername == Nothing
465
     isNothing (Container.findByName nl' othername)
459 466

  
460 467
testSuite "Container"
461 468
            [ 'prop_Container_addTwo
......
765 772
           -- this is not related to rMem, but as good a place to
766 773
           -- test as any
767 774
           inst_idx `elem` Node.sList a_ab &&
768
           not (inst_idx `elem` Node.sList d_ab)
775
           inst_idx `notElem` Node.sList d_ab
769 776
       x -> printTestCase ("Failed to add/remove instances: " ++ show x) False
770 777

  
771 778
-- | Check mdsk setting.
......
858 865
        && Node.availDisk node > 0
859 866
        && Node.availMem node > 0
860 867
        ==>
861
  let nl = makeSmallCluster node count
862
      il = Container.empty
863
      inst' = setInstanceSmallerThanNode node inst
868
  let (nl, il, inst') = makeSmallEmptyCluster node count inst
864 869
  in case Cluster.genAllocNodes defGroupList nl 2 True >>=
865 870
     Cluster.tryAlloc nl il inst' of
866 871
       Types.Bad _ -> False
......
900 905
        && not (Node.failN1 node)
901 906
        && isNodeBig node 4
902 907
        ==>
903
  let nl = makeSmallCluster node count
904
      il = Container.empty
905
      inst' = setInstanceSmallerThanNode node inst
908
  let (nl, il, inst') = makeSmallEmptyCluster node count inst
906 909
  in case Cluster.genAllocNodes defGroupList nl 2 True >>=
907 910
     Cluster.tryAlloc nl il inst' of
908 911
       Types.Bad _ -> False

Also available in: Unified diff