Revision 20bc5360 htest/Test/Ganeti/HTools/Node.hs

b/htest/Test/Ganeti/HTools/Node.hs
98 98

  
99 99
-- * Test cases
100 100

  
101
prop_Node_setAlias :: Node.Node -> String -> Bool
102
prop_Node_setAlias node name =
101
prop_setAlias :: Node.Node -> String -> Bool
102
prop_setAlias node name =
103 103
  Node.name newnode == Node.name node &&
104 104
  Node.alias newnode == name
105 105
    where newnode = Node.setAlias node name
106 106

  
107
prop_Node_setOffline :: Node.Node -> Bool -> Property
108
prop_Node_setOffline node status =
107
prop_setOffline :: Node.Node -> Bool -> Property
108
prop_setOffline node status =
109 109
  Node.offline newnode ==? status
110 110
    where newnode = Node.setOffline node status
111 111

  
112
prop_Node_setXmem :: Node.Node -> Int -> Property
113
prop_Node_setXmem node xm =
112
prop_setXmem :: Node.Node -> Int -> Property
113
prop_setXmem node xm =
114 114
  Node.xMem newnode ==? xm
115 115
    where newnode = Node.setXmem node xm
116 116

  
117
prop_Node_setMcpu :: Node.Node -> Double -> Property
118
prop_Node_setMcpu node mc =
117
prop_setMcpu :: Node.Node -> Double -> Property
118
prop_setMcpu node mc =
119 119
  Types.iPolicyVcpuRatio (Node.iPolicy newnode) ==? mc
120 120
    where newnode = Node.setMcpu node mc
121 121

  
122 122
-- | Check that an instance add with too high memory or disk will be
123 123
-- rejected.
124
prop_Node_addPriFM :: Node.Node -> Instance.Instance -> Property
125
prop_Node_addPriFM node inst =
124
prop_addPriFM :: Node.Node -> Instance.Instance -> Property
125
prop_addPriFM node inst =
126 126
  Instance.mem inst >= Node.fMem node && not (Node.failN1 node) &&
127 127
  not (Instance.isOffline inst) ==>
128 128
  case Node.addPri node inst'' of
......
133 133

  
134 134
-- | Check that adding a primary instance with too much disk fails
135 135
-- with type FailDisk.
136
prop_Node_addPriFD :: Node.Node -> Instance.Instance -> Property
137
prop_Node_addPriFD node inst =
136
prop_addPriFD :: Node.Node -> Instance.Instance -> Property
137
prop_addPriFD node inst =
138 138
  forAll (elements Instance.localStorageTemplates) $ \dt ->
139 139
  Instance.dsk inst >= Node.fDsk node && not (Node.failN1 node) ==>
140 140
  let inst' = setInstanceSmallerThanNode node inst
......
146 146

  
147 147
-- | Check that adding a primary instance with too many VCPUs fails
148 148
-- with type FailCPU.
149
prop_Node_addPriFC :: Property
150
prop_Node_addPriFC =
149
prop_addPriFC :: Property
150
prop_addPriFC =
151 151
  forAll (choose (1, maxCpu)) $ \extra ->
152 152
  forAll genOnlineNode $ \node ->
153 153
  forAll (arbitrary `suchThat` Instance.notOffline) $ \inst ->
......
159 159

  
160 160
-- | Check that an instance add with too high memory or disk will be
161 161
-- rejected.
162
prop_Node_addSec :: Node.Node -> Instance.Instance -> Int -> Property
163
prop_Node_addSec node inst pdx =
162
prop_addSec :: Node.Node -> Instance.Instance -> Int -> Property
163
prop_addSec node inst pdx =
164 164
  ((Instance.mem inst >= (Node.fMem node - Node.rMem node) &&
165 165
    not (Instance.isOffline inst)) ||
166 166
   Instance.dsk inst >= Node.fDsk node) &&
......
169 169

  
170 170
-- | Check that an offline instance with reasonable disk size but
171 171
-- extra mem/cpu can always be added.
172
prop_Node_addOfflinePri :: NonNegative Int -> NonNegative Int -> Property
173
prop_Node_addOfflinePri (NonNegative extra_mem) (NonNegative extra_cpu) =
172
prop_addOfflinePri :: NonNegative Int -> NonNegative Int -> Property
173
prop_addOfflinePri (NonNegative extra_mem) (NonNegative extra_cpu) =
174 174
  forAll genOnlineNode $ \node ->
175 175
  forAll (genInstanceSmallerThanNode node) $ \inst ->
176 176
  let inst' = inst { Instance.runSt = Types.AdminOffline
......
182 182

  
183 183
-- | Check that an offline instance with reasonable disk size but
184 184
-- extra mem/cpu can always be added.
185
prop_Node_addOfflineSec :: NonNegative Int -> NonNegative Int
186
                        -> Types.Ndx -> Property
187
prop_Node_addOfflineSec (NonNegative extra_mem) (NonNegative extra_cpu) pdx =
185
prop_addOfflineSec :: NonNegative Int -> NonNegative Int
186
                   -> Types.Ndx -> Property
187
prop_addOfflineSec (NonNegative extra_mem) (NonNegative extra_cpu) pdx =
188 188
  forAll genOnlineNode $ \node ->
189 189
  forAll (genInstanceSmallerThanNode node) $ \inst ->
190 190
  let inst' = inst { Instance.runSt = Types.AdminOffline
