Exemplo n.º 1
0
    def _callMethod(self, methodName, callData, args, kwargs):
        if not methodName.startswith('_'):
            if '.' in methodName:
                first, rest = methodName.split('.', 1)
                server = self._rpc_children.get(first)
                if server:
                    return server._callMethod(rest, callData, args, kwargs)
            else:
                m = getattr(self, methodName, None)
                if m and getattr(m, 'rpc_exposed', False):
                    # Collapse arguments to a tuple early to make API error
                    # detection easier.
                    filler = ArgFiller.fromFunc(m)
                    if m.rpc_callData:
                        args = (self, callData) + args
                    else:
                        args = (self,) + args

                    try:
                        args = filler.fill(args, kwargs)
                    except:
                        # Client passed wrong arguments.
                        rethrow(errors.APIError)

                    # Pull 'self' back out before invoking.
                    args = args[1:]
                    return m(*args)

        raise NoSuchMethodError(methodName)
Exemplo n.º 2
0
    def _doRequest(self, req, forceProxy):
        resetResolv = False
        lastError = response = None
        timer = timeutil.BackoffTimer()
        totalAttempts = 0
        # Make at least 'connectAttempts' connection attempts, stopping after
        # both passing the connectAttempts limit *and* hitting the end of the
        # iterator.
        while True:
            if totalAttempts >= self.connectAttempts:
                break
            # Reset the failed proxy list each time around so we don't end up
            # blacklisting everything if a second pass succeeds.
            failedProxies = set()

            if forceProxy is False:
                connIterator = self.proxyMap.getProxyIter(req.url,
                        protocolFilter=self.proxyFilter)
            else:
                connIterator = [forceProxy]

            for proxySpec in connIterator:
                totalAttempts += 1
                if proxySpec == proxy_map.DirectConnection:
                    proxySpec = None
                elif not forceProxy and self._shouldBypass(req.url, proxySpec):
                    proxySpec = None
                if lastError:
                    if proxySpec == self.lastProxy:
                        log.debug("Failed to open URL %s; trying again: %s",
                                req.url, lastError.format())
                    else:
                        log.info("Failed to open URL %s; trying the next "
                                "proxy: %s", req.url, lastError.format())
                    try:
                        req.reset()
                    except:
                        log.exception("Failed to rewind request body file, "
                                "unable to retry request:")
                        break
                # If a proxy was used, save it here
                self.lastProxy = proxySpec

                try:
                    response = self._requestOnce(req, proxySpec)
                    break
                except http_error.RequestError, err:
                    # Retry if an error occurred while sending the request.
                    lastError = err.wrapped
                    err = lastError.value
                    if lastError.check(socket.error):
                        self._processSocketError(err)
                        lastError.replace(err)
                except httplib.BadStatusLine:
                    # closed connection without sending a response.
                    lastError = util.SavedException()
                except socket.error, err:
                    # Fatal error, but attach proxy information to it.
                    self._processSocketError(err)
                    util.rethrow(err, False)
Exemplo n.º 3
0
    def configLine(self, line, fileName = "override", lineno = '<No line>'):
        line = line.strip()
        line = line.replace('\\\\', '\0').replace('\\#', '\1')
        line = line.split('#', 1)[0]
        if not line:
            return
        line = line.replace('\0', '\\').replace('\1', '#')

        parts = line.split(None, 1)
        if len(parts) == 1:
            key = parts[0]
            val = ''
        else:
            (key, val) = parts

        if key.lower() in self._cfg_def.directives:
            funcName, args, kwargs = self._cfg_def.directives[key.lower()]
            fn = getattr(self, funcName)
            try:
                fn(val, *args, **kwargs)
            except Exception, err:
                if errors.exceptionIsUncatchable(err):
                    raise
                util.rethrow(ParseError("%s:%s: when processing %s: %s"
                    % (fileName, lineno, key, err)))
