From 8a8ed513ea8eaf30af186c424831ad09d8338b65 Mon Sep 17 00:00:00 2001
From: Agata Murawska <agatamurawska@google.com>
Date: Mon, 14 Nov 2011 14:54:32 +0100
Subject: [PATCH] htools: remove 'running' from instance options

Signed-off-by: Agata Murawska <agatamurawska@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 htools/Ganeti/HTools/Cluster.hs  |  4 ++--
 htools/Ganeti/HTools/Instance.hs | 12 ++++++------
 htools/Ganeti/HTools/Loader.hs   |  2 +-
 htools/Ganeti/HTools/QC.hs       | 13 -------------
 4 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/htools/Ganeti/HTools/Cluster.hs b/htools/Ganeti/HTools/Cluster.hs
index aa5b4a679..16001c31e 100644
--- a/htools/Ganeti/HTools/Cluster.hs
+++ b/htools/Ganeti/HTools/Cluster.hs
@@ -1225,7 +1225,7 @@ computeMoves i inam mv c d =
       ReplaceSecondary _ -> (printf "r:%s" d, [rep d])
       ReplaceAndFailover _ -> (printf "r:%s f" c, [rep c, mig])
       ReplacePrimary _ -> (printf "f r:%s f" c, [mig, rep c, mig])
-    where morf = if Instance.running i then "migrate" else "failover"
+    where morf = if Instance.instanceRunning i then "migrate" else "failover"
           mig = printf "%s -f %s" morf inam::String
           rep n = printf "replace-disks -n %s %s" n inam
 
@@ -1325,7 +1325,7 @@ printNodes nl fs =
 printInsts :: Node.List -> Instance.List -> String
 printInsts nl il =
     let sil = sortBy (comparing Instance.idx) (Container.elems il)
-        helper inst = [ if Instance.running inst then "R" else " "
+        helper inst = [ if Instance.instanceRunning inst then "R" else " "
                       , Instance.name inst
                       , Container.nameOf nl (Instance.pNode inst)
                       , let sdx = Instance.sNode inst
diff --git a/htools/Ganeti/HTools/Instance.hs b/htools/Ganeti/HTools/Instance.hs
index 519e3851c..1d7bc7876 100644
--- a/htools/Ganeti/HTools/Instance.hs
+++ b/htools/Ganeti/HTools/Instance.hs
@@ -31,6 +31,7 @@ module Ganeti.HTools.Instance
     , AssocList
     , List
     , create
+    , instanceRunning
     , setIdx
     , setName
     , setAlias
@@ -40,7 +41,6 @@ module Ganeti.HTools.Instance
     , setMovable
     , specOf
     , shrinkByType
-    , runningStates
     , localStorageTemplates
     , hasSecondary
     , requiredNodes
@@ -61,7 +61,6 @@ data Instance = Instance
     , mem          :: Int       -- ^ Memory of the instance
     , dsk          :: Int       -- ^ Disk size of instance
     , vcpus        :: Int       -- ^ Number of VCPUs
-    , running      :: Bool      -- ^ Is the instance running?
     , runSt        :: T.InstanceStatus -- ^ Original run status
     , pNode        :: T.Ndx     -- ^ Original primary node
     , sNode        :: T.Ndx     -- ^ Original secondary node
@@ -80,9 +79,11 @@ instance T.Element Instance where
     setIdx   = setIdx
     allNames n = [name n, alias n]
 
--- | Constant holding the running instance states.
-runningStates :: [T.InstanceStatus]
-runningStates = [T.Running, T.ErrorUp]
+-- | Check if instance is running.
+instanceRunning :: Instance -> Bool
+instanceRunning (Instance {runSt = T.Running}) = True
+instanceRunning (Instance {runSt = T.ErrorUp}) = True
+instanceRunning _                               = False
 
 -- | Constant holding the local storage templates.
 --
@@ -124,7 +125,6 @@ create name_init mem_init dsk_init vcpus_init run_init tags_init
              , mem = mem_init
              , dsk = dsk_init
              , vcpus = vcpus_init
-             , running = run_init `elem` runningStates
              , runSt = run_init
              , pNode = pn
              , sNode = sn
diff --git a/htools/Ganeti/HTools/Loader.hs b/htools/Ganeti/HTools/Loader.hs
index 8f6fb6385..9bbad6e9f 100644
--- a/htools/Ganeti/HTools/Loader.hs
+++ b/htools/Ganeti/HTools/Loader.hs
@@ -306,7 +306,7 @@ checkData nl il =
         (\ msgs node ->
              let nname = Node.name node
                  nilst = map (`Container.find` il) (Node.pList node)
-                 dilst = filter (not . Instance.running) nilst
+                 dilst = filter (not . Instance.instanceRunning) nilst
                  adj_mem = sum . map Instance.mem $ dilst
                  delta_mem = truncate (Node.tMem node)
                              - Node.nMem node
diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs
index 40fa0fe68..a55ba02c2 100644
--- a/htools/Ganeti/HTools/QC.hs
+++ b/htools/Ganeti/HTools/QC.hs
@@ -513,17 +513,6 @@ prop_Instance_setBoth inst pdx sdx =
     where _types = (inst::Instance.Instance, pdx::Types.Ndx, sdx::Types.Ndx)
           si = Instance.setBoth inst pdx sdx
 
-prop_Instance_runStatus_True =
-    forAll (arbitrary `suchThat`
-            ((`elem` Instance.runningStates) . Instance.runSt))
-    Instance.running
-
-prop_Instance_runStatus_False inst =
-    let run_st = Instance.running inst
-        run_tx = Instance.runSt inst
-    in
-      run_tx `notElem` Instance.runningStates ==> not run_st
-
 prop_Instance_shrinkMG inst =
     Instance.mem inst >= 2 * Types.unitMem ==>
         case Instance.shrinkByType inst Types.FailMem of
@@ -572,8 +561,6 @@ testSuite "Instance"
               , 'prop_Instance_setPri
               , 'prop_Instance_setSec
               , 'prop_Instance_setBoth
-              , 'prop_Instance_runStatus_True
-              , 'prop_Instance_runStatus_False
               , 'prop_Instance_shrinkMG
               , 'prop_Instance_shrinkMF
               , 'prop_Instance_shrinkCG
-- 
GitLab