Remove Node.mCpu, replaced with the ipol vcpu_ratio
authorIustin Pop <iustin@google.com>
Tue, 24 Jan 2012 12:36:33 +0000 (13:36 +0100)
committerIustin Pop <iustin@google.com>
Thu, 26 Jan 2012 13:34:39 +0000 (14:34 +0100)
Since the iPolicy contains the vcpu_ratio now, we can remove the
per-node mCpu value (which was the initial way to set this attribute).

Furthermore, we need to re-set the hiCpu value when changing the
policy.

And of course some associated unittest changes.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenĂ© Nussbaumer <rn@google.com>

htools/Ganeti/HTools/Node.hs
htools/Ganeti/HTools/QC.hs

index 740c0e9..0f686c0 100644 (file)
@@ -113,7 +113,6 @@ data Node = Node
   , pRem     :: Double    -- ^ Percent of reserved memory
   , pCpu     :: Double    -- ^ Ratio of virtual to physical CPUs
   , mDsk     :: Double    -- ^ Minimum free disk ratio
-  , mCpu     :: Double    -- ^ Max ratio of virt-to-phys CPUs
   , loDsk    :: Int       -- ^ Autocomputed from mDsk low disk
                           -- threshold
   , hiCpu    :: Int       -- ^ Autocomputed from mCpu high cpu
@@ -214,9 +213,8 @@ create name_init mem_t_init mem_n_init mem_f_init
        , offline = offline_init
        , xMem = 0
        , mDsk = T.defReservedDiskRatio
-       , mCpu = T.defVcpuRatio
        , loDsk = mDskToloDsk T.defReservedDiskRatio dsk_t_init
-       , hiCpu = mCpuTohiCpu T.defVcpuRatio cpu_t_init
+       , hiCpu = mCpuTohiCpu (T.iPolicyVcpuRatio T.defIPolicy) cpu_t_init
        , utilPool = T.baseUtil
        , utilLoad = T.zeroUtil
        , pTags = Map.empty
@@ -256,13 +254,18 @@ setXmem t val = t { xMem = val }
 setMdsk :: Node -> Double -> Node
 setMdsk t val = t { mDsk = val, loDsk = mDskToloDsk val (tDsk t) }
 
--- | Sets the max cpu usage ratio.
+-- | Sets the max cpu usage ratio. This will update the node's
+-- ipolicy, losing sharing (but it should be a seldomly done operation).
 setMcpu :: Node -> Double -> Node
-setMcpu t val = t { mCpu = val, hiCpu = mCpuTohiCpu val (tCpu t) }
+setMcpu t val =
+  let new_ipol = (iPolicy t) { T.iPolicyVcpuRatio = val }
+  in t { hiCpu = mCpuTohiCpu val (tCpu t), iPolicy = new_ipol }
 
 -- | Sets the policy.
 setPolicy :: T.IPolicy -> Node -> Node
-setPolicy pol node = node { iPolicy = pol }
+setPolicy pol node =
+  node { iPolicy = pol
+       , hiCpu = mCpuTohiCpu (T.iPolicyVcpuRatio pol) (tCpu node) }
 
 -- | Computes the maximum reserved memory for peers from a peer map.
 computeMaxRes :: P.PeerMap -> P.Elem
@@ -391,7 +394,7 @@ addPriEx force t inst =
       new_ucpu = Instance.applyIfOnline inst (+ Instance.vcpus inst) (uCpu t)
       new_pcpu = fromIntegral new_ucpu / tCpu t
       new_dp = fromIntegral new_dsk / tDsk t
-      l_cpu = mCpu t
+      l_cpu = T.iPolicyVcpuRatio $ iPolicy t
       new_load = utilLoad t `T.addUtil` Instance.util inst
       inst_tags = Instance.tags inst
       old_tags = pTags t
index 159bf0a..fe83507 100644 (file)
@@ -809,11 +809,11 @@ prop_Text_Load_NodeFail fields =
 
 prop_Text_NodeLSIdempotent node =
   (Text.loadNode defGroupAssoc.
-       Utils.sepSplit '|' . Text.serializeNode defGroupList) n ==
+       Utils.sepSplit '|' . Text.serializeNode defGroupList) n ==?
   Just (Node.name n, n)
     -- override failN1 to what loadNode returns by default
-    where n = node { Node.failN1 = True, Node.offline = False
-                   , Node.iPolicy = Types.defIPolicy }
+    where n = Node.setPolicy Types.defIPolicy $
+              node { Node.failN1 = True, Node.offline = False }
 
 prop_Text_ISpecIdempotent ispec =
   case Text.loadISpec "dummy" . Utils.sepSplit ',' .
@@ -942,7 +942,7 @@ prop_Node_setXmem node xm =
     where newnode = Node.setXmem node xm
 
 prop_Node_setMcpu node mc =
-  Node.mCpu newnode ==? mc
+  Types.iPolicyVcpuRatio (Node.iPolicy newnode) ==? mc
     where newnode = Node.setMcpu node mc
 
 -- | Check that an instance add with too high memory or disk will be