Revision 3e77a36c

b/lib/constants.py
2280 2280
# Regex string for verifying a UUID
2281 2281
UUID_REGEX = "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"
2282 2282

  
2283
# Auto-repair tag prefixes
2284
AUTO_REPAIR_TAG_PREFIX = "ganeti:watcher:autorepair:"
2285
AUTO_REPAIR_TAG_ENABLED = AUTO_REPAIR_TAG_PREFIX
2286
AUTO_REPAIR_TAG_SUSPENDED = AUTO_REPAIR_TAG_ENABLED + "suspend:"
2287
AUTO_REPAIR_TAG_PENDING = AUTO_REPAIR_TAG_PREFIX + "pending:"
2288
AUTO_REPAIR_TAG_RESULT = AUTO_REPAIR_TAG_PREFIX + "result:"
2289

  
2290
# Auto-repair levels
2291
AUTO_REPAIR_FIX_STORAGE = "fix-storage"
2292
AUTO_REPAIR_MIGRATE = "migrate"
2293
AUTO_REPAIR_FAILOVER = "failover"
2294
AUTO_REPAIR_REINSTALL = "reinstall"
2295
AUTO_REPAIR_ALL_TYPES = [
2296
  AUTO_REPAIR_FIX_STORAGE,
2297
  AUTO_REPAIR_MIGRATE,
2298
  AUTO_REPAIR_FAILOVER,
2299
  AUTO_REPAIR_REINSTALL,
2300
]
2301

  
2302
# Auto-repair results
2303
AUTO_REPAIR_SUCCESS = "success"
2304
AUTO_REPAIR_FAILURE = "failure"
2305
AUTO_REPAIR_ENOPERM = "enoperm"
2306
AUTO_REPAIR_ALL_RESULTS = frozenset([
2307
    AUTO_REPAIR_SUCCESS,
2308
    AUTO_REPAIR_FAILURE,
2309
    AUTO_REPAIR_ENOPERM,
2310
])
2311

  
2283 2312
# Do not re-export imported modules
2284 2313
del re, _vcsversion, _autoconf, socket, pathutils, compat
b/src/Ganeti/HTools/Types.hs
72 72
  , IPolicy(..)
73 73
  , defIPolicy
74 74
  , rspecFromISpec
75
  , AutoRepairType(..)
76
  , autoRepairTypeToRaw
77
  , autoRepairTypeFromRaw
78
  , AutoRepairResult(..)
79
  , autoRepairResultToRaw
80
  , autoRepairResultFromRaw
75 81
  ) where
76 82

  
77 83
import qualified Data.Map as M
......
347 353
       , ("ChangeAll",       'C.iallocatorNevacAll)
348 354
       ])
349 355
$(THH.makeJSONInstance ''EvacMode)
356

  
357
-- | The repair modes for the auto-repair tool.
358
$(THH.declareSADT "AutoRepairType"
359
       -- Order is important here: from least destructive to most.
360
       [ ("ArFixStorage", 'C.autoRepairFixStorage)
361
       , ("ArMigrate",    'C.autoRepairMigrate)
362
       , ("ArFailover",   'C.autoRepairFailover)
363
       , ("ArReinstall",  'C.autoRepairReinstall)
364
       ])
365

  
366
-- | The possible auto-repair results.
367
$(THH.declareSADT "AutoRepairResult"
368
       [ ("ArSuccess", 'C.autoRepairSuccess)
369
       , ("ArFailure", 'C.autoRepairFailure)
370
       , ("ArEnoperm", 'C.autoRepairEnoperm)
371
       ])
b/test/hs/Test/Ganeti/HTools/Types.hs
38 38
  ) where
39 39

  
40 40
import Test.QuickCheck hiding (Result)
41
import Test.HUnit
41 42

  
42 43
import Control.Applicative
44
import Data.List (sort)
43 45

  
44 46
import Test.Ganeti.TestHelper
45 47
import Test.Ganeti.TestCommon
......
47 49
import Test.Ganeti.Types ()
48 50

  
49 51
import Ganeti.BasicTypes
52
import qualified Ganeti.Constants as C
50 53
import qualified Ganeti.HTools.Types as Types
51 54

  
52 55
-- * Helpers
......
146 149
                 Ok v' -> v == v'
147 150
    where r = eitherToResult ei
148 151

  
152
-- | Test 'AutoRepairType' ordering is as expected and consistent with Python
153
-- codebase.
154
case_AutoRepairType_sort :: Assertion
155
case_AutoRepairType_sort = do
156
  let expected = [ Types.ArFixStorage
157
                 , Types.ArMigrate
158
                 , Types.ArFailover
159
                 , Types.ArReinstall
160
                 ]
161
      all_hs_raw = map Types.autoRepairTypeToRaw [minBound..maxBound]
162
  assertEqual "Haskell order" expected [minBound..maxBound]
163
  assertEqual "consistent with Python" C.autoRepairAllTypes all_hs_raw
164

  
165
-- | Test 'AutoRepairResult' type is equivalent with Python codebase.
166
case_AutoRepairResult_pyequiv :: Assertion
167
case_AutoRepairResult_pyequiv = do
168
  let all_py_results = sort C.autoRepairAllResults
169
      all_hs_results = sort $
170
                       map Types.autoRepairResultToRaw [minBound..maxBound]
171
  assertEqual "for AutoRepairResult equivalence" all_py_results all_hs_results
172

  
149 173
testSuite "HTools/Types"
150 174
            [ 'prop_ISpec_serialisation
151 175
            , 'prop_IPolicy_serialisation
152 176
            , 'prop_EvacMode_serialisation
153 177
            , 'prop_opToResult
154 178
            , 'prop_eitherToResult
179
            , 'case_AutoRepairType_sort
180
            , 'case_AutoRepairResult_pyequiv
155 181
            ]

Also available in: Unified diff