From 4cd79ca8e8ab1e46a6d891e6a567cd819a8936b9 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Fri, 5 Oct 2012 02:01:22 +0100
Subject: [PATCH] Cleanup network timeouts and htools imports

This patch removes the last HTools module imports from non-htools code
(the HTools.Types module), but it requires an associated cleanup:
using luxi-specific constants for luxi timeouts (the only effect is
that one timeout decreases from 15 to 10, the default value in the
python code), and moving of the (now) RAPI specific constants to
RAPI.hs (which allows simplifying their type/usage).

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 htools/Ganeti/Confd/Server.hs |  2 +-
 htools/Ganeti/HTools/Rapi.hs  | 12 ++++++++++--
 htools/Ganeti/HTools/Types.hs | 10 ----------
 htools/Ganeti/Luxi.hs         |  8 ++++----
 4 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/htools/Ganeti/Confd/Server.hs b/htools/Ganeti/Confd/Server.hs
index 5644f115a..e2aa6a5e9 100644
--- a/htools/Ganeti/Confd/Server.hs
+++ b/htools/Ganeti/Confd/Server.hs
@@ -44,9 +44,9 @@ import System.Time
 import qualified Text.JSON as J
 import System.INotify
 
+import Ganeti.BasicTypes
 import Ganeti.Daemon
 import Ganeti.JSON
-import Ganeti.HTools.Types
 import Ganeti.Objects
 import Ganeti.Confd
 import Ganeti.Confd.Utils
diff --git a/htools/Ganeti/HTools/Rapi.hs b/htools/Ganeti/HTools/Rapi.hs
index 6f1a9fb9f..b7a737047 100644
--- a/htools/Ganeti/HTools/Rapi.hs
+++ b/htools/Ganeti/HTools/Rapi.hs
@@ -66,12 +66,20 @@ getUrl _ = return $ fail "RAPI/curl backend disabled at compile time"
 
 #else
 
+-- | Connection timeout (when using non-file methods).
+connTimeout :: Long
+connTimeout = 15
+
+-- | The default timeout for queries (when using non-file methods).
+queryTimeout :: Long
+queryTimeout = 60
+
 -- | The curl options we use.
 curlOpts :: [CurlOption]
 curlOpts = [ CurlSSLVerifyPeer False
            , CurlSSLVerifyHost 0
-           , CurlTimeout (fromIntegral queryTimeout)
-           , CurlConnectTimeout (fromIntegral connTimeout)
+           , CurlTimeout queryTimeout
+           , CurlConnectTimeout connTimeout
            ]
 
 getUrl url = do
diff --git a/htools/Ganeti/HTools/Types.hs b/htools/Ganeti/HTools/Types.hs
index 31b3d704c..fb8391054 100644
--- a/htools/Ganeti/HTools/Types.hs
+++ b/htools/Ganeti/HTools/Types.hs
@@ -72,8 +72,6 @@ module Ganeti.HTools.Types
   , FailStats
   , OpResult(..)
   , opToResult
-  , connTimeout
-  , queryTimeout
   , EvacMode(..)
   , ISpec(..)
   , IPolicy(..)
@@ -319,14 +317,6 @@ unknownField = "<unknown field>"
 -- | A list of command elements.
 type JobSet = [MoveJob]
 
--- | Connection timeout (when using non-file methods).
-connTimeout :: Int
-connTimeout = 15
-
--- | The default timeout for queries (when using non-file methods).
-queryTimeout :: Int
-queryTimeout = 60
-
 -- | Default max disk usage ratio.
 defReservedDiskRatio :: Double
 defReservedDiskRatio = 0
diff --git a/htools/Ganeti/Luxi.hs b/htools/Ganeti/Luxi.hs
index 12dc6ed2b..2086a0eef 100644
--- a/htools/Ganeti/Luxi.hs
+++ b/htools/Ganeti/Luxi.hs
@@ -67,8 +67,8 @@ import System.IO.Error (isEOFError)
 import System.Timeout
 import qualified Network.Socket as S
 
+import Ganeti.BasicTypes
 import Ganeti.JSON
-import Ganeti.HTools.Types
 import Ganeti.Utils
 
 import Ganeti.Constants
@@ -214,7 +214,7 @@ data Client = Client { socket :: Handle           -- ^ The socket of the client
 getClient :: String -> IO Client
 getClient path = do
   s <- S.socket S.AF_UNIX S.Stream S.defaultProtocol
-  withTimeout connTimeout "creating luxi connection" $
+  withTimeout luxiDefCtmo "creating luxi connection" $
               S.connect s (S.SockAddrUnix path)
   rf <- newIORef B.empty
   h <- S.socketToHandle s ReadWriteMode
@@ -250,7 +250,7 @@ closeClient = hClose . socket
 
 -- | Sends a message over a luxi transport.
 sendMsg :: Client -> String -> IO ()
-sendMsg s buf = withTimeout queryTimeout "sending luxi message" $ do
+sendMsg s buf = withTimeout luxiDefRwto "sending luxi message" $ do
   let encoded = UTF8.fromString buf
       handle = socket s
   B.hPut handle encoded
@@ -262,7 +262,7 @@ sendMsg s buf = withTimeout queryTimeout "sending luxi message" $ do
 -- message and the leftover buffer contents.
 recvUpdate :: Handle -> B.ByteString -> IO (B.ByteString, B.ByteString)
 recvUpdate handle obuf = do
-  nbuf <- withTimeout queryTimeout "reading luxi response" $ do
+  nbuf <- withTimeout luxiDefRwto "reading luxi response" $ do
             _ <- hWaitForInput handle (-1)
             B.hGetNonBlocking handle 4096
   let (msg, remaining) = B.break (eOM ==) nbuf
-- 
GitLab