import qualified Ganeti.HTools.Loader as Loader
import qualified Ganeti.HTools.Luxi
import qualified Ganeti.HTools.Node as Node
+import qualified Ganeti.HTools.Group as Group
import qualified Ganeti.HTools.PeerMap as PeerMap
import qualified Ganeti.HTools.Rapi
import qualified Ganeti.HTools.Simu
maxCpu :: Int
maxCpu = 1024
+defGroup :: Group.Group
+defGroup = flip Group.setIdx 0 $
+ Group.create "default" Utils.defaultGroupID
+ Types.AllocPreferred
+
+defGroupList :: Group.List
+defGroupList = Container.fromAssocList [(Group.idx defGroup, defGroup)]
+
+defGroupAssoc :: Data.Map.Map String Types.Gdx
+defGroupAssoc = Data.Map.singleton (Group.uuid defGroup) (Group.idx defGroup)
+
-- * Helper functions
-- | Simple checker for whether OpResult is fail or pass
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
offl <- arbitrary
let n = Node.create name (fromIntegral mem_t) mem_n mem_f
(fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) offl
- Utils.defaultGroupID
+ 0
n' = Node.buildPeers n Container.empty
return n'
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 ==>
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 ==>
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
then "Y"
else "N"
any_broken = any (< 0) [tm, nm, fm, td, fd, tc]
- in case Text.loadNode [name, tm_s, nm_s, fm_s, td_s, fd_s, tc_s, fo_s] of
+ gid = Group.uuid defGroup
+ in case Text.loadNode defGroupAssoc
+ [name, tm_s, nm_s, fm_s, td_s, fd_s, tc_s, fo_s, gid] of
Nothing -> False
Just (name', node) ->
if fo || any_broken
Node.tCpu node == fromIntegral tc
prop_Text_Load_NodeFail fields =
- length fields /= 8 ==> isNothing $ Text.loadNode fields
+ length fields /= 8 ==> isNothing $ Text.loadNode Data.Map.empty fields
prop_Text_NodeLSIdempotent node =
- (Text.loadNode .
- Utils.sepSplit '|' . Text.serializeNode) n ==
+ (Text.loadNode defGroupAssoc.
+ Utils.sepSplit '|' . Text.serializeNode defGroupList) n ==
Just (Node.name n, n)
-- override failN1 to what loadNode returns by default
where n = node { Node.failN1 = True, Node.offline = False }
inst' = setInstanceSmallerThanNode node inst
in case Cluster.tryAlloc nl il inst' rqnodes of
Types.Bad _ -> False
- Types.Ok (_, _, sols3) ->
- case sols3 of
+ Types.Ok as ->
+ case Cluster.asSolutions as of
[] -> False
- (_, (xnl, xi, _)):[] ->
- let cv = Cluster.compCV xnl
- il' = Container.add (Instance.idx xi) xi il
+ (xnl, xi, _, cv):[] ->
+ let il' = Container.add (Instance.idx xi) xi il
tbl = Cluster.Table xnl il' cv []
in not (canBalance tbl True False)
_ -> False
inst' = setInstanceSmallerThanNode node inst
in case Cluster.tryAlloc nl il inst' rqnodes of
Types.Bad _ -> False
- Types.Ok (_, _, sols3) ->
- case sols3 of
+ Types.Ok as ->
+ case Cluster.asSolutions as of
[] -> False
- (_, (xnl, xi, _)):[] ->
+ (xnl, xi, _, _):[] ->
let sdx = Instance.sNode xi
il' = Container.add (Instance.idx xi) xi il
in case Cluster.tryEvac xnl il' [sdx] of
prop_ClusterCheckConsistency node inst =
let nl = makeSmallCluster node 3
[node1, node2, node3] = Container.elems nl
- node3' = node3 { Node.group = "other-uuid" }
+ node3' = node3 { Node.group = 1 }
nl' = Container.add (Node.idx node3') node3' nl
inst1 = Instance.setBoth inst (Node.idx node1) (Node.idx node2)
inst2 = Instance.setBoth inst (Node.idx node1) Node.noSecondary
-- is zero
prop_Loader_mergeData ns =
let na = Container.fromAssocList $ map (\n -> (Node.idx n, n)) ns
- in case Loader.mergeData [] [] [] (na, Container.empty, []) of
+ in case Loader.mergeData [] [] []
+ (Container.empty, na, Container.empty, []) of
Types.Bad _ -> False
- Types.Ok (nl, il, _) ->
+ Types.Ok (_, nl, il, _) ->
let nodes = Container.elems nl
instances = Container.elems il
in (sum . map (length . Node.pList)) nodes == 0 &&