Commit 497beee2 authored by Iustin Pop's avatar Iustin Pop
Browse files

Move NICMode from Objects.hs to Types.hs



Also add some unittests for this type.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent a3f02317
......@@ -85,8 +85,6 @@ $(genArbitrary ''PartialBeParams)
$(genArbitrary ''AdminState)
$(genArbitrary ''NICMode)
$(genArbitrary ''PartialNicParams)
$(genArbitrary ''PartialNic)
......
......@@ -103,6 +103,8 @@ $(genArbitrary ''IAllocatorTestDir)
$(genArbitrary ''IAllocatorMode)
$(genArbitrary ''NICMode)
-- * Properties
prop_AllocPolicy_serialisation :: AllocPolicy -> Property
......@@ -231,6 +233,17 @@ case_IAllocatorMode_pyequiv = do
all_hs_codes = sort $ map Types.iAllocatorModeToRaw [minBound..maxBound]
assertEqual "for IAllocatorMode equivalence" all_py_codes all_hs_codes
-- | Test 'NICMode' serialisation.
prop_NICMode_serialisation :: NICMode -> Property
prop_NICMode_serialisation = testSerialisation
-- | Tests equivalence with Python, based on Constants.hs code.
case_NICMode_pyequiv :: Assertion
case_NICMode_pyequiv = do
let all_py_codes = sort C.nicValidModes
all_hs_codes = sort $ map Types.nICModeToRaw [minBound..maxBound]
assertEqual "for NICMode equivalence" all_py_codes all_hs_codes
testSuite "Types"
[ 'prop_AllocPolicy_serialisation
, 'prop_DiskTemplate_serialisation
......@@ -258,4 +271,6 @@ testSuite "Types"
, 'prop_IAllocatorTestDir_serialisation
, 'prop_IAllocatorMode_serialisation
, 'case_IAllocatorMode_pyequiv
, 'prop_NICMode_serialisation
, 'case_NICMode_pyequiv
]
......@@ -33,7 +33,6 @@ module Ganeti.Objects
, vTypeFromRaw
, HvParams
, OsParams
, NICMode(..)
, PartialNicParams(..)
, FilledNicParams(..)
, fillNicParams
......@@ -168,12 +167,6 @@ roleDescription NRMaster = "master"
-- * NIC definitions
$(declareSADT "NICMode"
[ ("NMBridged", 'C.nicModeBridged)
, ("NMRouted", 'C.nicModeRouted)
])
$(makeJSONInstance ''NICMode)
$(buildParam "Nic" "nicp"
[ simpleField "mode" [t| NICMode |]
, simpleField "link" [t| String |]
......
......@@ -67,6 +67,8 @@ module Ganeti.Types
, IAllocatorTestDir(..)
, IAllocatorMode(..)
, iAllocatorModeToRaw
, NICMode(..)
, nICModeToRaw
) where
import qualified Text.JSON as JSON
......@@ -314,3 +316,10 @@ $(THH.declareSADT "IAllocatorMode"
, ("IAllocatorChangeGroup", 'C.iallocatorModeChgGroup)
])
$(THH.makeJSONInstance ''IAllocatorMode)
-- | Netork mode.
$(THH.declareSADT "NICMode"
[ ("NMBridged", 'C.nicModeBridged)
, ("NMRouted", 'C.nicModeRouted)
])
$(THH.makeJSONInstance ''NICMode)
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