Fix hspace's KM metrics
[ganeti-local] / Ganeti / HTools / QC.hs
index 6321029..c23e81d 100644 (file)
@@ -24,12 +24,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 -}
 
 module Ganeti.HTools.QC
-    ( test_PeerMap
-    , test_Container
-    , test_Instance
-    , test_Node
-    , test_Text
-    , test_Cluster
+    ( testPeerMap
+    , testContainer
+    , testInstance
+    , testNode
+    , testText
+    , testCluster
     ) where
 
 import Test.QuickCheck
@@ -69,7 +69,7 @@ instance Arbitrary Instance.Instance where
       pn <- arbitrary
       sn <- arbitrary
       vcpus <- arbitrary
-      return $ Instance.create name mem dsk vcpus run_st pn sn
+      return $ Instance.create name mem dsk vcpus run_st [] pn sn
 
 -- and a random node
 instance Arbitrary Node.Node where
@@ -88,11 +88,11 @@ instance Arbitrary Node.Node where
       return n'
 
 -- | Make sure add is idempotent
-prop_PeerMap_addIdempotent pmap key elem =
+prop_PeerMap_addIdempotent pmap key em =
     fn puniq == fn (fn puniq)
     where _types = (pmap::PeerMap.PeerMap,
-                    key::PeerMap.Key, elem::PeerMap.Elem)
-          fn = PeerMap.add key elem
+                    key::PeerMap.Key, em::PeerMap.Elem)
+          fn = PeerMap.add key em
           puniq = PeerMap.accumArray const pmap
 
 -- | Make sure remove is idempotent
@@ -109,10 +109,10 @@ prop_PeerMap_findMissing pmap key =
           puniq = PeerMap.accumArray const pmap
 
 -- | Make sure an added item is found
-prop_PeerMap_addFind pmap key elem =
-    PeerMap.find key (PeerMap.add key elem puniq) == elem
+prop_PeerMap_addFind pmap key em =
+    PeerMap.find key (PeerMap.add key em puniq) == em
     where _types = (pmap::PeerMap.PeerMap,
-                    key::PeerMap.Key, elem::PeerMap.Elem)
+                    key::PeerMap.Key, em::PeerMap.Elem)
           puniq = PeerMap.accumArray const pmap
 
 -- | Manual check that maxElem returns the maximum indeed, or 0 for null
@@ -122,7 +122,7 @@ prop_PeerMap_maxElem pmap =
     where _types = pmap::PeerMap.PeerMap
           puniq = PeerMap.accumArray const pmap
 
