Commit 7dd14211 authored by Agata Murawska's avatar Agata Murawska
Browse files

htools: change runSt type to InstanceStatus


Signed-off-by: default avatarAgata Murawska <agatamurawska@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 3771d104
......@@ -68,8 +68,7 @@ parseBaseInstance n a = do
vcpus <- extract "vcpus"
tags <- extract "tags"
dt <- extract "disk_template"
let running = "running"
return (n, Instance.create n mem disk vcpus running tags True 0 0 dt)
return (n, Instance.create n mem disk vcpus Running tags True 0 0 dt)
-- | Parses an instance as found in the cluster instance list.
parseInstance :: NameAssoc -- ^ The node name-to-index association list
......
......@@ -62,7 +62,7 @@ data Instance = Instance
, dsk :: Int -- ^ Disk size of instance
, vcpus :: Int -- ^ Number of VCPUs
, running :: Bool -- ^ Is the instance running?
, runSt :: String -- ^ Original (text) run status
, runSt :: T.InstanceStatus -- ^ Original run status
, pNode :: T.Ndx -- ^ Original primary node
, sNode :: T.Ndx -- ^ Original secondary node
, idx :: T.Idx -- ^ Internal index
......@@ -81,8 +81,8 @@ instance T.Element Instance where
allNames n = [name n, alias n]
-- | Constant holding the running instance states.
runningStates :: [String]
runningStates = [C.inststRunning, C.inststErrorup]
runningStates :: [T.InstanceStatus]
runningStates = [T.Running, T.ErrorUp]
-- | Constant holding the local storage templates.
--
......@@ -115,7 +115,7 @@ type List = Container.Container Instance
--
-- Some parameters are not initialized by function, and must be set
-- later (via 'setIdx' for example).
create :: String -> Int -> Int -> Int -> String
create :: String -> Int -> Int -> Int -> T.InstanceStatus
-> [String] -> Bool -> T.Ndx -> T.Ndx -> T.DiskTemplate -> Instance
create name_init mem_init dsk_init vcpus_init run_init tags_init
auto_balance_init pn sn dt =
......
......@@ -424,7 +424,7 @@ main = do
-- utility functions
let iofspec spx = Instance.create "new" (rspecMem spx) (rspecDsk spx)
(rspecCpu spx) "running" [] True (-1) (-1) disk_template
(rspecCpu spx) Running [] True (-1) (-1) disk_template
allocnodes <- exitIfBad $ Cluster.genAllocNodes gl nl req_nodes True
......
......@@ -123,7 +123,7 @@ setInstanceSmallerThanNode node inst =
-- | Create an instance given its spec.
createInstance mem dsk vcpus =
Instance.create "inst-unnamed" mem dsk vcpus "running" [] True (-1) (-1)
Instance.create "inst-unnamed" mem dsk vcpus Types.Running [] True (-1) (-1)
Types.DTDrbd8
-- | Create a small cluster by repeating a node spec.
......@@ -187,20 +187,23 @@ getFQDN = do
let frest' = map (map dnsGetChar) frest
return (felem ++ "." ++ intercalate "." frest')
instance Arbitrary Types.InstanceStatus where
arbitrary = elements [ Types.AdminDown
, Types.AdminOffline
, Types.ErrorDown
, Types.ErrorUp
, Types.NodeDown
, Types.NodeOffline
, Types.Running
, Types.WrongNode]
-- let's generate a random instance
instance Arbitrary Instance.Instance where
arbitrary = do
name <- getFQDN
mem <- choose (0, maxMem)
dsk <- choose (0, maxDsk)
run_st <- elements [ C.inststErrorup
, C.inststErrordown
, C.inststAdmindown
, C.inststNodedown
, C.inststNodeoffline
, C.inststRunning
, "no_such_status1"
, "no_such_status2"]
run_st <- arbitrary
pn <- arbitrary
sn <- arbitrary
vcpus <- choose (0, maxCpu)
......@@ -591,6 +594,7 @@ prop_Text_Load_Instance name mem dsk vcpus status
let vcpus_s = show vcpus
dsk_s = show dsk
mem_s = show mem
status_s = Types.instanceStatusToRaw status
ndx = if null snode
then [(pnode, pdx)]
else [(pnode, pdx), (snode, sdx)]
......@@ -599,13 +603,13 @@ prop_Text_Load_Instance name mem dsk vcpus status
sbal = if autobal then "Y" else "N"
sdt = Types.diskTemplateToRaw dt
inst = Text.loadInst nl
[name, mem_s, dsk_s, vcpus_s, status,
[name, mem_s, dsk_s, vcpus_s, status_s,
sbal, pnode, snode, sdt, tags]
fail1 = Text.loadInst nl
[name, mem_s, dsk_s, vcpus_s, status,
[name, mem_s, dsk_s, vcpus_s, status_s,
sbal, pnode, pnode, tags]
_types = ( name::String, mem::Int, dsk::Int
, vcpus::Int, status::String
, vcpus::Int, status::Types.InstanceStatus
, snode::String
, autobal::Bool)
in
......
......@@ -95,7 +95,7 @@ serializeInstance nl inst =
in
printf "%s|%d|%d|%d|%s|%s|%s|%s|%s|%s"
iname (Instance.mem inst) (Instance.dsk inst)
(Instance.vcpus inst) (Instance.runSt inst)
(Instance.vcpus inst) (instanceStatusToRaw (Instance.runSt inst))
(if Instance.autoBalance inst then "Y" else "N")
pnode snode (diskTemplateToRaw (Instance.diskTemplate inst))
(intercalate "," (Instance.tags inst))
......@@ -162,6 +162,7 @@ loadInst ktn [ name, mem, dsk, vcpus, status, auto_bal, pnode, snode
vmem <- tryRead name mem
vdsk <- tryRead name dsk
vvcpus <- tryRead name vcpus
vstatus <- instanceStatusFromRaw status
auto_balance <- case auto_bal of
"Y" -> return True
"N" -> return False
......@@ -172,7 +173,7 @@ loadInst ktn [ name, mem, dsk, vcpus, status, auto_bal, pnode, snode
when (sidx == pidx) $ fail $ "Instance " ++ name ++
" has same primary and secondary node - " ++ pnode
let vtags = sepSplit ',' tags
newinst = Instance.create name vmem vdsk vvcpus status vtags
newinst = Instance.create name vmem vdsk vvcpus vstatus vtags
auto_balance pidx sidx disk_template
return (name, newinst)
loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ show s ++ "'"
......
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