Add initial constants and Haskell ADTs for auto repair
authorDato Simó <dato@google.com>
Fri, 16 Nov 2012 22:16:10 +0000 (22:16 +0000)
committerDato Simó <dato@google.com>
Mon, 14 Jan 2013 15:52:09 +0000 (15:52 +0000)
In this commit, the AutoRepairType and AutoRepairResult types are defined,
with the possible values specified in doc/design-autorepair.rst.

Signed-off-by: Dato Simó <dato@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/constants.py
src/Ganeti/HTools/Types.hs
test/hs/Test/Ganeti/HTools/Types.hs

index 508d608..b24c055 100644 (file)
@@ -2280,5 +2280,34 @@ RANDOM_UUID_FILE = "/proc/sys/kernel/random/uuid"
 # Regex string for verifying a UUID
 UUID_REGEX = "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"
 
+# Auto-repair tag prefixes
+AUTO_REPAIR_TAG_PREFIX = "ganeti:watcher:autorepair:"
+AUTO_REPAIR_TAG_ENABLED = AUTO_REPAIR_TAG_PREFIX
+AUTO_REPAIR_TAG_SUSPENDED = AUTO_REPAIR_TAG_ENABLED + "suspend:"
+AUTO_REPAIR_TAG_PENDING = AUTO_REPAIR_TAG_PREFIX + "pending:"
+AUTO_REPAIR_TAG_RESULT = AUTO_REPAIR_TAG_PREFIX + "result:"
+
+# Auto-repair levels
+AUTO_REPAIR_FIX_STORAGE = "fix-storage"
+AUTO_REPAIR_MIGRATE = "migrate"
+AUTO_REPAIR_FAILOVER = "failover"
+AUTO_REPAIR_REINSTALL = "reinstall"
+AUTO_REPAIR_ALL_TYPES = [
+  AUTO_REPAIR_FIX_STORAGE,
+  AUTO_REPAIR_MIGRATE,
+  AUTO_REPAIR_FAILOVER,
+  AUTO_REPAIR_REINSTALL,
+]
+
+# Auto-repair results
+AUTO_REPAIR_SUCCESS = "success"
+AUTO_REPAIR_FAILURE = "failure"
+AUTO_REPAIR_ENOPERM = "enoperm"
+AUTO_REPAIR_ALL_RESULTS = frozenset([
+    AUTO_REPAIR_SUCCESS,
+    AUTO_REPAIR_FAILURE,
+    AUTO_REPAIR_ENOPERM,
+])
+
 # Do not re-export imported modules
 del re, _vcsversion, _autoconf, socket, pathutils, compat
index 160473b..b006dde 100644 (file)
@@ -72,6 +72,12 @@ module Ganeti.HTools.Types
   , IPolicy(..)
   , defIPolicy
   , rspecFromISpec
+  , AutoRepairType(..)
+  , autoRepairTypeToRaw
+  , autoRepairTypeFromRaw
+  , AutoRepairResult(..)
+  , autoRepairResultToRaw
+  , autoRepairResultFromRaw
   ) where
 
 import qualified Data.Map as M
@@ -347,3 +353,19 @@ $(THH.declareSADT "EvacMode"
        , ("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.
+       [ ("ArFixStorage", 'C.autoRepairFixStorage)
+       , ("ArMigrate",    'C.autoRepairMigrate)
+       , ("ArFailover",   'C.autoRepairFailover)
+       , ("ArReinstall",  'C.autoRepairReinstall)
+       ])
+
+-- | The possible auto-repair results.
+$(THH.declareSADT "AutoRepairResult"
+       [ ("ArSuccess", 'C.autoRepairSuccess)
+       , ("ArFailure", 'C.autoRepairFailure)
+       , ("ArEnoperm", 'C.autoRepairEnoperm)
+       ])
index 5dbcbe7..7c12c41 100644 (file)
@@ -38,8 +38,10 @@ module Test.Ganeti.HTools.Types
   ) where
 
 import Test.QuickCheck hiding (Result)
+import Test.HUnit
 
 import Control.Applicative
+import Data.List (sort)
 
 import Test.Ganeti.TestHelper
 import Test.Ganeti.TestCommon
@@ -47,6 +49,7 @@ import Test.Ganeti.TestHTools
 import Test.Ganeti.Types ()
 
 import Ganeti.BasicTypes
+import qualified Ganeti.Constants as C
 import qualified Ganeti.HTools.Types as Types
 
 -- * Helpers
@@ -146,10 +149,33 @@ prop_eitherToResult ei =
                  Ok v' -> v == v'
     where r = eitherToResult ei
 
+-- | Test 'AutoRepairType' ordering is as expected and consistent with Python
+-- codebase.
+case_AutoRepairType_sort :: Assertion
+case_AutoRepairType_sort = do
+  let expected = [ Types.ArFixStorage
+                 , Types.ArMigrate
+                 , Types.ArFailover
+                 , Types.ArReinstall
+                 ]
+      all_hs_raw = 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 $
+                       map Types.autoRepairResultToRaw [minBound..maxBound]
+  assertEqual "for AutoRepairResult equivalence" all_py_results all_hs_results
+
 testSuite "HTools/Types"
             [ 'prop_ISpec_serialisation
             , 'prop_IPolicy_serialisation
             , 'prop_EvacMode_serialisation
             , 'prop_opToResult
             , 'prop_eitherToResult
+            , 'case_AutoRepairType_sort
+            , 'case_AutoRepairResult_pyequiv
             ]