Exemple #1
0
    def _dispatch(self, method, params):
        func = self._get_handler(method)
        context.method = method
        context.params = params
        self.check_session()
        self.enforce_lockout()
        # handle named parameters
        params, opts = koji.decode_args(*params)

        if self.logger.isEnabledFor(logging.INFO):
            self.logger.info("Handling method %s for session %s (#%s)", method,
                             context.session.id, context.session.callnum)
            if method != 'uploadFile' and self.logger.isEnabledFor(
                    logging.DEBUG):
                self.logger.debug("Params: %s", pprint.pformat(params))
                self.logger.debug("Opts: %s", pprint.pformat(opts))
            start = time.time()

        ret = koji.util.call_with_argcheck(func, params, opts)

        if self.logger.isEnabledFor(logging.INFO):
            rusage = resource.getrusage(resource.RUSAGE_SELF)
            self.logger.info(
                "Completed method %s for session %s (#%s): %f seconds, rss %s, stime %f",
                method, context.session.id, context.session.callnum,
                time.time() - start, rusage.ru_maxrss, rusage.ru_stime)

        return ret
Exemple #2
0
def parse_task_params(method, params):
    """Parse task params into a dictionary

    New tasks should already be dictionaries
    """

    # check for new style
    if (len(params) == 1 and isinstance(params[0], dict)
            and '__method__' in params[0]):
        ret = params[0].copy()
        del ret['__method__']
        return ret

    # otherwise sort out the legacy signatures
    args, kwargs = koji.decode_args(*params)

    if method not in LEGACY_SIGNATURES:
        raise TypeError("No legacy signature for %s" % method)

    err = None
    for argspec in LEGACY_SIGNATURES[method]:
        try:
            params = koji.util.apply_argspec(argspec, args, kwargs)
            break
        except koji.ParameterError as e:
            if not err:
                err = e.args[0]
    else:
        raise koji.ParameterError("Invalid signature for %s: %s" %
                                  (method, err))

    return params
Exemple #3
0
    def _dispatch(self, method, params):
        func = self._get_handler(method)
        context.method = method
        context.params = params
        self.check_session()
        self.enforce_lockout()
        # handle named parameters
        params, opts = koji.decode_args(*params)

        if self.logger.isEnabledFor(logging.INFO):
            self.logger.info("Handling method %s for session %s (#%s)",
                            method, context.session.id, context.session.callnum)
            if method != 'uploadFile' and self.logger.isEnabledFor(logging.DEBUG):
                self.logger.debug("Params: %s", pprint.pformat(params))
                self.logger.debug("Opts: %s", pprint.pformat(opts))
            start = time.time()

        ret = koji.util.call_with_argcheck(func, params, opts)

        if self.logger.isEnabledFor(logging.INFO):
            rusage = resource.getrusage(resource.RUSAGE_SELF)
            self.logger.info("Completed method %s for session %s (#%s): %f seconds, rss %s, stime %f",
                            method, context.session.id, context.session.callnum,
                            time.time()-start,
                            rusage.ru_maxrss, rusage.ru_stime)

        return ret
Exemple #4
0
def parse_task_params(method, params):
    """Parse task params into a dictionary

    New tasks should already be dictionaries
    """

    # check for new style
    if (len(params) == 1 and isinstance(params[0], dict)
                and '__method__' in params[0]):
        ret = params[0].copy()
        del ret['__method__']
        return ret

    # otherwise sort out the legacy signatures
    args, kwargs = koji.decode_args(*params)

    if method not in LEGACY_SIGNATURES:
        raise TypeError("No legacy signature for %s" % method)

    err = None
    for argspec in LEGACY_SIGNATURES[method]:
        try:
            params = koji.util.apply_argspec(argspec, args, kwargs)
            break
        except koji.ParameterError as e:
            if not err:
                err = e.args[0]
    else:
        raise koji.ParameterError("Invalid signature for %s: %s" % (method, err))

    return params
Exemple #5
0
 def __init__(self, id, method, params, session, options, workdir=None):
     self.id = id  # task id
     if method not in self.Methods:
         raise koji.GenericError, 'method "%s" is not supported' % method
     self.method = method
     # handle named parameters
     self.params, self.opts = koji.decode_args(*params)
     self.session = session
     self.options = options
     if workdir is None:
         workdir = "%s/%s" % (self.options.workdir, koji.pathinfo.taskrelpath(id))
     self.workdir = workdir
     self.logger = logging.getLogger("koji.build.BaseTaskHandler")
     self.manager = None
