Revision fcfc0c2d test/hs/Test/Ganeti/HTools/Instance.hs

b/test/hs/Test/Ganeti/HTools/Instance.hs
7 7

  
8 8
{-
9 9

  
10
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
10
Copyright (C) 2009, 2010, 2011, 2012, 2013 Google Inc.
11 11

  
12 12
This program is free software; you can redistribute it and/or modify
13 13
it under the terms of the GNU General Public License as published by
......
30 30
  ( testHTools_Instance
31 31
  , genInstanceSmallerThanNode
32 32
  , genInstanceMaybeBiggerThanNode
33
  , genInstanceSmallerThan
34 33
  , genInstanceOnNodeList
35 34
  , genInstanceList
36 35
  , Instance.Instance(..)
37 36
  ) where
38 37

  
38
import Control.Monad (liftM)
39 39
import Test.QuickCheck hiding (Result)
40 40

  
41 41
import Test.Ganeti.TestHelper
......
52 52
-- * Arbitrary instances
53 53

  
54 54
-- | Generates a random instance with maximum disk/mem/cpu values.
55
genInstanceSmallerThan :: Int -> Int -> Int -> Gen Instance.Instance
56
genInstanceSmallerThan lim_mem lim_dsk lim_cpu = do
55
genInstanceSmallerThan :: Int -> Int -> Int -> Maybe Int ->
56
                          Gen Instance.Instance
57
genInstanceSmallerThan lim_mem lim_dsk lim_cpu lim_spin = do
57 58
  name <- genFQDN
58 59
  mem <- choose (0, lim_mem)
59 60
  dsk <- choose (0, lim_dsk)
......
62 63
  sn <- arbitrary
63 64
  vcpus <- choose (0, lim_cpu)
64 65
  dt <- arbitrary
65
  spindles <- arbitrary
66
  spindles <- case lim_spin of
67
    Nothing -> genMaybe $ choose (0, maxSpindles)
68
    Just ls -> liftM Just $ choose (0, ls)
66 69
  let disk = Instance.Disk dsk spindles
67 70
  return $ Instance.create
68 71
    name mem dsk [disk] vcpus run_st [] True pn sn dt 1 []
......
73 76
  genInstanceSmallerThan (Node.availMem node `div` 2)
74 77
                         (Node.availDisk node `div` 2)
75 78
                         (Node.availCpu node `div` 2)
79
                         (if Node.exclStorage node
80
                          then Just $ Node.fSpindles node `div` 2
81
                          else Nothing)
76 82

  
77 83
-- | Generates an instance possibly bigger than a node.
78 84
genInstanceMaybeBiggerThanNode :: Node.Node -> Gen Instance.Instance
......
80 86
  genInstanceSmallerThan (Node.availMem  node + Types.unitMem * 2)
81 87
                         (Node.availDisk node + Types.unitDsk * 3)
82 88
                         (Node.availCpu  node + Types.unitCpu * 4)
89
                         (if Node.exclStorage node
90
                          then Just $ Node.fSpindles node +
91
                               Types.unitSpindle * 5
92
                          else Nothing)
83 93

  
84 94
-- | Generates an instance with nodes on a node list.
85 95
-- The following rules are respected:
......
106 116

  
107 117
-- let's generate a random instance
108 118
instance Arbitrary Instance.Instance where
109
  arbitrary = genInstanceSmallerThan maxMem maxDsk maxCpu
119
  arbitrary = genInstanceSmallerThan maxMem maxDsk maxCpu Nothing
110 120

  
111 121
-- * Test cases
112 122

  

Also available in: Unified diff