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

Remove JOB_STATUS_GONE and add unittests

… for the serialization/deserialization of the job and opcode status.

Job status 'gone' was not actually used. It can be reintroduced if
needed.
parent 41065165
......@@ -30,6 +30,7 @@ module Ganeti.HTools.QC
, testNode
, testText
, testOpCodes
, testJobs
, testCluster
, testLoader
) where
......@@ -43,6 +44,7 @@ import qualified Text.JSON as J
import qualified Data.Map
import qualified Data.IntMap as IntMap
import qualified Ganeti.OpCodes as OpCodes
import qualified Ganeti.Jobs as Jobs
import qualified Ganeti.HTools.CLI as CLI
import qualified Ganeti.HTools.Cluster as Cluster
import qualified Ganeti.HTools.Container as Container
......@@ -176,6 +178,12 @@ instance Arbitrary OpCodes.OpCode where
liftM3 OpCodes.OpMigrateInstance arbitrary arbitrary arbitrary
_ -> fail "Wrong opcode")
instance Arbitrary Jobs.OpStatus where
arbitrary = elements [minBound..maxBound]
instance Arbitrary Jobs.JobStatus where
arbitrary = elements [minBound..maxBound]
-- * Actual tests
-- | Make sure add is idempotent
......@@ -659,6 +667,24 @@ testOpCodes =
[ run prop_OpCodes_serialization
]
-- | Check that (queued) job/opcode status serialization is idempotent
prop_OpStatus_serialization os =
case J.readJSON (J.showJSON os) of
J.Error _ -> False
J.Ok os' -> os == os'
where _types = os::Jobs.OpStatus
prop_JobStatus_serialization js =
case J.readJSON (J.showJSON js) of
J.Error _ -> False
J.Ok js' -> js == js'
where _types = js::Jobs.JobStatus
testJobs =
[ run prop_OpStatus_serialization
, run prop_JobStatus_serialization
]
-- | Loader tests
prop_Loader_lookupNode ktn inst node =
......
......@@ -70,7 +70,6 @@ data JobStatus = JOB_STATUS_QUEUED
| JOB_STATUS_CANCELING
| JOB_STATUS_CANCELED
| JOB_STATUS_ERROR
| JOB_STATUS_GONE
deriving (Eq, Enum, Ord, Bounded, Show)
instance JSON JobStatus where
......@@ -83,7 +82,6 @@ instance JSON JobStatus where
JOB_STATUS_CANCELED -> "canceled"
JOB_STATUS_SUCCESS -> "success"
JOB_STATUS_ERROR -> "error"
JOB_STATUS_GONE -> "gone" -- Fake status
readJSON s = case readJSON s of
J.Ok "queued" -> J.Ok JOB_STATUS_QUEUED
J.Ok "waiting" -> J.Ok JOB_STATUS_WAITLOCK
......
......@@ -70,6 +70,7 @@ allTests =
, ("Node", fast, testNode)
, ("Text", fast, testText)
, ("OpCodes", fast, testOpCodes)
, ("Jobs", fast, testJobs)
, ("Loader", fast, testLoader)
, ("Cluster", slow, testCluster)
]
......
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