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):
-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')
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
+# $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
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),