Commit d696bbef authored by Iustin Pop's avatar Iustin Pop
Browse files

Add more basic Ganeti types



These are needed both in opcodes and (potentially) outside, so we add
them in the main Types module.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 405bffe2
......@@ -34,6 +34,7 @@ module Test.Ganeti.Types
, NonEmpty(..)
) where
import Data.List (sort)
import Test.QuickCheck as QuickCheck hiding (Result)
import Test.HUnit
......@@ -41,6 +42,7 @@ import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
import Ganeti.BasicTypes
import qualified Ganeti.Constants as C
import Ganeti.Types as Types
{-# ANN module "HLint: ignore Use camelCase" #-}
......@@ -59,11 +61,21 @@ $(genArbitrary ''DiskTemplate)
$(genArbitrary ''InstanceStatus)
$(genArbitrary ''MigrationMode)
$(genArbitrary ''VerifyOptionalChecks)
$(genArbitrary ''DdmSimple)
$(genArbitrary ''CVErrorCode)
instance (Arbitrary a) => Arbitrary (Types.NonEmpty a) where
arbitrary = do
QuickCheck.NonEmpty lst <- arbitrary
Types.mkNonEmpty lst
-- * Properties
prop_AllocPolicy_serialisation :: AllocPolicy -> Property
prop_AllocPolicy_serialisation = testSerialisation
......@@ -116,6 +128,29 @@ case_NonEmpty_fail =
assertEqual "building non-empty list from an empty list"
(Bad "Received empty value for non-empty list") (mkNonEmpty ([]::[Int]))
-- | Tests migration mode serialisation.
prop_MigrationMode_serialisation :: MigrationMode -> Property
prop_MigrationMode_serialisation = testSerialisation
-- | Tests verify optional checks serialisation.
prop_VerifyOptionalChecks_serialisation :: VerifyOptionalChecks -> Property
prop_VerifyOptionalChecks_serialisation = testSerialisation
-- | Tests 'DdmSimple' serialisation.
prop_DdmSimple_serialisation :: DdmSimple -> Property
prop_DdmSimple_serialisation = testSerialisation
-- | Tests 'CVErrorCode' serialisation.
prop_CVErrorCode_serialisation :: CVErrorCode -> Property
prop_CVErrorCode_serialisation = testSerialisation
-- | Tests equivalence with Python, based on Constants.hs code.
case_CVErrorCode_pyequiv :: Assertion
case_CVErrorCode_pyequiv = do
let all_py_codes = sort C.cvAllEcodesStrings
all_hs_codes = sort $ map Types.cVErrorCodeToRaw [minBound..maxBound]
assertEqual "for CVErrorCode equivalence" all_py_codes all_hs_codes
testSuite "Types"
[ 'prop_AllocPolicy_serialisation
, 'prop_DiskTemplate_serialisation
......@@ -126,4 +161,9 @@ testSuite "Types"
, 'prop_Positive_fail
, 'prop_NonEmpty_pass
, 'case_NonEmpty_fail
, 'prop_MigrationMode_serialisation
, 'prop_VerifyOptionalChecks_serialisation
, 'prop_DdmSimple_serialisation
, 'prop_CVErrorCode_serialisation
, 'case_CVErrorCode_pyequiv
]
......@@ -49,6 +49,11 @@ module Ganeti.Types
, NonEmpty
, fromNonEmpty
, mkNonEmpty
, MigrationMode(..)
, VerifyOptionalChecks(..)
, DdmSimple(..)
, CVErrorCode(..)
, cVErrorCodeToRaw
) where
import qualified Text.JSON as JSON
......@@ -139,3 +144,60 @@ $(THH.declareSADT "InstanceStatus"
, ("WrongNode", 'C.inststWrongnode)
])
$(THH.makeJSONInstance ''InstanceStatus)
-- | Migration mode.
$(THH.declareSADT "MigrationMode"
[ ("MigrationLive", 'C.htMigrationLive)
, ("MigrationNonLive", 'C.htMigrationNonlive)
])
$(THH.makeJSONInstance ''MigrationMode)
-- | Verify optional checks.
$(THH.declareSADT "VerifyOptionalChecks"
[ ("VerifyNPlusOneMem", 'C.verifyNplusoneMem)
])
$(THH.makeJSONInstance ''VerifyOptionalChecks)
-- | Cluster verify error codes.
$(THH.declareSADT "CVErrorCode"
[ ("CvECLUSTERCFG", 'C.cvEclustercfgCode)
, ("CvECLUSTERCERT", 'C.cvEclustercertCode)
, ("CvECLUSTERFILECHECK", 'C.cvEclusterfilecheckCode)
, ("CvECLUSTERDANGLINGNODES", 'C.cvEclusterdanglingnodesCode)
, ("CvECLUSTERDANGLINGINST", 'C.cvEclusterdanglinginstCode)
, ("CvEINSTANCEBADNODE", 'C.cvEinstancebadnodeCode)
, ("CvEINSTANCEDOWN", 'C.cvEinstancedownCode)
, ("CvEINSTANCELAYOUT", 'C.cvEinstancelayoutCode)
, ("CvEINSTANCEMISSINGDISK", 'C.cvEinstancemissingdiskCode)
, ("CvEINSTANCEFAULTYDISK", 'C.cvEinstancefaultydiskCode)
, ("CvEINSTANCEWRONGNODE", 'C.cvEinstancewrongnodeCode)
, ("CvEINSTANCESPLITGROUPS", 'C.cvEinstancesplitgroupsCode)
, ("CvEINSTANCEPOLICY", 'C.cvEinstancepolicyCode)
, ("CvENODEDRBD", 'C.cvEnodedrbdCode)
, ("CvENODEDRBDHELPER", 'C.cvEnodedrbdhelperCode)
, ("CvENODEFILECHECK", 'C.cvEnodefilecheckCode)
, ("CvENODEHOOKS", 'C.cvEnodehooksCode)
, ("CvENODEHV", 'C.cvEnodehvCode)
, ("CvENODELVM", 'C.cvEnodelvmCode)
, ("CvENODEN1", 'C.cvEnoden1Code)
, ("CvENODENET", 'C.cvEnodenetCode)
, ("CvENODEOS", 'C.cvEnodeosCode)
, ("CvENODEORPHANINSTANCE", 'C.cvEnodeorphaninstanceCode)
, ("CvENODEORPHANLV", 'C.cvEnodeorphanlvCode)
, ("CvENODERPC", 'C.cvEnoderpcCode)
, ("CvENODESSH", 'C.cvEnodesshCode)
, ("CvENODEVERSION", 'C.cvEnodeversionCode)
, ("CvENODESETUP", 'C.cvEnodesetupCode)
, ("CvENODETIME", 'C.cvEnodetimeCode)
, ("CvENODEOOBPATH", 'C.cvEnodeoobpathCode)
, ("CvENODEUSERSCRIPTS", 'C.cvEnodeuserscriptsCode)
, ("CvENODEFILESTORAGEPATHS", 'C.cvEnodefilestoragepathsCode)
])
$(THH.makeJSONInstance ''CVErrorCode)
-- | Dynamic device modification, just add\/remove version.
$(THH.declareSADT "DdmSimple"
[ ("DdmSimpleAdd", 'C.ddmAdd)
, ("DdmSimpleRemove", 'C.ddmRemove)
])
$(THH.makeJSONInstance ''DdmSimple)
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