Prevent silent failure in case of connection problems
authorMichele Tartara <mtartara@google.com>
Tue, 9 Jul 2013 13:06:36 +0000 (15:06 +0200)
committerMichele Tartara <mtartara@google.com>
Tue, 9 Jul 2013 14:22:56 +0000 (14:22 +0000)
While running "gnt-node list", if a query to ConfD fails (especially
because of permission problems) it used to just fail silently, with gnt-node
showing question marks instead of data.

With this patch, ConfD records the error in its log file, together with a
message giving an indication of the reason.

Fixes Issue 517.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

src/Ganeti/Query/Node.hs

index 293ceb7..36b5000 100644 (file)
@@ -36,6 +36,7 @@ import qualified Data.Map as Map
 import qualified Text.JSON as J
 
 import Ganeti.Config
+import Ganeti.Logging
 import Ganeti.Objects
 import Ganeti.JSON
 import Ganeti.Rpc
@@ -214,6 +215,15 @@ fieldsMap :: FieldMap Node Runtime
 fieldsMap =
   Map.fromList $ map (\v@(f, _, _) -> (fdefName f, v)) nodeFields
 
+-- | Scan the list of results produced by executeRpcCall and log all the RPC
+-- errors.
+logRpcErrors :: [(Node, Runtime)] -> IO ()
+logRpcErrors allElems =
+  let logOneRpcErr (_, Right _) = return ()
+      logOneRpcErr (_, Left err) =
+        logError $ "Error in the RPC HTTP reply: " ++ show err
+  in mapM_ logOneRpcErr allElems
+
 -- | Collect live data from RPC query if enabled.
 --
 -- FIXME: Check which fields we actually need and possibly send empty
@@ -233,6 +243,7 @@ collectLiveData True cfg nodes = do
              Nothing -> (n : bn, gn, em)
       (bnodes, gnodes, emap) = foldr step ([], [], []) nodes
   rpcres <- executeRpcCall gnodes (RpcCallNodeInfo vgs hvs (Map.fromList emap))
+  logRpcErrors rpcres
   -- FIXME: The order of nodes in the result could be different from the input
   return $ zip bnodes (repeat $ Left (RpcResultError "Broken configuration"))
            ++ rpcres