Revision b9e12624 test/hs/Test/Ganeti/Rpc.hs
b/test/hs/Test/Ganeti/Rpc.hs | ||
---|---|---|
36 | 36 |
|
37 | 37 |
import Test.Ganeti.TestHelper |
38 | 38 |
import Test.Ganeti.TestCommon |
39 |
import Test.Ganeti.Objects () |
|
39 |
import Test.Ganeti.Objects (genInst)
|
|
40 | 40 |
|
41 | 41 |
import qualified Ganeti.Rpc as Rpc |
42 | 42 |
import qualified Ganeti.Objects as Objects |
... | ... | |
44 | 44 |
import qualified Ganeti.JSON as JSON |
45 | 45 |
import Ganeti.Types |
46 | 46 |
|
47 |
instance Arbitrary Rpc.RpcCallInstanceConsoleInfo where |
|
48 |
arbitrary = Rpc.RpcCallInstanceConsoleInfo <$> genConsoleInfoCallParams |
|
49 |
|
|
47 | 50 |
genStorageUnit :: Gen StorageUnit |
48 | 51 |
genStorageUnit = do |
49 | 52 |
storage_type <- arbitrary |
... | ... | |
86 | 89 |
instance Arbitrary Rpc.RpcCallNodeInfo where |
87 | 90 |
arbitrary = Rpc.RpcCallNodeInfo <$> genStorageUnitMap <*> genHvSpecs |
88 | 91 |
|
89 |
-- | Monadic check that, for an offline node and a call that does not |
|
92 |
-- | Generates per-instance console info params for the 'InstanceConsoleInfo' |
|
93 |
-- call. |
|
94 |
genConsoleInfoCallParams :: Gen [(String, Rpc.InstanceConsoleInfoParams)] |
|
95 |
genConsoleInfoCallParams = do |
|
96 |
numInstances <- choose (0, 3) |
|
97 |
names <- vectorOf numInstances arbitrary |
|
98 |
params <- vectorOf numInstances genInstanceConsoleInfoParams |
|
99 |
return $ zip names params |
|
100 |
|
|
101 |
-- | Generates parameters for the console info call, consisting of an instance |
|
102 |
-- object, node object, 'HvParams', and 'FilledBeParams'. |
|
103 |
genInstanceConsoleInfoParams :: Gen Rpc.InstanceConsoleInfoParams |
|
104 |
genInstanceConsoleInfoParams = Rpc.InstanceConsoleInfoParams <$> |
|
105 |
genInst <*> arbitrary <*> genHvParams <*> arbitrary |
|
106 |
|
|
107 |
-- | Monadic check that, for an offline node and a call that does not support |
|
90 | 108 |
-- offline nodes, we get a OfflineNodeError response. |
91 |
-- FIXME: We need a way of generalizing this, running it for |
|
92 |
-- every call manually will soon get problematic |
|
93 |
prop_noffl_request_allinstinfo :: Rpc.RpcCallAllInstancesInfo -> Property |
|
94 |
prop_noffl_request_allinstinfo call = |
|
109 |
runOfflineTest :: (Rpc.Rpc a b, Eq b, Show b) => a -> Property |
|
110 |
runOfflineTest call = |
|
95 | 111 |
forAll (arbitrary `suchThat` Objects.nodeOffline) $ \node -> monadicIO $ do |
96 | 112 |
res <- run $ Rpc.executeRpcCall [node] call |
97 | 113 |
stop $ res ==? [(node, Left Rpc.OfflineNodeError)] |
98 | 114 |
|
115 |
prop_noffl_request_allinstinfo :: Rpc.RpcCallAllInstancesInfo -> Property |
|
116 |
prop_noffl_request_allinstinfo = runOfflineTest |
|
117 |
|
|
118 |
prop_noffl_request_instconsinfo :: Rpc.RpcCallInstanceConsoleInfo -> Property |
|
119 |
prop_noffl_request_instconsinfo = runOfflineTest |
|
120 |
|
|
99 | 121 |
prop_noffl_request_instlist :: Rpc.RpcCallInstanceList -> Property |
100 |
prop_noffl_request_instlist call = |
|
101 |
forAll (arbitrary `suchThat` Objects.nodeOffline) $ \node -> monadicIO $ do |
|
102 |
res <- run $ Rpc.executeRpcCall [node] call |
|
103 |
stop $ res ==? [(node, Left Rpc.OfflineNodeError)] |
|
122 |
prop_noffl_request_instlist = runOfflineTest |
|
104 | 123 |
|
105 | 124 |
prop_noffl_request_nodeinfo :: Rpc.RpcCallNodeInfo -> Property |
106 |
prop_noffl_request_nodeinfo call = |
|
107 |
forAll (arbitrary `suchThat` Objects.nodeOffline) $ \node -> monadicIO $ do |
|
108 |
res <- run $ Rpc.executeRpcCall [node] call |
|
109 |
stop $ res ==? [(node, Left Rpc.OfflineNodeError)] |
|
125 |
prop_noffl_request_nodeinfo = runOfflineTest |
|
110 | 126 |
|
111 | 127 |
testSuite "Rpc" |
112 | 128 |
[ 'prop_noffl_request_allinstinfo |
129 |
, 'prop_noffl_request_instconsinfo |
|
113 | 130 |
, 'prop_noffl_request_instlist |
114 | 131 |
, 'prop_noffl_request_nodeinfo |
115 | 132 |
] |
Also available in: Unified diff