-test_PeerMap =
+testPeerMap =
     [ run prop_PeerMap_addIdempotent
     , run prop_PeerMap_removeIdempotent
     , run prop_PeerMap_maxElem
@@ -140,7 +140,7 @@ prop_Container_addTwo cdata i1 i2 =
           cont = foldl (\c x -> Container.add x x c) Container.empty cdata
           fn x1 x2 = Container.addTwo x1 x1 x2 x2
 
-test_Container =
+testContainer =
     [ run prop_Container_addTwo ]
 
 -- Simple instance tests, we only have setter/getters
@@ -154,31 +154,31 @@ prop_Instance_setName inst name =
     where _types = (inst::Instance.Instance, name::String)
 
 prop_Instance_setPri inst pdx =
-    Instance.pnode (Instance.setPri inst pdx) == pdx
+    Instance.pNode (Instance.setPri inst pdx) == pdx
     where _types = (inst::Instance.Instance, pdx::Types.Ndx)
 
 prop_Instance_setSec inst sdx =
-    Instance.snode (Instance.setSec inst sdx) == sdx
+    Instance.sNode (Instance.setSec inst sdx) == sdx
     where _types = (inst::Instance.Instance, sdx::Types.Ndx)
 
 prop_Instance_setBoth inst pdx sdx =
-    Instance.pnode si == pdx && Instance.snode si == sdx
+    Instance.pNode si == pdx && Instance.sNode si == sdx
     where _types = (inst::Instance.Instance, pdx::Types.Ndx, sdx::Types.Ndx)
           si = Instance.setBoth inst pdx sdx
 
 prop_Instance_runStatus_True inst =
     let run_st = Instance.running inst
-        run_tx = Instance.run_st inst
+        run_tx = Instance.runSt inst
     in
-      run_tx == "running" || run_tx == "ERROR_up" ==> run_st == True
+      run_tx `elem` Instance.runningStates ==> run_st
 
 prop_Instance_runStatus_False inst =
     let run_st = Instance.running inst
-        run_tx = Instance.run_st inst
+        run_tx = Instance.runSt inst
     in
-      run_tx /= "running" && run_tx /= "ERROR_up" ==> run_st == False
+      run_tx `notElem` Instance.runningStates ==> not run_st
 
-test_Instance =
+testInstance =
     [ run prop_Instance_setIdx
     , run prop_Instance_setName
     , run prop_Instance_setPri
@@ -199,8 +199,9 @@ prop_Text_Load_Instance name mem dsk vcpus status pnode snode pdx sdx =
                then sdx + 1
                else sdx
         ndx = [(pnode, pdx), (rsnode, rsdx)]
+        tags = ""
         inst = Text.loadInst ndx
-               (name:mem_s:dsk_s:vcpus_s:status:pnode:rsnode:[])::
+               [name, mem_s, dsk_s, vcpus_s, status, pnode, rsnode, tags]::
                Maybe (String, Instance.Instance)
         _types = ( name::String, mem::Int, dsk::Int
                  , vcpus::Int, status::String
@@ -213,18 +214,18 @@ prop_Text_Load_Instance name mem dsk vcpus status pnode snode pdx sdx =
             (Instance.name i == name &&
              Instance.vcpus i == vcpus &&
              Instance.mem i == mem &&
-             Instance.pnode i == pdx &&
-             Instance.snode i == rsdx)
+             Instance.pNode i == pdx &&
+             Instance.sNode i == rsdx)
 
-test_Text =
+testText =
     [ run prop_Text_Load_Instance
     ]
 
 -- Node tests
 
 -- | Check that an instance add with too high memory or disk will be rejected
-prop_Node_addPri node inst = (Instance.mem inst >= Node.f_mem node ||
-                              Instance.dsk inst >= Node.f_dsk node) &&
+prop_Node_addPri node inst = (Instance.mem inst >= Node.fMem node ||
+                              Instance.dsk inst >= Node.fDsk node) &&
                              not (Node.failN1 node)
                              ==>
                              isFailure (Node.addPri node inst)
@@ -233,13 +234,13 @@ prop_Node_addPri node inst = (Instance.mem inst >= Node.f_mem node ||
 
 -- | Check that an instance add with too high memory or disk will be rejected
 prop_Node_addSec node inst pdx =
-    (Instance.mem inst >= (Node.f_mem node - Node.r_mem node) ||
-     Instance.dsk inst >= Node.f_dsk node) &&
+    (Instance.mem inst >= (Node.fMem node - Node.rMem node) ||
+     Instance.dsk inst >= Node.fDsk node) &&
     not (Node.failN1 node)
     ==> isFailure (Node.addSec node inst pdx)
         where _types = (node::Node.Node, inst::Instance.Instance, pdx::Int)
 
-test_Node =
+testNode =
     [ run prop_Node_addPri
     , run prop_Node_addSec
     ]
@@ -249,16 +250,16 @@ test_Node =
 
 -- | Check that the cluster score is close to zero for a homogeneous cluster
 prop_Score_Zero node count =
-    ((not $ Node.offline node) && (not $ Node.failN1 node) && (count > 0) &&
-     (Node.t_dsk node > 0) && (Node.t_mem node > 0)) ==>
+    (not (Node.offline node) && not (Node.failN1 node) && (count > 0) &&
+     (Node.tDsk node > 0) && (Node.tMem node > 0)) ==>
     let fn = Node.buildPeers node Container.empty
-        nlst = (zip [1..] $ replicate count fn)::[(Types.Ndx, Node.Node)]
+        nlst = zip [1..] $ replicate count fn::[(Types.Ndx, Node.Node)]
         nl = Container.fromAssocList nlst
         score = Cluster.compCV nl
     -- we can't say == 0 here as the floating point errors accumulate;
     -- this should be much lower than the default score in CLI.hs
-    in score > 1e-15
+    in score <= 1e-15
 
-test_Cluster =
+testCluster =
     [ run prop_Score_Zero
     ]