Exemple #6
0
 def __init__(self, id, method, params, session, options, workdir=None):
     self.id = id  #task id
     if method not in self.Methods:
         raise koji.GenericError, 'method "%s" is not supported' % method
     self.method = method
     # handle named parameters
     self.params, self.opts = koji.decode_args(*params)
     self.session = session
     self.options = options
     if workdir is None:
         workdir = "%s/%s" % (self.options.workdir,
                              koji.pathinfo.taskrelpath(id))
     self.workdir = workdir
     self.logger = logging.getLogger("koji.build.BaseTaskHandler")
     self.manager = None
Exemple #7
0
 def multiCall(self, strict=False):
     if not self.multicall:
         raise Exception("not in multicall")
     ret = []
     self.multicall = False
     calls = self._calls
     self._calls = []
     for call in calls:
         method = call['methodName']
         args, kwargs = koji.decode_args(call['params'])
         try:
             result = self._callMethod(method, args, kwargs)
             ret.append(result)
         except Fault as fault:
             if strict:
                 raise
             else:
                 ret.append({'faultCode': fault.faultCode,
                             'faultString': fault.faultString})
     return ret
 def multiCall(self, strict=False):
     if not self.multicall:
         raise Exception("not in multicall")
     ret = []
     self.multicall = False
     calls = self._calls
     self._calls = []
     for call in calls:
         method = call['methodName']
         args, kwargs = koji.decode_args(call['params'])
         try:
             result = self._callMethod(method, args, kwargs)
             ret.append(result)
         except Fault as fault:
             if strict:
                 raise
             else:
                 ret.append({'faultCode': fault.faultCode,
                             'faultString': fault.faultString})
     return ret
Exemple #9
0
    def _dispatch(self, method, params):
        func = self._get_handler(method)
        context.method = method
        if not hasattr(context, "session"):
            #we may be called again by one of our meta-calls (like multiCall)
            #so we should only create a session if one does not already exist
            context.session = koji.auth.Session()
            try:
                context.session.validate()
            except koji.AuthLockError:
                #might be ok, depending on method
                if method not in ('exclusiveSession', 'login', 'krbLogin',
                                  'logout'):
                    raise
            if context.opts.get('LockOut') and \
                   method not in ('login', 'krbLogin', 'sslLogin', 'logout'):
                if not context.session.hasPerm('admin'):
                    raise koji.ServerOffline, "Server disabled for maintenance"
        # handle named parameters
        params, opts = koji.decode_args(*params)

        if self.logger.isEnabledFor(logging.DEBUG):
            self.logger.debug("Handling method %s for session %s (#%s)",
                              method, context.session.id,
                              context.session.callnum)
            if method != 'uploadFile':
                self.logger.debug("Params: %s", pprint.pformat(params))
                self.logger.debug("Opts: %s", pprint.pformat(opts))
            start = time.time()

        ret = func(*params, **opts)

        if self.logger.isEnabledFor(logging.DEBUG):
            self.logger.debug(
                "Completed method %s for session %s (#%s): %f seconds", method,
                context.session.id, context.session.callnum,
                time.time() - start)

        return ret
Exemple #10
0
    def _dispatch(self,method,params):
        func = self._get_handler(method)
        context.method = method
        if not hasattr(context,"session"):
            #we may be called again by one of our meta-calls (like multiCall)
            #so we should only create a session if one does not already exist
            context.session = koji.auth.Session()
            try:
                context.session.validate()
            except koji.AuthLockError:
                #might be ok, depending on method
                if method not in ('exclusiveSession','login', 'krbLogin', 'logout'):
                    raise
            if context.opts.get('LockOut') and \
                   method not in ('login', 'krbLogin', 'sslLogin', 'logout'):
                if not context.session.hasPerm('admin'):
                    raise koji.ServerOffline, "Server disabled for maintenance"
        # handle named parameters
        params,opts = koji.decode_args(*params)

        if self.logger.isEnabledFor(logging.DEBUG):
            self.logger.debug("Handling method %s for session %s (#%s)",
                            method, context.session.id, context.session.callnum)
            if method != 'uploadFile':
                self.logger.debug("Params: %s", pprint.pformat(params))
                self.logger.debug("Opts: %s", pprint.pformat(opts))
            start = time.time()

        ret = func(*params,**opts)

        if self.logger.isEnabledFor(logging.DEBUG):
            self.logger.debug("Completed method %s for session %s (#%s): %f seconds",
                            method, context.session.id, context.session.callnum,
                            time.time()-start)

        return ret