Exemplo n.º 4
0
    def configLine(self, line, fileName = "override", lineno = '<No line>'):
        line = line.strip()
        line = line.replace('\\\\', '\0').replace('\\#', '\1')
        line = line.split('#', 1)[0]
        if not line:
            return
        line = line.replace('\0', '\\').replace('\1', '#')

        parts = line.split(None, 1)
        if len(parts) == 1:
            key = parts[0]
            val = ''
        else:
            (key, val) = parts

        if key.lower() in self._cfg_def.directives:
            funcName, args, kwargs = self._cfg_def.directives[key.lower()]
            fn = getattr(self, funcName)
            try:
                fn(val, *args, **kwargs)
            except Exception, err:
                if errors.exceptionIsUncatchable(err):
                    raise
                util.rethrow(ParseError("%s:%s: when processing %s: %s"
                    % (fileName, lineno, key, err)))
Exemplo n.º 5
0
    def __init__(self, busClient, dispatcherId=None):
        if dispatcherId is None:
            try:
                dispatcherId = findBusNode(busClient,
                                           dispatcher.Dispatcher.sessionClass)
            except OpenError, err:
                rethrow(BuildSystemUnreachableError)

            if dispatcherId is None:
                raise BuildSystemUnreachableError(
                    "Could not contact the dispatcher")
Exemplo n.º 6
0
 def request(self, address, contentType, request_body, response_filter):
     try:
         conn = self.make_connection(address)
         self.send_request(conn, address)
         self.send_host(conn, address)
         self.send_user_agent(conn)
         self.send_authorization(conn, address)
         self.send_content(conn, contentType, request_body)
     except socket.error, err:
         rethrow(errors.OpenError("Error contacting server at %s: %s" %
             (address, err)))
Exemplo n.º 7
0
    def __init__(self, busClient, dispatcherId=None):
        if dispatcherId is None:
            try:
                dispatcherId = findBusNode(busClient,
                        dispatcher.Dispatcher.sessionClass)
            except OpenError, err:
                rethrow(BuildSystemUnreachableError)

            if dispatcherId is None:
                raise BuildSystemUnreachableError(
                        "Could not contact the dispatcher")
Exemplo n.º 8
0
    def request(self, url, body, verbose=0):
        self.verbose = verbose

        req = self.opener.newRequest(url,
                                     method='POST',
                                     headers=self.extraHeaders)

        req.setAbortCheck(self.abortCheck)
        req.setData(body, compress=self.compress)
        if self.entitlement:
            req.headers['X-Conary-Entitlement'] = self.entitlement
        if self.serverName:
            req.headers['X-Conary-Servername'] = self.serverName
        req.headers['User-agent'] = self.user_agent

        # Make sure we capture some useful information from the
        # opener, even if we failed
        try:
            try:
                response = self.opener.open(req)
            except AbortError:
                raise
            except http_error.ResponseError, err:
                if err.errcode == 403:
                    raise errors.InsufficientPermission(
                        repoName=self.serverName, url=url)
                elif err.errcode == 500:
                    raise errors.InternalServerError(err)
                else:
                    # Already has adequate URL information, so just rethrow it
                    # without modifying the message.
                    util.rethrow(errors.OpenError, False)
            except (socket.error, EnvironmentError, http_error.TransportError):
                e_type, e_value, e_tb = sys.exc_info()
                if isinstance(e_value, socket.error):
                    errmsg = http_error.splitSocketError(e_value)[1]
                elif isinstance(e_value, EnvironmentError):
                    errmsg = e_value.sterror
                    # sometimes there is a socket error hiding inside an
                    # IOError!
                    if isinstance(errmsg, socket.error):
                        errmsg = http_error.splitSocketError(errmsg)[1]
                else:
                    e_name = getattr(e_type, '__name__', 'Unknown Error')
                    errmsg = '%s: %s' % (e_name, e_value)
                raise errors.OpenError(
                    "Error occurred opening repository %s: %s" %
                    (url, errmsg)), None, e_tb

            else:
                self.responseHeaders = response.headers
                self.responseProtocol = response.protocolVersion
                return self.parse_response(response)
