Merge 'EvacNode' and 'NodeEvacMode'
authorJose A. Lopes <jabolopes@google.com>
Wed, 25 Sep 2013 13:40:14 +0000 (15:40 +0200)
committerJose A. Lopes <jabolopes@google.com>
Wed, 2 Oct 2013 12:50:28 +0000 (14:50 +0200)
Merge 'EvacMode' and 'NodeEvacMode' which are associated with the
duplicated constants 'IALLOCATOR_NEVAC_*' and 'NODE_EVAC_*'.  This
merge moves the type 'EvacMode' to 'Ganeti.Types' in order to avoid a
circular dependency between 'Ganeti.HsConstants' and
'Ganeti.HTools.Types'.  The type 'EvacMode' is preferred to the type
'NodeEvacMode' given that its use is more widespread.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

12 files changed:
lib/ht.py
lib/masterd/iallocator.py
src/Ganeti/HTools/Backend/IAlloc.hs
src/Ganeti/HTools/Cluster.hs
src/Ganeti/HTools/Loader.hs
src/Ganeti/HTools/Types.hs
src/Ganeti/HsConstants.hs
src/Ganeti/OpParams.hs
src/Ganeti/Types.hs
test/hs/Test/Ganeti/HTools/Cluster.hs
test/hs/Test/Ganeti/HTools/Types.hs
test/hs/Test/Ganeti/Types.hs

index f0f0b5d..d6171ac 100644 (file)
--- a/lib/ht.py
+++ b/lib/ht.py
@@ -537,7 +537,7 @@ TExportMode = TElemOf(constants.EXPORT_MODES)
 TDiskIndex = TAnd(TNonNegativeInt, lambda val: val < constants.MAX_DISKS)
 TReplaceDisksMode = TElemOf(constants.REPLACE_MODES)
 TDiskTemplate = TElemOf(constants.DISK_TEMPLATES)
-TNodeEvacMode = TElemOf(constants.NODE_EVAC_MODES)
+TEvacMode = TElemOf(constants.NODE_EVAC_MODES)
 TIAllocatorTestDir = TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS)
 TIAllocatorMode = TElemOf(constants.VALID_IALLOCATOR_MODES)
 
index 5a670b6..e380db6 100644 (file)
@@ -336,7 +336,7 @@ class IAReqNodeEvac(IARequestBase):
   MODE = constants.IALLOCATOR_MODE_NODE_EVAC
   REQ_PARAMS = [
     ("instances", _STRING_LIST),
-    ("evac_mode", ht.TNodeEvacMode),
+    ("evac_mode", ht.TEvacMode),
     ]
   REQ_RESULT = _NEVAC_RESULT
 
index dd92497..27dc2e6 100644 (file)
@@ -50,6 +50,7 @@ import Ganeti.HTools.CLI
 import Ganeti.HTools.Loader
 import Ganeti.HTools.Types
 import Ganeti.JSON
