From d067f40b0b9f2aee13c5fa5daa8695f6e94a3eae Mon Sep 17 00:00:00 2001 From: "Jose A. Lopes" Date: Wed, 25 Sep 2013 15:40:14 +0200 Subject: [PATCH] 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: Jose A. Lopes Reviewed-by: Klaus Aehlig --- lib/ht.py | 2 +- lib/masterd/iallocator.py | 2 +- src/Ganeti/HTools/Backend/IAlloc.hs | 1 + src/Ganeti/HTools/Cluster.hs | 2 +- src/Ganeti/HTools/Loader.hs | 1 + src/Ganeti/HTools/Types.hs | 9 --------- src/Ganeti/HsConstants.hs | 8 ++++---- src/Ganeti/OpParams.hs | 4 ++-- src/Ganeti/Types.hs | 19 ++++++++++++------- test/hs/Test/Ganeti/HTools/Cluster.hs | 1 + test/hs/Test/Ganeti/HTools/Types.hs | 7 ------- test/hs/Test/Ganeti/Types.hs | 4 ++-- 12 files changed, 26 insertions(+), 34 deletions(-) diff --git a/lib/ht.py b/lib/ht.py index f0f0b5d..d6171ac 100644 --- 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) diff --git a/lib/masterd/iallocator.py b/lib/masterd/iallocator.py index 5a670b6..e380db6 100644 --- a/lib/masterd/iallocator.py +++ b/lib/masterd/iallocator.py @@ -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 diff --git a/src/Ganeti/HTools/Backend/IAlloc.hs b/src/Ganeti/HTools/Backend/IAlloc.hs index dd92497..27dc2e6 100644 --- a/src/Ganeti/HTools/Backend/IAlloc.hs +++ b/src/Ganeti/HTools/Backend/IAlloc.hs @@ -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" #-} diff --git a/src/Ganeti/HTools/Cluster.hs b/src/Ganeti/HTools/Cluster.hs index 88891a4..fe3432c 100644 --- a/src/Ganeti/HTools/Cluster.hs +++ b/src/Ganeti/HTools/Cluster.hs @@ -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 diff --git a/src/Ganeti/HTools/Loader.hs b/src/Ganeti/HTools/Loader.hs index 49d337d..7049ff6 100644 --- a/src/Ganeti/HTools/Loader.hs +++ b/src/Ganeti/HTools/Loader.hs @@ -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 diff --git a/src/Ganeti/HTools/Types.hs b/src/Ganeti/HTools/Types.hs index 764c56c..b4f8c86 100644 --- a/src/Ganeti/HTools/Types.hs +++ b/src/Ganeti/HTools/Types.hs @@ -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. diff --git a/src/Ganeti/HsConstants.hs b/src/Ganeti/HsConstants.hs index 1a64e2d..fe20ff6 100644 --- a/src/Ganeti/HsConstants.hs +++ b/src/Ganeti/HsConstants.hs @@ -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 diff --git a/src/Ganeti/OpParams.hs b/src/Ganeti/OpParams.hs index fee24aa..ed06a02 100644 --- a/src/Ganeti/OpParams.hs +++ b/src/Ganeti/OpParams.hs @@ -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 = diff --git a/src/Ganeti/Types.hs b/src/Ganeti/Types.hs index ba9dea7..bf6012a 100644 --- a/src/Ganeti/Types.hs +++ b/src/Ganeti/Types.hs @@ -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" diff --git a/test/hs/Test/Ganeti/HTools/Cluster.hs b/test/hs/Test/Ganeti/HTools/Cluster.hs index fe63b79..0555f7c 100644 --- a/test/hs/Test/Ganeti/HTools/Cluster.hs +++ b/test/hs/Test/Ganeti/HTools/Cluster.hs @@ -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" #-} diff --git a/test/hs/Test/Ganeti/HTools/Types.hs b/test/hs/Test/Ganeti/HTools/Types.hs index fecbda2..4556a13 100644 --- a/test/hs/Test/Ganeti/HTools/Types.hs +++ b/test/hs/Test/Ganeti/HTools/Types.hs @@ -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 diff --git a/test/hs/Test/Ganeti/Types.hs b/test/hs/Test/Ganeti/Types.hs index 0e8c5eb..4315ecb 100644 --- a/test/hs/Test/Ganeti/Types.hs +++ b/test/hs/Test/Ganeti/Types.hs @@ -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. -- 1.7.10.4