Add a very simple test rpc program
authorIustin Pop <iustin@google.com>
Tue, 16 Oct 2012 10:56:40 +0000 (12:56 +0200)
committerIustin Pop <iustin@google.com>
Tue, 16 Oct 2012 12:14:14 +0000 (14:14 +0200)
This only supports test delay for now, is not built by default (only
on demand), and is also not installed anywhere.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

.gitignore
Makefile.am
htools/rpc-test.hs [new file with mode: 0644]

index 2902265..3d5cb0f 100644 (file)
 /htools/htools
 /htools/hconfd
 /htools/ganeti-confd
+/htools/rpc-test
 /htest/hpc-htools
 /htest/test
 /htools/*.prof*
index 77f5169..4452f42 100644 (file)
@@ -386,7 +386,13 @@ HS_PROGS = htools/htools
 HS_BIN_ROLES = hbal hscan hspace hinfo hcheck
 HS_HTOOLS_PROGS = $(HS_BIN_ROLES) hail
 
-HS_ALL_PROGS = $(HS_PROGS) htest/test htest/hpc-htools htools/hconfd
+HS_ALL_PROGS = \
+       $(HS_PROGS) \
+       htest/hpc-htools \
+       htest/test \
+       htools/hconfd \
+       htools/rpc-test
+
 HS_PROG_SRCS = $(patsubst %,%.hs,$(HS_ALL_PROGS))
 HS_BUILT_TEST_HELPERS = $(HS_BIN_ROLES:%=htest/%) htest/hail
 
diff --git a/htools/rpc-test.hs b/htools/rpc-test.hs
new file mode 100644 (file)
index 0000000..b0cad68
--- /dev/null
@@ -0,0 +1,56 @@
+{-| RPC test program.
+
+-}
+
+{-
+
+Copyright (C) 2011, 2012 Google Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.
+
+-}
+
+import System.Environment
+import System.Exit
+import System.IO
+
+import Ganeti.Config
+import Ganeti.Objects
+import qualified Ganeti.Path as P
+import Ganeti.Rpc
+import Ganeti.Utils
+
+-- | Show usage info and exit.
+usage :: IO ()
+usage = do
+  prog <- getProgName
+  hPutStrLn stderr $ "Usage: " ++ prog ++ " delay node..."
+  exitWith $ ExitFailure 1
+
+main :: IO ()
+main = do
+  args <- getArgs
+  (delay, nodes) <- case args of
+                      [] -> usage >> return ("", []) -- workaround types...
+                      _:[] -> usage >> return ("", [])
+                      x:xs -> return (x, xs)
+  cfg <- loadConfig P.clusterConfFile >>=
+         exitIfBad "Can't load configuration"
+  let call = RpcCallTestDelay (read delay)
+  nodes' <- exitIfBad "Can't find node" $ mapM (getNode cfg) nodes
+  results <- executeRpcCall nodes' call
+  putStr $ printTable "" ["Node", "Result"]
+           (map (\(n, r) -> [nodeName n, show r]) results) [False, False]