Commit d067f40b authored by Jose A. Lopes's avatar Jose A. Lopes
Browse files

Merge 'EvacNode' and 'NodeEvacMode'



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: default avatarJose A. Lopes <jabolopes@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 6dc364f9
......@@ -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)
......
......@@ -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
......
......@@ -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" #-}
......
......@@ -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
......
......@@ -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
......
......@@ -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.
......
......@@ -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
......
......@@ -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 =
......
......@@ -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"
......
......@@ -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" #-}
......
......@@ -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
......
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment