diff --git a/htest/Test/Ganeti/Jobs.hs b/htest/Test/Ganeti/Jobs.hs index b6d954678c184da20c40586e1708dc702be43270..7131581d930489c24f5000d6456d88e54ce136f0 100644 --- a/htest/Test/Ganeti/Jobs.hs +++ b/htest/Test/Ganeti/Jobs.hs @@ -1,6 +1,3 @@ -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} - {-| Unittests for ganeti-htools. -} @@ -28,29 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Test.Ganeti.Jobs (testJobs) where -import Test.QuickCheck - import Test.Ganeti.TestHelper -import Test.Ganeti.TestCommon - -import qualified Ganeti.Jobs as Jobs - --- * Arbitrary instances - -$(genArbitrary ''Jobs.OpStatus) - -$(genArbitrary ''Jobs.JobStatus) - --- * Test cases - --- | Check that (queued) job\/opcode status serialization is idempotent. -prop_OpStatus_serialization :: Jobs.OpStatus -> Property -prop_OpStatus_serialization = testSerialisation - -prop_JobStatus_serialization :: Jobs.JobStatus -> Property -prop_JobStatus_serialization = testSerialisation testSuite "Jobs" - [ 'prop_OpStatus_serialization - , 'prop_JobStatus_serialization + [ ] diff --git a/htest/Test/Ganeti/Types.hs b/htest/Test/Ganeti/Types.hs index f758456e7c0965881220553b8eb039577d57d5e1..0129a525ba77b47ed08fc3604969c2472fbe631f 100644 --- a/htest/Test/Ganeti/Types.hs +++ b/htest/Test/Ganeti/Types.hs @@ -115,6 +115,8 @@ $(genArbitrary ''NetworkType) $(genArbitrary ''NICMode) +$(genArbitrary ''JobStatus) + $(genArbitrary ''FinalizedJobStatus) instance Arbitrary JobId where @@ -128,6 +130,8 @@ $(genArbitrary ''JobDependency) $(genArbitrary ''OpSubmitPriority) +$(genArbitrary ''OpStatus) + -- * Properties prop_AllocPolicy_serialisation :: AllocPolicy -> Property @@ -287,6 +291,14 @@ case_NetworkType_pyequiv = do prop_NICMode_serialisation :: NICMode -> Property prop_NICMode_serialisation = testSerialisation +-- | Test 'OpStatus' serialisation. +prop_OpStatus_serialization :: OpStatus -> Property +prop_OpStatus_serialization = testSerialisation + +-- | Test 'JobStatus' serialisation. +prop_JobStatus_serialization :: JobStatus -> Property +prop_JobStatus_serialization = testSerialisation + -- | Tests equivalence with Python, based on Constants.hs code. case_NICMode_pyequiv :: Assertion case_NICMode_pyequiv = do @@ -352,6 +364,8 @@ testSuite "Types" , 'prop_NetworkType_serialisation , 'case_NetworkType_pyequiv , 'prop_NICMode_serialisation + , 'prop_OpStatus_serialization + , 'prop_JobStatus_serialization , 'case_NICMode_pyequiv , 'prop_FinalizedJobStatus_serialisation , 'case_FinalizedJobStatus_pyequiv diff --git a/htools/Ganeti/HTools/Program/Hbal.hs b/htools/Ganeti/HTools/Program/Hbal.hs index deea30f522c4c6dfeb00b34c154c95034a7e23ac..ca0b03707a755a13868e4032025f1728fb965c34 100644 --- a/htools/Ganeti/HTools/Program/Hbal.hs +++ b/htools/Ganeti/HTools/Program/Hbal.hs @@ -57,11 +57,10 @@ import Ganeti.HTools.ExtLoader import Ganeti.HTools.Types import Ganeti.HTools.Loader import Ganeti.OpCodes (wrapOpCode, setOpComment, OpCode, MetaOpCode) -import Ganeti.Types (fromJobId) +import Ganeti.Types import Ganeti.Utils import qualified Ganeti.Luxi as L -import Ganeti.Jobs import Ganeti.Version (version) -- | Options list and functions. diff --git a/htools/Ganeti/Jobs.hs b/htools/Ganeti/Jobs.hs index 04ac18088d32d8a2eeee19eaeb68c617e6780159..212dec69c067c8efb3606499c7281914442b67df 100644 --- a/htools/Ganeti/Jobs.hs +++ b/htools/Ganeti/Jobs.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE TemplateHaskell #-} - {-| Implementation of the job information. -} @@ -26,35 +24,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -} module Ganeti.Jobs - ( OpStatus(..) - , JobStatus(..) + ( ) where - -import qualified Ganeti.Constants as C -import qualified Ganeti.THH as THH - --- | Our ADT for the OpCode status at runtime (while in a job). -$(THH.declareSADT "OpStatus" - [ ("OP_STATUS_QUEUED", 'C.opStatusQueued) - , ("OP_STATUS_WAITING", 'C.opStatusWaiting) - , ("OP_STATUS_CANCELING", 'C.opStatusCanceling) - , ("OP_STATUS_RUNNING", 'C.opStatusRunning) - , ("OP_STATUS_CANCELED", 'C.opStatusCanceled) - , ("OP_STATUS_SUCCESS", 'C.opStatusSuccess) - , ("OP_STATUS_ERROR", 'C.opStatusError) - ]) -$(THH.makeJSONInstance ''OpStatus) - --- | The JobStatus data type. Note that this is ordered especially --- such that greater\/lesser comparison on values of this type makes --- sense. -$(THH.declareSADT "JobStatus" - [ ("JOB_STATUS_QUEUED", 'C.jobStatusQueued) - , ("JOB_STATUS_WAITING", 'C.jobStatusWaiting) - , ("JOB_STATUS_CANCELING", 'C.jobStatusCanceling) - , ("JOB_STATUS_RUNNING", 'C.jobStatusRunning) - , ("JOB_STATUS_CANCELED", 'C.jobStatusCanceled) - , ("JOB_STATUS_SUCCESS", 'C.jobStatusSuccess) - , ("JOB_STATUS_ERROR", 'C.jobStatusError) - ]) -$(THH.makeJSONInstance ''JobStatus) diff --git a/htools/Ganeti/Luxi.hs b/htools/Ganeti/Luxi.hs index a59bd9bb21522dc656748023f200c722af71ea2a..65132e017487396a71ddc6f6fb4eddd94c5f187b 100644 --- a/htools/Ganeti/Luxi.hs +++ b/htools/Ganeti/Luxi.hs @@ -72,7 +72,6 @@ import Ganeti.BasicTypes import Ganeti.Constants import Ganeti.Errors import Ganeti.JSON -import Ganeti.Jobs (JobStatus) import Ganeti.OpParams (pTagsObject) import Ganeti.OpCodes import qualified Ganeti.Query.Language as Qlang diff --git a/htools/Ganeti/Types.hs b/htools/Ganeti/Types.hs index bafc5bcc281998fcbd761e9dd68caf552cffd4af..a654b921d9976b8f770f18170bfc0f9729c5f209 100644 --- a/htools/Ganeti/Types.hs +++ b/htools/Ganeti/Types.hs @@ -74,6 +74,9 @@ module Ganeti.Types , networkTypeToRaw , NICMode(..) , nICModeToRaw + , JobStatus(..) + , jobStatusToRaw + , jobStatusFromRaw , FinalizedJobStatus(..) , finalizedJobStatusToRaw , JobId @@ -83,6 +86,9 @@ module Ganeti.Types , JobIdDep(..) , JobDependency(..) , OpSubmitPriority(..) + , OpStatus(..) + , opStatusToRaw + , opStatusFromRaw ) where import Control.Monad (liftM) @@ -363,6 +369,20 @@ $(THH.declareSADT "NICMode" ]) $(THH.makeJSONInstance ''NICMode) +-- | The JobStatus data type. Note that this is ordered especially +-- such that greater\/lesser comparison on values of this type makes +-- sense. +$(THH.declareSADT "JobStatus" + [ ("JOB_STATUS_QUEUED", 'C.jobStatusQueued) + , ("JOB_STATUS_WAITING", 'C.jobStatusWaiting) + , ("JOB_STATUS_CANCELING", 'C.jobStatusCanceling) + , ("JOB_STATUS_RUNNING", 'C.jobStatusRunning) + , ("JOB_STATUS_CANCELED", 'C.jobStatusCanceled) + , ("JOB_STATUS_SUCCESS", 'C.jobStatusSuccess) + , ("JOB_STATUS_ERROR", 'C.jobStatusError) + ]) +$(THH.makeJSONInstance ''JobStatus) + -- | Finalized job status. $(THH.declareSADT "FinalizedJobStatus" [ ("JobStatusCanceled", 'C.jobStatusCanceled) @@ -429,3 +449,15 @@ $(THH.declareIADT "OpSubmitPriority" , ("OpPrioHigh", 'C.opPrioHigh) ]) $(THH.makeJSONInstance ''OpSubmitPriority) + +-- | Our ADT for the OpCode status at runtime (while in a job). +$(THH.declareSADT "OpStatus" + [ ("OP_STATUS_QUEUED", 'C.opStatusQueued) + , ("OP_STATUS_WAITING", 'C.opStatusWaiting) + , ("OP_STATUS_CANCELING", 'C.opStatusCanceling) + , ("OP_STATUS_RUNNING", 'C.opStatusRunning) + , ("OP_STATUS_CANCELED", 'C.opStatusCanceled) + , ("OP_STATUS_SUCCESS", 'C.opStatusSuccess) + , ("OP_STATUS_ERROR", 'C.opStatusError) + ]) +$(THH.makeJSONInstance ''OpStatus)