......
196 196
       v -> failTest $ "Expected OpGood/OpGood, but got: " ++ show v
197 197

  
198 198
-- | Checks for memory reservation changes.
199
prop_Node_rMem :: Instance.Instance -> Property
200
prop_Node_rMem inst =
199
prop_rMem :: Instance.Instance -> Property
200
prop_rMem inst =
201 201
  not (Instance.isOffline inst) ==>
202 202
  forAll (genOnlineNode `suchThat` ((> Types.unitMem) . Node.fMem)) $ \node ->
203 203
  -- ab = auto_balance, nb = non-auto_balance
......
230 230
       x -> failTest $ "Failed to add/remove instances: " ++ show x
231 231

  
232 232
-- | Check mdsk setting.
233
prop_Node_setMdsk :: Node.Node -> SmallRatio -> Bool
234
prop_Node_setMdsk node mx =
233
prop_setMdsk :: Node.Node -> SmallRatio -> Bool
234
prop_setMdsk node mx =
235 235
  Node.loDsk node' >= 0 &&
236 236
  fromIntegral (Node.loDsk node') <= Node.tDsk node &&
237 237
  Node.availDisk node' >= 0 &&
......
242 242
          SmallRatio mx' = mx
243 243

  
244 244
-- Check tag maps
245
prop_Node_tagMaps_idempotent :: Property
246
prop_Node_tagMaps_idempotent =
245
prop_tagMaps_idempotent :: Property
246
prop_tagMaps_idempotent =
247 247
  forAll genTags $ \tags ->
248 248
  Node.delTags (Node.addTags m tags) tags ==? m
249 249
    where m = Map.empty
250 250

  
251
prop_Node_tagMaps_reject :: Property
252
prop_Node_tagMaps_reject =
251
prop_tagMaps_reject :: Property
252
prop_tagMaps_reject =
253 253
  forAll (genTags `suchThat` (not . null)) $ \tags ->
254 254
  let m = Node.addTags Map.empty tags
255 255
  in all (\t -> Node.rejectAddTags m [t]) tags
256 256

  
257
prop_Node_showField :: Node.Node -> Property
258
prop_Node_showField node =
257
prop_showField :: Node.Node -> Property
258
prop_showField node =
259 259
  forAll (elements Node.defaultFields) $ \ field ->
260 260
  fst (Node.showHeader field) /= Types.unknownField &&
261 261
  Node.showField node field /= Types.unknownField
262 262

  
263
prop_Node_computeGroups :: [Node.Node] -> Bool
264
prop_Node_computeGroups nodes =
263
prop_computeGroups :: [Node.Node] -> Bool
264
prop_computeGroups nodes =
265 265
  let ng = Node.computeGroups nodes
266 266
      onlyuuid = map fst ng
267 267
  in length nodes == sum (map (length . snd) ng) &&
......
270 270
     (null nodes || not (null ng))
271 271

  
272 272
-- Check idempotence of add/remove operations
273
prop_Node_addPri_idempotent :: Property
274
prop_Node_addPri_idempotent =
273
prop_addPri_idempotent :: Property
274
prop_addPri_idempotent =
275 275
  forAll genOnlineNode $ \node ->
276 276
  forAll (genInstanceSmallerThanNode node) $ \inst ->
277 277
  case Node.addPri node inst of
278 278
    Types.OpGood node' -> Node.removePri node' inst ==? node
279 279
    _ -> failTest "Can't add instance"
280 280

  
281
prop_Node_addSec_idempotent :: Property
282
prop_Node_addSec_idempotent =
281
prop_addSec_idempotent :: Property
282
prop_addSec_idempotent =
283 283
  forAll genOnlineNode $ \node ->
284 284
  forAll (genInstanceSmallerThanNode node) $ \inst ->
285 285
  let pdx = Node.idx node + 1
......
290 290
       _ -> failTest "Can't add instance"
291 291

  
292 292
testSuite "Node"
293
            [ 'prop_Node_setAlias
294
            , 'prop_Node_setOffline
295
            , 'prop_Node_setMcpu
296
            , 'prop_Node_setXmem
297
            , 'prop_Node_addPriFM
298
            , 'prop_Node_addPriFD
299
            , 'prop_Node_addPriFC
300
            , 'prop_Node_addSec
301
            , 'prop_Node_addOfflinePri
302
            , 'prop_Node_addOfflineSec
303
            , 'prop_Node_rMem
304
            , 'prop_Node_setMdsk
305
            , 'prop_Node_tagMaps_idempotent
306
            , 'prop_Node_tagMaps_reject
307
            , 'prop_Node_showField
308
            , 'prop_Node_computeGroups
309
            , 'prop_Node_addPri_idempotent
310
            , 'prop_Node_addSec_idempotent
293
            [ 'prop_setAlias
294
            , 'prop_setOffline
295
            , 'prop_setMcpu
296
            , 'prop_setXmem
297
            , 'prop_addPriFM
298
            , 'prop_addPriFD
299
            , 'prop_addPriFC
300
            , 'prop_addSec
301
            , 'prop_addOfflinePri
302
            , 'prop_addOfflineSec
303
            , 'prop_rMem
304
            , 'prop_setMdsk
305
            , 'prop_tagMaps_idempotent
306
            , 'prop_tagMaps_reject
307
            , 'prop_showField
308
            , 'prop_computeGroups
309
            , 'prop_addPri_idempotent
310
            , 'prop_addSec_idempotent
311 311
            ]

Also available in: Unified diff