Exemplo n.º 9
0
    def request(self, url, body, verbose=0):
        self.verbose = verbose

        req = self.opener.newRequest(url, method='POST',
                headers=self.extraHeaders)

        req.setAbortCheck(self.abortCheck)
        req.setData(body, compress=self.compress)
        if self.entitlement:
            req.headers['X-Conary-Entitlement'] = self.entitlement
        if self.serverName:
            req.headers['X-Conary-Servername'] = self.serverName
        req.headers['User-agent'] = self.user_agent
        req.headers['Accept'] = ','.join(self.contentTypes + [self.mixedType])

        # Make sure we capture some useful information from the
        # opener, even if we failed
        try:
            try:
                response = self.opener.open(req)
            except AbortError:
                raise
            except http_error.ResponseError, err:
                if err.errcode == 403:
                    raise errors.InsufficientPermission(
                            repoName=self.serverName, url=url)
                elif err.errcode == 500:
                    raise errors.InternalServerError(err)
                else:
                    # Already has adequate URL information, so just rethrow it
                    # without modifying the message.
                    util.rethrow(errors.OpenError, False)
            except (socket.error, EnvironmentError, http_error.TransportError):
                e_type, e_value, e_tb = sys.exc_info()
                if isinstance(e_value, socket.error):
                    errmsg = http_error.splitSocketError(e_value)[1]
                elif isinstance(e_value, EnvironmentError):
                    errmsg = e_value.strerror
                    # sometimes there is a socket error hiding inside an
                    # IOError!
                    if isinstance(errmsg, socket.error):
                        errmsg = http_error.splitSocketError(errmsg)[1]
                else:
                    e_name = getattr(e_type, '__name__', 'Unknown Error')
                    errmsg = '%s: %s' % (e_name, e_value)
                raise errors.OpenError(
                        "Error occurred opening repository %s: %s" %
                        (url, errmsg)), None, e_tb

            else:
                self.responseHeaders = response.headers
                self.responseProtocol = response.protocolVersion
                return self.parse_response(response)
Exemplo n.º 10
0
    def _openDb(self):
        if not self._db:
            self._db = dbstore.connect(self._cfg.dbPath, self._cfg.dbDriver)
            self._autoDb = True

        # check to make sure the schema version is correct
        try:
            schema.checkVersion(self._db)
        except sqlerrors.SchemaVersionError:
            rethrow(mint_error.DatabaseVersionMismatch, False)

        tables = TableCache(self._db, self._cfg)
        self._copyTables(tables)
        if self._db.inTransaction(True):
            self._db.commit()
Exemplo n.º 11
0
    def _doRequest(self, req, forceProxy):
        resetResolv = False
        lastError = response = None
        timer = timeutil.BackoffTimer()
        totalAttempts = 0
        # Make at least 'connectAttempts' connection attempts, stopping after
        # both passing the connectAttempts limit *and* hitting the end of the
        # iterator.
        while True:
            if totalAttempts >= self.connectAttempts:
                break
            # Reset the failed proxy list each time around so we don't end up
            # blacklisting everything if a second pass succeeds.
            failedProxies = set()

            if forceProxy is False:
                connIterator = self.proxyMap.getProxyIter(
                    req.url, protocolFilter=self.proxyFilter)
            else:
                connIterator = [forceProxy]

            for proxySpec in connIterator:
                totalAttempts += 1
                if proxySpec == proxy_map.DirectConnection:
                    proxySpec = None
                elif not forceProxy and self._shouldBypass(req.url, proxySpec):
                    proxySpec = None
                if lastError:
                    if proxySpec == self.lastProxy:
                        log.debug("Failed to open URL %s; trying again: %s",
                                  req.url, lastError.format())
                    else:
                        log.info(
                            "Failed to open URL %s; trying the next "
                            "proxy: %s", req.url, lastError.format())
                    try:
                        req.reset()
                    except:
                        log.exception("Failed to rewind request body file, "
                                      "unable to retry request:")
                        break
                # If a proxy was used, save it here
                self.lastProxy = proxySpec

                try:
                    response = self._requestOnce(req, proxySpec)
                    break
                except http_error.RequestError, err:
                    # Retry if an error occurred while sending the request.
                    lastError = err.wrapped
                    err = lastError.value
                    if lastError.check(socket.error):
                        self._processSocketError(err)
                        lastError.replace(err)
                except httplib.BadStatusLine:
                    # closed connection without sending a response.
                    lastError = util.SavedException()
                except socket.error, err:
                    # Fatal error, but attach proxy information to it.
                    self._processSocketError(err)
                    util.rethrow(err, False)