get rid of curlwrapper.CurlException and raise xmlrpclib.ProtocolError instead
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 28 May 2008 10:22:40 +0000 (10:22 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 28 May 2008 10:22:40 +0000 (10:22 +0000)
temporarily prints as many details as possible when curl fails

conf_files.py
curlwrapper.py
safexmlrpc.py

index c5d5924..0ae0024 100644 (file)
@@ -52,7 +52,7 @@ class conf_files:
         url = 'https://%s/%s' % (self.config.PLC_BOOT_HOST, cf_rec['source'])
         try:
             contents = curlwrapper.retrieve(url, self.config.cacert)
-        except curlwrapper.CurlException:
+        except xmlrpclib.ProtocolError,e:
             logger.log('conf_files: failed to retrieve %s from %s, skipping' % (dest, url))
             return
         if not cf_rec['always_update'] and sha.new(contents).digest() == self.checksum(dest):
index e259578..54394d9 100644 (file)
@@ -1,7 +1,8 @@
-from subprocess import PIPE, Popen
-
+# $Id$
 
-class CurlException(Exception): pass
+from subprocess import PIPE, Popen
+# raise xmplrpclib.ProtocolError
+import xmlrpclib
 
 def retrieve(url, cacert=None, postdata=None, timeout=300):
     options = ('/usr/bin/curl', '--fail', '--silent')
@@ -14,5 +15,11 @@ def retrieve(url, cacert=None, postdata=None, timeout=300):
     data = p.stdout.read()
     err = p.stderr.read()
     rc = p.wait()
-    if rc != 0: raise CurlException(err)
-    else: return data
+    if rc != 0: 
+        # when this triggers, the error sometimes doesn't get printed
+        print 'curlwrapper.retrieve: raising xmlrpclib.ProtocolError\n  (url=%s,code=%d,stderr=%s,post=%r)'\
+            %(url,rc,err,postdata)
+        if cacert: print "Using cacert file %s"%cacert
+        raise xmlrpclib.ProtocolError(url, rc, err, postdata)
+    else: 
+        return data
index 7961a75..f320c9c 100644 (file)
@@ -1,10 +1,11 @@
+# $Id$
+
 """Leverage curl to make XMLRPC requests that check the server's credentials."""
 
 import curlwrapper
-import xmlrpclib
 
+class CertificateCheckingSafeTransport (xmlrpclib.Transport):
 
-class CertificateCheckingSafeTransport(xmlrpclib.Transport):
     def __init__(self, cacert, timeout):
         self.cacert = cacert
         self.timeout = timeout
@@ -12,18 +13,15 @@ class CertificateCheckingSafeTransport(xmlrpclib.Transport):
     def request(self, host, handler, request_body, verbose=0):
         self.verbose = verbose
         url='https://%s%s' % (host, handler)
-        try:
-            contents = curlwrapper.retrieve(url,
-                                            cacert = self.cacert,
-                                            postdata = request_body,
-                                            timeout = self.timeout)
-            return xmlrpclib.loads(contents)[0]
-        except curlwrapper.CurlException, e:
-            # when this triggers, the error sometimes doesn't get printed
-            print 'CertificateCheckingSafeTransport.request: Catching curlwrapper.CurlException with error <%s>'%str(e)
-            raise xmlrpclib.ProtocolError(url, -1, str(e), request_body)
+        # this might raise an xmlrpclib.Protocolerror exception
+        contents = curlwrapper.retrieve(url,
+                                        cacert = self.cacert,
+                                        postdata = request_body,
+                                        timeout = self.timeout)
+        return xmlrpclib.loads(contents)[0]
 
 class ServerProxy(xmlrpclib.ServerProxy):
+
     def __init__(self, uri, cacert, timeout = 300, **kwds):
         xmlrpclib.ServerProxy.__init__(self, uri,
                                        CertificateCheckingSafeTransport(cacert, timeout),