From 1ca709c17c149d32a340a3a162f7c805e308caed Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 15 Feb 2013 14:08:17 +0100 Subject: [PATCH] Switch the curl bindings from optional to required Currently, we support curl being optional via some sporting exercises: ifdefs in the code, data types that represent 'Curl is disabled' state, etc. However, with the future work on RPC, we would have to even make the dependencies list conditional on it, etc. This is too much work, when the curl library is included even in stable distributions. This patch changes curl from option to required, the same as the other base libraries. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michele Tartara <mtartara@google.com> --- INSTALL | 36 +++++++++++++------------------ Makefile.am | 9 +++----- configure.ac | 34 +++-------------------------- src/Ganeti/HTools/Backend/Rapi.hs | 8 ------- src/Ganeti/Rpc.hs | 17 +++------------ 5 files changed, 24 insertions(+), 80 deletions(-) diff --git a/INSTALL b/INSTALL index 6b3825d62..636d67bd6 100644 --- a/INSTALL +++ b/INSTALL @@ -133,19 +133,22 @@ deploy Ganeti on production machines). More specifically: `utf8-string <http://hackage.haskell.org/package/utf8-string>`_ libraries; these usually come with the GHC compiler - `deepseq <http://hackage.haskell.org/package/deepseq>`_ +- `curl <http://hackage.haskell.org/package/curl>`_, tested with + versions 1.3.4 and above Some of these are also available as package in Debian/Ubuntu:: $ apt-get install ghc6 libghc6-json-dev libghc6-network-dev \ - libghc6-parallel-dev libghc6-deepseq-dev + libghc6-parallel-dev libghc6-deepseq-dev \ + libghc6-curl-dev Or in newer versions of these distributions (using GHC 7.x):: $ apt-get install ghc libghc-json-dev libghc-network-dev \ - libghc-parallel-dev libghc-deepseq-dev \ - libghc-utf8-string-dev + libghc-parallel-dev libghc-deepseq-dev \ + libghc-utf8-string-dev libghc-curl-dev -In Fedora, they are available via packages as well:: +In Fedora, some of them are available via packages as well:: $ yum install ghc ghc-json-devel ghc-network-devel \ ghc-parallel-devel ghc-deepseq-devel @@ -158,25 +161,16 @@ the Haskell platform. You can also install ``cabal`` manually:: Then install the additional libraries via ``cabal``:: - $ cabal install json network parallel utf8-string - -The compilation of the htools components is automatically enabled when -the compiler and the requisite libraries are found. You can use the -``--enable-htools`` configure flag to force the selection (at which -point ``./configure`` will fail if it doesn't find the prerequisites). - + $ cabal install json network parallel utf8-string curl Haskell optional features ~~~~~~~~~~~~~~~~~~~~~~~~~ Optionally, more functionality can be enabled if your build machine has -a few more Haskell libraries enabled: RAPI access to remote cluster from -htools (``--enable-htools-rapi``), the ``ganeti-confd`` -daemon (``--enable-confd``) and the monitoring agent +a few more Haskell libraries enabled: the ``ganeti-confd`` daemon +(``--enable-confd``) and the monitoring agent (``--enable-monitoring``). The list of extra dependencies for these is: -- `curl <http://hackage.haskell.org/package/curl>`_, tested with - versions 1.3.4 and above - `hslogger <http://software.complete.org/hslogger>`_, version 1.1 and above (note that Debian Squeeze only has version 1.0.9) - `Crypto <http://hackage.haskell.org/package/Crypto>`_, tested with @@ -193,19 +187,19 @@ These libraries are available in Debian Wheezy (but not in Squeeze, with the exception of curl), so you can use either apt:: $ apt-get install libghc-hslogger-dev libghc-crypto-dev libghc-text-dev \ - libghc-hinotify-dev libghc-regex-pcre-dev libghc-curl-dev \ + libghc-hinotify-dev libghc-regex-pcre-dev \ libghc-attoparsec-dev libghc-vector-dev or ``cabal``:: - $ cabal install hslogger Crypto text hinotify regex-pcre curl \ + $ cabal install hslogger Crypto text hinotify regex-pcre \ attoparsec vector to install them. -The most recent Fedora doesn't provide ``curl``, ``crypto``, -``inotify``. So these need to be installed using ``cabal``, if -desired. The other packages can be installed via ``yum``:: +The most recent Fedora doesn't provide ``crypto``, ``inotify``. So these +need to be installed using ``cabal``, if desired. The other packages can +be installed via ``yum``:: $ yum install ghc-hslogger-devel ghc-text-devel \ ghc-regex-pcre-devel diff --git a/Makefile.am b/Makefile.am index d38f11572..88054a0d3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -770,7 +770,7 @@ $(HS_ALL_PROGS): %: %.hs $(HS_LIBTEST_SRCS) $(HS_BUILT_SRCS) Makefile @rm -f $(notdir $@).tix $(GHC) --make \ $(HFLAGS) \ - $(HS_NOCURL) $(HS_PARALLEL3) $(HS_REGEX_PCRE) \ + $(HS_PARALLEL3) $(HS_REGEX_PCRE) \ -osuf $(notdir $@).o -hisuf $(notdir $@).hi \ $(HEXTRA) $(HEXTRA_INT) $@ @touch "$@" @@ -1844,10 +1844,7 @@ hs-apidoc: $(HS_BUILT_SRCS) $(LN_S) ../hscolour.css $(APIDOC_HS_DIR)/Ganeti/Confd/hscolour.css set -e ; \ cd src; \ - if [ "$(HS_NOCURL)" ]; \ - then OPTGHC="--optghc=$(HS_NOCURL)"; \ - else OPTGHC=""; \ - fi; \ + OPTGHC=""; \ if [ "$(HS_PARALLEL3)" ]; \ then OPTGHC="$$OPTGHC --optghc=$(HS_PARALLEL3)"; \ fi; \ @@ -1871,7 +1868,7 @@ TAGS: $(GENERATED_FILES) rm -f TAGS $(GHC) -e ":etags" -v0 \ $(filter-out -O -Werror,$(HFLAGS)) \ - $(HS_NOCURL) $(HS_PARALLEL3) $(HS_REGEX_PCRE) \ + $(HS_PARALLEL3) $(HS_REGEX_PCRE) \ $(HS_LIBTEST_SRCS) find . -path './lib/*.py' -o -path './scripts/gnt-*' -o \ -path './daemons/ganeti-*' -o -path './tools/*' -o \ diff --git a/configure.ac b/configure.ac index 0683f5fcb..e00771adc 100644 --- a/configure.ac +++ b/configure.ac @@ -467,14 +467,6 @@ then AC_MSG_WARN([qemu-img not found, using ovfconverter will not be possible]) fi -# --enable-htools-rapi -HTOOLS_RAPI= -AC_ARG_ENABLE([htools-rapi], - [AS_HELP_STRING([--enable-htools-rapi], - [enable use of curl in the Haskell code (default: check)])], - [], - [enable_htools_rapi=check]) - # --enable-confd ENABLE_CONFD= AC_ARG_ENABLE([confd], @@ -517,29 +509,13 @@ fi # check for modules, first custom/special checks AC_MSG_NOTICE([checking for required haskell modules]) -HS_NOCURL=-DNO_CURL -if test "$enable_htools_rapi" != no; then - AC_GHC_PKG_CHECK([curl], [HS_NOCURL=], []) - if test -n "$HS_NOCURL"; then - if test "$enable_htools_rapi" = check; then - AC_MSG_WARN(m4_normalize([The curl library was not found, Haskell - code will be compiled without RAPI support])) - else - AC_MSG_FAILURE(m4_normalize([The curl library was not found, but it has - been requested])) - fi - else - AC_MSG_NOTICE([Enabling curl/RAPI/RPC usage in Haskell code]) - fi -fi -AC_SUBST(HS_NOCURL) - HS_PARALLEL3= AC_GHC_PKG_CHECK([parallel-3.*], [HS_PARALLEL3=-DPARALLEL3], [AC_GHC_PKG_REQUIRE(parallel)], t) AC_SUBST(HS_PARALLEL3) # and now standard modules +AC_GHC_PKG_REQUIRE(curl) AC_GHC_PKG_REQUIRE(json) AC_GHC_PKG_REQUIRE(network) AC_GHC_PKG_REQUIRE(mtl) @@ -641,8 +617,8 @@ AC_ARG_ENABLE([split-query], ;; esac ]], - [[case "x${has_confd}x${HS_NOCURL}x" in - xTruexx) + [[case "x${has_confd}x" in + xTruex) enable_split_query=True ;; *) @@ -655,10 +631,6 @@ if test x$enable_split_query = xTrue -a x$has_confd != xTrue; then AC_MSG_ERROR([Split queries require the confd daemon]) fi -if test x$enable_split_query = xTrue -a x$HS_NOCURL != x; then - AC_MSG_ERROR([Split queries require the htools-rapi feature (curl library)]) -fi - if test x$enable_split_query = xTrue; then AC_MSG_NOTICE([Split query functionality enabled]) fi diff --git a/src/Ganeti/HTools/Backend/Rapi.hs b/src/Ganeti/HTools/Backend/Rapi.hs index eaf061c4c..5a1cd4934 100644 --- a/src/Ganeti/HTools/Backend/Rapi.hs +++ b/src/Ganeti/HTools/Backend/Rapi.hs @@ -33,10 +33,8 @@ module Ganeti.HTools.Backend.Rapi import Control.Exception import Data.List (isPrefixOf) import Data.Maybe (fromMaybe) -#ifndef NO_CURL import Network.Curl import Network.Curl.Types () -#endif import Control.Monad import Text.JSON (JSObject, fromJSObject, decodeStrict) import Text.JSON.Types (JSValue(..)) @@ -61,11 +59,6 @@ filePrefix = "file://" -- | Read an URL via curl and return the body if successful. getUrl :: (Monad m) => String -> IO (m String) -#ifdef NO_CURL -getUrl _ = return $ fail "RAPI/curl backend disabled at compile time" - -#else - -- | Connection timeout (when using non-file methods). connTimeout :: Long connTimeout = 15 @@ -88,7 +81,6 @@ getUrl url = do CurlOK -> return body _ -> fail $ printf "Curl error for '%s', error %s" url (show code)) -#endif -- | Helper to convert I/O errors in 'Bad' values. ioErrToResult :: IO a -> IO (Result a) diff --git a/src/Ganeti/Rpc.hs b/src/Ganeti/Rpc.hs index 284bb5ef7..2eabd3679 100644 --- a/src/Ganeti/Rpc.hs +++ b/src/Ganeti/Rpc.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, CPP, +{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, BangPatterns, TemplateHaskell #-} {-| Implementation of the RPC client. @@ -7,7 +7,7 @@ {- -Copyright (C) 2012 Google Inc. +Copyright (C) 2012, 2013 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 @@ -75,10 +75,8 @@ import Data.Maybe (fromMaybe) import qualified Text.JSON as J import Text.JSON.Pretty (pp_value) -#ifndef NO_CURL import Network.Curl import qualified Ganeti.Path as P -#endif import qualified Ganeti.Constants as C import Ganeti.Objects @@ -88,7 +86,6 @@ import Ganeti.Compat -- * Base RPC functionality and types -#ifndef NO_CURL -- | The curl options used for RPC. curlOpts :: [CurlOption] curlOpts = [ CurlFollowLocation False @@ -98,12 +95,10 @@ curlOpts = [ CurlFollowLocation False , CurlSSLKeyType "PEM" , CurlConnectTimeout (fromIntegral C.rpcConnectTimeout) ] -#endif -- | Data type for RPC error reporting. data RpcError - = CurlDisabledError - | CurlLayerError Node String + = CurlLayerError Node String | JsonDecodeError String | RpcResultError String | OfflineNodeError Node @@ -111,8 +106,6 @@ data RpcError -- | Provide explanation to RPC errors. explainRpcError :: RpcError -> String -explainRpcError CurlDisabledError = - "RPC/curl backend disabled at compile time" explainRpcError (CurlLayerError node code) = "Curl error for " ++ nodeName node ++ ", " ++ code explainRpcError (JsonDecodeError msg) = @@ -164,9 +157,6 @@ executeHttpRequest :: Node -> ERpcError HttpClientRequest -> IO (ERpcError String) executeHttpRequest _ (Left rpc_err) = return $ Left rpc_err -#ifdef NO_CURL -executeHttpRequest _ _ = return $ Left CurlDisabledError -#else executeHttpRequest node (Right request) = do cert_file <- P.nodedCertFile let reqOpts = [ CurlTimeout (fromIntegral $ requestTimeout request) @@ -181,7 +171,6 @@ executeHttpRequest node (Right request) = do return $ case code of CurlOK -> Right body _ -> Left $ CurlLayerError node (show code) -#endif -- | Prepare url for the HTTP request. prepareUrl :: (RpcCall a) => Node -> a -> String -- GitLab