From a46f34d7fab2bf029332d7ff1d86ebbcb19c621d Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Thu, 25 Feb 2010 14:47:17 +0100 Subject: [PATCH] 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. --- Ganeti/HTools/Instance.hs | 7 ++++++- Ganeti/HTools/QC.hs | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Ganeti/HTools/Instance.hs b/Ganeti/HTools/Instance.hs index d14ad933d..c091f62a9 100644 --- a/Ganeti/HTools/Instance.hs +++ b/Ganeti/HTools/Instance.hs @@ -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 diff --git a/Ganeti/HTools/QC.hs b/Ganeti/HTools/QC.hs index 35c4b1e71..c23e81db1 100644 --- a/Ganeti/HTools/QC.hs +++ b/Ganeti/HTools/QC.hs @@ -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 -- GitLab