Commit a46f34d7 authored by Iustin Pop's avatar Iustin Pop
Browse files

Abstract instance running states into a list

This removes some manual checks from a few places in the code with a
single list defined once.
parent 5182e970
......@@ -39,6 +39,7 @@ module Ganeti.HTools.Instance
, setMovable
, specOf
, shrinkByType
, runningStates
) where
import qualified Ganeti.HTools.Types as T
......@@ -77,6 +78,10 @@ unitDsk = 256
unitCpu :: Int
unitCpu = 1
-- | Running instance states.
runningStates :: [String]
runningStates = ["running", "ERROR_up"]
-- | A simple name for the int, instance association list.
type AssocList = [(T.Idx, Instance)]
......@@ -96,7 +101,7 @@ create name_init mem_init dsk_init vcpus_init run_init tags_init pn sn =
, mem = mem_init
, dsk = dsk_init
, vcpus = vcpus_init
, running = run_init == "running" || run_init == "ERROR_up"
, running = run_init `elem` runningStates
, runSt = run_init
, pNode = pn
, sNode = sn
......
......@@ -170,13 +170,13 @@ prop_Instance_runStatus_True inst =
let run_st = Instance.running inst
run_tx = Instance.runSt inst
in
run_tx == "running" || run_tx == "ERROR_up" ==> run_st
run_tx `elem` Instance.runningStates ==> run_st
prop_Instance_runStatus_False inst =
let run_st = Instance.running inst
run_tx = Instance.runSt inst
in
run_tx /= "running" && run_tx /= "ERROR_up" ==> not run_st
run_tx `notElem` Instance.runningStates ==> not run_st
testInstance =
[ run prop_Instance_setIdx
......
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