+import Ganeti.Types (EvacMode(ChangePrimary, ChangeSecondary))
 import Ganeti.Utils
 
 {-# ANN module "HLint: ignore Eta reduce" #-}
index 88891a4..fe3432c 100644 (file)
@@ -94,7 +94,7 @@ import Ganeti.HTools.Types
 import Ganeti.Compat
 import qualified Ganeti.OpCodes as OpCodes
 import Ganeti.Utils
-import Ganeti.Types (mkNonEmpty)
+import Ganeti.Types (EvacMode(..), mkNonEmpty)
 
 -- * Types
 
index 49d337d..7049ff6 100644 (file)
@@ -60,6 +60,7 @@ import Ganeti.BasicTypes
 import qualified Ganeti.Constants as C
 import Ganeti.HTools.Types
 import Ganeti.Utils
+import Ganeti.Types (EvacMode)
 
 -- * Constants
 
index 764c56c..b4f8c86 100644 (file)
@@ -69,7 +69,6 @@ module Ganeti.HTools.Types
   , FailStats
   , OpResult
   , opToResult
-  , EvacMode(..)
   , ISpec(..)
   , MinMaxISpecs(..)
   , IPolicy(..)
@@ -378,14 +377,6 @@ class Element a where
   -- | Updates the index of the element
   setIdx  :: a -> Int -> a
 
--- | The iallocator node-evacuate evac_mode type.
-$(THH.declareSADT "EvacMode"
-       [ ("ChangePrimary",   'C.iallocatorNevacPri)
-       , ("ChangeSecondary", 'C.iallocatorNevacSec)
-       , ("ChangeAll",       'C.iallocatorNevacAll)
-       ])
-$(THH.makeJSONInstance ''EvacMode)
-
 -- | The repair modes for the auto-repair tool.
 $(THH.declareSADT "AutoRepairType"
        -- Order is important here: from least destructive to most.
index 1a64e2d..fe20ff6 100644 (file)
@@ -1100,16 +1100,16 @@ defaultIallocatorShortcut = "."
 -- * Node evacuation
 
 nodeEvacPri :: String
-nodeEvacPri = Types.nodeEvacModeToRaw NEvacPrimary
+nodeEvacPri = Types.evacModeToRaw ChangePrimary
 
 nodeEvacSec :: String
-nodeEvacSec = Types.nodeEvacModeToRaw NEvacSecondary
+nodeEvacSec = Types.evacModeToRaw ChangeSecondary
 
 nodeEvacAll :: String
-nodeEvacAll = Types.nodeEvacModeToRaw NEvacAll
+nodeEvacAll = Types.evacModeToRaw ChangeAll
 
 nodeEvacModes :: FrozenSet String
-nodeEvacModes = ConstantUtils.mkSet $ map Types.nodeEvacModeToRaw [minBound..]
+nodeEvacModes = ConstantUtils.mkSet $ map Types.evacModeToRaw [minBound..]
 
 -- * Job status
 
index fee24aa..ed06a02 100644 (file)
@@ -940,7 +940,7 @@ pRemoteNodeUuid =
 pEvacMode :: Field
 pEvacMode =
   withDoc "Node evacuation mode" .
-  renameField "EvacMode" $ simpleField "mode" [t| NodeEvacMode |]
+  renameField "EvacMode" $ simpleField "mode" [t| EvacMode |]
 
 pInstanceName :: Field
 pInstanceName =
@@ -1485,7 +1485,7 @@ pIAllocatorEvacMode =
   withDoc "IAllocator evac mode" .
   renameField "IAllocatorEvacMode" .
   optionalField $
-  simpleField "evac_mode" [t| NodeEvacMode |]
+  simpleField "evac_mode" [t| EvacMode |]
 
 pIAllocatorSpindleUse :: Field
 pIAllocatorSpindleUse =
index ba9dea7..bf6012a 100644 (file)
@@ -82,8 +82,8 @@ module Ganeti.Types
   , oobStatusToRaw
   , StorageType(..)
   , storageTypeToRaw
-  , NodeEvacMode(..)
-  , nodeEvacModeToRaw
+  , EvacMode(..)
+  , evacModeToRaw
   , FileDriver(..)
   , fileDriverToRaw
   , InstCreateMode(..)
@@ -512,12 +512,17 @@ addParamsToStorageUnit es (SURaw StorageLvmVg key) = SULvmVg key es
 addParamsToStorageUnit _ (SURaw StorageRados key) = SURados key
 
 -- | Node evac modes.
-$(THH.declareLADT ''String "NodeEvacMode"
-  [ ("NEvacPrimary",   "primary-only")
-  , ("NEvacSecondary", "secondary-only")
-  , ("NEvacAll",       "all")
+--
+-- This is part of the 'IAllocator' interface and it is used, for
+-- example, in 'Ganeti.HTools.Loader.RqType'.  However, it must reside
+-- in this module, and not in 'Ganeti.HTools.Types', because it is
+-- also used by 'Ganeti.HsConstants'.
+$(THH.declareLADT ''String "EvacMode"
+  [ ("ChangePrimary",   "primary-only")
+  , ("ChangeSecondary", "secondary-only")
+  , ("ChangeAll",       "all")
   ])
-$(THH.makeJSONInstance ''NodeEvacMode)
+$(THH.makeJSONInstance ''EvacMode)
 
 -- | The file driver type.
 $(THH.declareLADT ''String "FileDriver"
index fe63b79..0555f7c 100644 (file)
@@ -48,6 +48,7 @@ import qualified Ganeti.HTools.Group as Group
 import qualified Ganeti.HTools.Instance as Instance
 import qualified Ganeti.HTools.Node as Node
 import qualified Ganeti.HTools.Types as Types
+import qualified Ganeti.Types as Types (EvacMode(..))
 
 {-# ANN module "HLint: ignore Use camelCase" #-}
 
index fecbda2..4556a13 100644 (file)
@@ -31,7 +31,6 @@ module Test.Ganeti.HTools.Types
   , Types.AllocPolicy(..)
   , Types.DiskTemplate(..)
   , Types.FailMode(..)
-  , Types.EvacMode(..)
   , Types.ISpec(..)
   , Types.IPolicy(..)
   , nullIPolicy
@@ -61,8 +60,6 @@ import qualified Ganeti.HTools.Types as Types
 
 $(genArbitrary ''Types.FailMode)
 
-$(genArbitrary ''Types.EvacMode)
-
 instance Arbitrary a => Arbitrary (Types.OpResult a) where
   arbitrary = arbitrary >>= \c ->
               if c
@@ -155,9 +152,6 @@ prop_ISpec_serialisation = testSerialisation
 prop_IPolicy_serialisation :: Types.IPolicy -> Property
 prop_IPolicy_serialisation = testSerialisation
 
-prop_EvacMode_serialisation :: Types.EvacMode -> Property
-prop_EvacMode_serialisation = testSerialisation
-
 prop_opToResult :: Types.OpResult Int -> Property
 prop_opToResult op =
   case op of
@@ -200,7 +194,6 @@ case_AutoRepairResult_pyequiv = do
 testSuite "HTools/Types"
             [ 'prop_ISpec_serialisation
             , 'prop_IPolicy_serialisation
-            , 'prop_EvacMode_serialisation
             , 'prop_opToResult
             , 'prop_eitherToResult
             , 'case_AutoRepairType_sort
index 0e8c5eb..4315ecb 100644 (file)
@@ -115,7 +115,7 @@ allStorageTypes = [minBound..maxBound]::[StorageType]
 instance Arbitrary StorageType where
   arbitrary = elements allStorageTypes
 
-$(genArbitrary ''NodeEvacMode)
+$(genArbitrary ''EvacMode)
 
 $(genArbitrary ''FileDriver)
 
@@ -269,7 +269,7 @@ prop_StorageType_serialisation :: StorageType -> Property
 prop_StorageType_serialisation = testSerialisation
 
 -- | Test 'NodeEvacMode' serialisation.
-prop_NodeEvacMode_serialisation :: NodeEvacMode -> Property
+prop_NodeEvacMode_serialisation :: EvacMode -> Property
 prop_NodeEvacMode_serialisation = testSerialisation
 
 -- | Test 'FileDriver' serialisation.