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

Haskell to Python constants: more constants



* move several groups of constants, from Python to Haskell, which are
  currently being used in Haskell, including SSH and daemon related
  constants, policy allocation, blockdev driver manual (this is a
  single constant), auto repair related constants, and data collector
  version (also a single constant)
* constant 'AUTO_REPAIR_ALL_RESULTS' is moved to Python and its type
  changes from '[String]' to 'FrozenSet String' in order to be
  consistent with the Python type
* fix tests related to the constant 'autoRepairAllResults' (i.e., the
  Haskell version of 'AUTO_REPAIR_ALL_RESULTS') to reflect the type
  change
* update instances of 'FrozenSet'
Signed-off-by: default avatarJose A. Lopes <jabolopes@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 6970c28b
......@@ -38,7 +38,7 @@ import Ganeti.PyValueInstances ()
--
-- See 'PyValue' instance for 'FrozenSet'.
newtype FrozenSet a = FrozenSet { unFrozenSet :: Set a }
deriving (Show)
deriving (Eq, Show)
-- | Converts a Haskell 'Set' into a Python 'frozenset'
--
......
......@@ -102,3 +102,118 @@ sshLoginUser = AutoConf.sshLoginUser
sshConsoleUser :: String
sshConsoleUser = AutoConf.sshConsoleUser
-- * SSH constants
ssh :: String
ssh = "ssh"
scp :: String
scp = "scp"
-- * Daemons
confd :: String
confd = "ganeti-confd"
masterd :: String
masterd = "ganeti-masterd"
mond :: String
mond = "ganeti-mond"
noded :: String
noded = "ganeti-noded"
luxid :: String
luxid = "ganeti-luxid"
rapi :: String
rapi = "ganeti-rapi"
daemons :: FrozenSet String
daemons =
mkSet [confd,
luxid,
masterd,
mond,
noded,
rapi]
-- * Possible values for NodeGroup.alloc_policy
allocPolicyLastResort :: String
allocPolicyLastResort = "last_resort"
allocPolicyPreferred :: String
allocPolicyPreferred = "preferred"
allocPolicyUnallocable :: String
allocPolicyUnallocable = "unallocable"
validAllocPolicies :: [String]
validAllocPolicies =
[allocPolicyLastResort,
allocPolicyPreferred,
allocPolicyUnallocable]
-- | Temporary external/shared storage parameters
blockdevDriverManual :: String
blockdevDriverManual = "manual"
-- * Auto-repair tag prefixes
autoRepairTagPrefix :: String
autoRepairTagPrefix = "ganeti:watcher:autorepair:"
autoRepairTagEnabled :: String
autoRepairTagEnabled = autoRepairTagPrefix
autoRepairTagPending :: String
autoRepairTagPending = autoRepairTagPrefix ++ "pending:"
autoRepairTagResult :: String
autoRepairTagResult = autoRepairTagPrefix ++ "result:"
autoRepairTagSuspended :: String
autoRepairTagSuspended = autoRepairTagPrefix ++ "suspend:"
-- * Auto-repair levels
autoRepairFailover :: String
autoRepairFailover = "failover"
autoRepairFixStorage :: String
autoRepairFixStorage = "fix-storage"
autoRepairMigrate :: String
autoRepairMigrate = "migrate"
autoRepairReinstall :: String
autoRepairReinstall = "reinstall"
autoRepairAllTypes :: FrozenSet String
autoRepairAllTypes =
mkSet [autoRepairFailover,
autoRepairFixStorage,
autoRepairMigrate,
autoRepairReinstall]
-- * Auto-repair results
autoRepairEnoperm :: String
autoRepairEnoperm = "enoperm"
autoRepairFailure :: String
autoRepairFailure = "failure"
autoRepairSuccess :: String
autoRepairSuccess = "success"
autoRepairAllResults :: FrozenSet String
autoRepairAllResults =
mkSet [autoRepairEnoperm, autoRepairFailure, autoRepairSuccess]
-- | The version identifier for builtin data collectors
builtinDataCollectorVersion :: String
builtinDataCollectorVersion = "B"
......@@ -41,7 +41,6 @@ import Test.QuickCheck hiding (Result)
import Test.HUnit
import Control.Applicative
import Data.List (sort)
import Control.Monad (replicateM)
import Test.Ganeti.TestHelper
......@@ -51,6 +50,7 @@ import Test.Ganeti.Types (allDiskTemplates)
import Ganeti.BasicTypes
import qualified Ganeti.Constants as C
import Ganeti.ConstantUtils
import qualified Ganeti.HTools.Types as Types
{-# ANN module "HLint: ignore Use camelCase" #-}
......@@ -185,15 +185,15 @@ case_AutoRepairType_sort = do
, Types.ArFailover
, Types.ArReinstall
]
all_hs_raw = map Types.autoRepairTypeToRaw [minBound..maxBound]
all_hs_raw = mkSet $ map Types.autoRepairTypeToRaw [minBound..maxBound]
assertEqual "Haskell order" expected [minBound..maxBound]
assertEqual "consistent with Python" C.autoRepairAllTypes all_hs_raw
-- | Test 'AutoRepairResult' type is equivalent with Python codebase.
case_AutoRepairResult_pyequiv :: Assertion
case_AutoRepairResult_pyequiv = do
let all_py_results = sort C.autoRepairAllResults
all_hs_results = sort $
let all_py_results = C.autoRepairAllResults
all_hs_results = mkSet $
map Types.autoRepairResultToRaw [minBound..maxBound]
assertEqual "for AutoRepairResult equivalence" all_py_results all_hs_results
......
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