Commit 06fb841e authored by Iustin Pop's avatar Iustin Pop
Browse files

Add two utility functions for the Result type



Actually, this just moves the functions from the QC module to Types, and
removes a duplicate entry from Cluster.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent 99b63608
......@@ -854,9 +854,6 @@ instanceGroup nl i =
findSplitInstances :: Node.List -> Instance.List -> [Instance.Instance]
findSplitInstances nl il =
filter (not . isOk . instanceGroup nl) (Container.elems il)
where isOk x = case x of
Bad _ -> False
_ -> True
-- | Splits a cluster into the component node groups
splitCluster :: Node.List -> Instance.List ->
......
......@@ -85,14 +85,6 @@ isFailure :: Types.OpResult a -> Bool
isFailure (Types.OpFail _) = True
isFailure _ = False
-- | Simple checker for whether Result is fail or pass
isOk :: Types.Result a -> Bool
isOk (Types.Ok _ ) = True
isOk _ = False
isBad :: Types.Result a -> Bool
isBad = not . isOk
-- | Update an instance to be smaller than a node
setInstanceSmallerThanNode node inst =
inst { Instance.mem = Node.availMem node `div` 2
......@@ -388,7 +380,7 @@ prop_Instance_shrinkMG inst =
prop_Instance_shrinkMF inst =
Instance.mem inst < 2 * Types.unitMem ==>
isBad $ Instance.shrinkByType inst Types.FailMem
Types.isBad $ Instance.shrinkByType inst Types.FailMem
prop_Instance_shrinkCG inst =
Instance.vcpus inst >= 2 * Types.unitCpu ==>
......@@ -399,7 +391,7 @@ prop_Instance_shrinkCG inst =
prop_Instance_shrinkCF inst =
Instance.vcpus inst < 2 * Types.unitCpu ==>
isBad $ Instance.shrinkByType inst Types.FailCPU
Types.isBad $ Instance.shrinkByType inst Types.FailCPU
prop_Instance_shrinkDG inst =
Instance.dsk inst >= 2 * Types.unitDsk ==>
......@@ -410,7 +402,7 @@ prop_Instance_shrinkDG inst =
prop_Instance_shrinkDF inst =
Instance.dsk inst < 2 * Types.unitDsk ==>
isBad $ Instance.shrinkByType inst Types.FailDisk
Types.isBad $ Instance.shrinkByType inst Types.FailDisk
prop_Instance_setMovable inst m =
Instance.movable inst' == m
......
......@@ -47,6 +47,8 @@ module Ganeti.HTools.Types
, MoveJob
, JobSet
, Result(..)
, isOk
, isBad
, Element(..)
, FailMode(..)
, FailStats
......@@ -178,6 +180,15 @@ instance Monad Result where
return = Ok
fail = Bad
-- | Simple checker for whether Result is OK
isOk :: Result a -> Bool
isOk (Ok _) = True
isOk _ = False
-- | Simple checker for whether Result is a failure
isBad :: Result a -> Bool
isBad = not . isOk
-- | Reason for an operation's falure
data FailMode = FailMem -- ^ Failed due to not enough RAM
| FailDisk -- ^ Failed due to not enough disk
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment