1 {-# LANGUAGE TemplateHaskell #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 {-| Unittests for ganeti-htools.
10 Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 module Test.Ganeti.Rpc (testRpc) where
31 import Test.QuickCheck
32 import Test.QuickCheck.Monadic (monadicIO, run, stop)
34 import Control.Applicative
35 import qualified Data.Map as Map
37 import Test.Ganeti.TestHelper
38 import Test.Ganeti.TestCommon
39 import Test.Ganeti.Objects ()
41 import qualified Ganeti.Rpc as Rpc
42 import qualified Ganeti.Objects as Objects
44 instance Arbitrary Rpc.RpcCallAllInstancesInfo where
45 arbitrary = Rpc.RpcCallAllInstancesInfo <$> arbitrary
47 instance Arbitrary Rpc.RpcCallInstanceList where
48 arbitrary = Rpc.RpcCallInstanceList <$> arbitrary
50 instance Arbitrary Rpc.RpcCallNodeInfo where
51 arbitrary = Rpc.RpcCallNodeInfo <$> arbitrary <*> arbitrary <*>
54 -- | Monadic check that, for an offline node and a call that does not
55 -- offline nodes, we get a OfflineNodeError response.
56 -- FIXME: We need a way of generalizing this, running it for
57 -- every call manually will soon get problematic
58 prop_noffl_request_allinstinfo :: Rpc.RpcCallAllInstancesInfo -> Property
59 prop_noffl_request_allinstinfo call =
60 forAll (arbitrary `suchThat` Objects.nodeOffline) $ \node -> monadicIO $ do
61 res <- run $ Rpc.executeRpcCall [node] call
62 stop $ res ==? [(node, Left (Rpc.OfflineNodeError node))]
64 prop_noffl_request_instlist :: Rpc.RpcCallInstanceList -> Property
65 prop_noffl_request_instlist call =
66 forAll (arbitrary `suchThat` Objects.nodeOffline) $ \node -> monadicIO $ do
67 res <- run $ Rpc.executeRpcCall [node] call
68 stop $ res ==? [(node, Left (Rpc.OfflineNodeError node))]
70 prop_noffl_request_nodeinfo :: Rpc.RpcCallNodeInfo -> Property
71 prop_noffl_request_nodeinfo call =
72 forAll (arbitrary `suchThat` Objects.nodeOffline) $ \node -> monadicIO $ do
73 res <- run $ Rpc.executeRpcCall [node] call
74 stop $ res ==? [(node, Left (Rpc.OfflineNodeError node))]
77 [ 'prop_noffl_request_allinstinfo
78 , 'prop_noffl_request_instlist
79 , 'prop_noffl_request_nodeinfo