module Test.Ganeti.TestHTools
( nullIPolicy
, defGroup
, defGroupList
, defGroupAssoc
, createInstance
, makeSmallCluster
, setInstanceSmallerThanNode
) where
import qualified Data.Map as Map
import Test.Ganeti.TestCommon
import qualified Ganeti.Constants as C
import qualified Ganeti.HTools.Container as Container
import qualified Ganeti.HTools.Group as Group
import qualified Ganeti.HTools.Instance as Instance
import qualified Ganeti.HTools.Loader as Loader
import qualified Ganeti.HTools.Node as Node
import qualified Ganeti.HTools.Types as Types
nullIPolicy :: Types.IPolicy
nullIPolicy = Types.IPolicy
{ Types.iPolicyMinSpec = Types.ISpec { Types.iSpecMemorySize = 0
, Types.iSpecCpuCount = 0
, Types.iSpecDiskSize = 0
, Types.iSpecDiskCount = 0
, Types.iSpecNicCount = 0
, Types.iSpecSpindleUse = 0
}
, Types.iPolicyMaxSpec = Types.ISpec { Types.iSpecMemorySize = maxBound
, Types.iSpecCpuCount = maxBound
, Types.iSpecDiskSize = maxBound
, Types.iSpecDiskCount = C.maxDisks
, Types.iSpecNicCount = C.maxNics
, Types.iSpecSpindleUse = maxBound
}
, Types.iPolicyStdSpec = Types.ISpec { Types.iSpecMemorySize = Types.unitMem
, Types.iSpecCpuCount = Types.unitCpu
, Types.iSpecDiskSize = Types.unitDsk
, Types.iSpecDiskCount = 1
, Types.iSpecNicCount = 1
, Types.iSpecSpindleUse = 1
}
, Types.iPolicyDiskTemplates = [minBound..maxBound]
, Types.iPolicyVcpuRatio = maxVcpuRatio
, Types.iPolicySpindleRatio = maxSpindleRatio
}
defGroup :: Group.Group
defGroup = flip Group.setIdx 0 $
Group.create "default" Types.defaultGroupID Types.AllocPreferred
nullIPolicy []
defGroupList :: Group.List
defGroupList = Container.fromList [(Group.idx defGroup, defGroup)]
defGroupAssoc :: Map.Map String Types.Gdx
defGroupAssoc = Map.singleton (Group.uuid defGroup) (Group.idx defGroup)
createInstance :: Int -> Int -> Int -> Instance.Instance
createInstance mem dsk vcpus =
Instance.create "inst-unnamed" mem dsk [dsk] vcpus Types.Running [] True (1)
(1) Types.DTDrbd8 1
makeSmallCluster :: Node.Node -> Int -> Node.List
makeSmallCluster node count =
let origname = Node.name node
origalias = Node.alias node
nodes = map (\idx -> node { Node.name = origname ++ "-" ++ show idx
, Node.alias = origalias ++ "-" ++ show idx })
[1..count]
fn = flip Node.buildPeers Container.empty
namelst = map (\n -> (Node.name n, fn n)) nodes
(_, nlst) = Loader.assignIndices namelst
in nlst
setInstanceSmallerThanNode :: Node.Node
-> Instance.Instance -> Instance.Instance
setInstanceSmallerThanNode node inst =
inst { Instance.mem = Node.availMem node `div` 2
, Instance.dsk = Node.availDisk node `div` 2
, Instance.vcpus = Node.availCpu node `div` 2
}