Exemplo n.º 1
0
 def tempf(*args, **kwargs):
     try:
         argstr = "*" + repr(args) + ", **" + repr(kwargs)
     except:
         argstr = "???"
     try:
         logf("start %s(%s) {" % (fstr, argstr))
     except:
         pass
     try:
         answ = f(*args, **kwargs)
         try:
             logf("} %s returned %s" % (fstr, repr(answ)))
         except:
             pass
         return answ
     except:
         (etype, e, etb) = sys.exc_info()
         if getattr(e, '_printed', False):
             tb = '...'
         else:
             tb = repr(format_exc())
             setattr(e, '_printed', True)
         try:
             logf("} %s raised %s (%s)" % (fstr, repr(e), tb))
         except:
             pass
         raise e, None, etb
Exemplo n.º 2
0
def do_task_result(fname, task_id, result_type, path, score, summary):
    """
    Report task result

    result_type -- 'Pass'|'Warn'|'Fail'|'Panic'

    return 0 on success, error message otherwise
    """
    global results
    try:
        log.info(
            "%s(task_id=%r, result_type=%r, path=%r, score=%r, summary=%r)",
            fname, task_id, result_type, path, score, summary)
        rec_args = get_recipe_args(task_id=task_id)
        if not rec_args:
            raise no_task(task_id=task_id)
        ix = 'task%s_res' % task_id
        result = rec_args.get(ix, "Pass")
        if RESULT_TYPE_.count(result) == 0 \
            or (RESULT_TYPE_.count(result_type) > 0 \
                    and RESULT_TYPE_.index(result) < RESULT_TYPE_.index(result_type)):
            rec_args[ix] = result_type
        result_id = "%s%s%.2d" % (task_id, time.strftime("%H%M%S"),
                                  randint(0, 99))
        add_result(task_id, result_id)
        results.result(task_id, result_type, path, score, summary, result_id)
        log.info("%s.RETURN: %s", fname, result_id)
        misc.log_flush(log)
        return result_id
    except:
        log.error("%s", misc.format_exc())
        results.result(task_id, result_type, path, score, summary, "ERROR")
        raise
Exemplo n.º 3
0
def do_task_result(fname, task_id, result_type, path, score, summary):
    """
    Report task result

    result_type -- 'Pass'|'Warn'|'Fail'|'Panic'

    return 0 on success, error message otherwise
    """
    global results
    try:
        log.info(
                "%s(task_id=%r, result_type=%r, path=%r, score=%r, summary=%r)",
                fname, task_id, result_type, path, score, summary)
        rec_args = get_recipe_args(task_id=task_id)
        if not rec_args:
            raise no_task(task_id=task_id)
        ix = 'task%s_res' % task_id
        result = rec_args.get(ix, "Pass")
        if RESULT_TYPE_.count(result) == 0 \
            or (RESULT_TYPE_.count(result_type) > 0 \
                    and RESULT_TYPE_.index(result) < RESULT_TYPE_.index(result_type)):
            rec_args[ix]=result_type
        result_id = "%s%s%.2d" % (task_id, time.strftime("%H%M%S"), randint(0, 99))
        add_result(task_id, result_id)
        results.result(task_id, result_type, path, score, summary, result_id)
        log.info("%s.RETURN: %s", fname, result_id)
        misc.log_flush(log)
        return result_id
    except:
        log.error("%s", misc.format_exc())
        results.result(task_id, result_type, path, score, summary, "ERROR")
        raise
Exemplo n.º 4
0
    def proc_cmd(self, cmd):
        """
        Process received Command.

        @cmd is a command. Should be an instance of Command class.
        """
        print "%s.proc_cmd(%r)" % (self, cmd)
        handler = getattr(self, "proc_cmd_"+cmd.command(), None)
        if not handler:
            echo_evt = self.proc_def_handler(cmd, event.echo(cmd,
                ECHO.NOT_IMPLEMENTED, origin=self.origin()))
        else:
            try:
                echo_evt = handler(cmd, event.echo(cmd, ECHO.OK,
                    origin=self.origin()))
            except:
                echo_evt = self.proc_exception(cmd, event.echo(cmd, ECHO.EXCEPTION,
                    origin=self.origin(), exception=format_exc()))
        if echo_evt:
            self.send_cmd(echo_evt)
Exemplo n.º 5
0
 def tempf(*args, **kwargs):
     try: argstr = "*"+repr(args)+", **"+repr(kwargs)
     except: argstr = "???"
     try: logf("start %s(%s) {" % (fstr, argstr))
     except: pass
     try:
         answ = f(*args, **kwargs)
         try: logf("} %s returned %s" % (fstr, repr(answ)))
         except: pass
         return answ
     except:
         (etype, e, etb) = sys.exc_info()
         if getattr(e, '_printed', False):
             tb = '...'
         else:
             tb = repr(format_exc())
             setattr(e, '_printed', True)
         try: logf("} %s raised %s (%s)" % (fstr, repr(e), tb))
         except: pass
         raise e, None, etb
Exemplo n.º 6
0
    def proc_cmd(self, backend, cmd):
        """Process Command received from backend.

        @backend is the backend, which issued the command.
        @cmd is a command. Should be an instance of Command class.

        This is the only method mandatory for Backend side
        Controller-Adaptor."""
        log.debug("Controller: proc_cmd(..., %r)", cmd)
        handler = getattr(self, "proc_cmd_"+cmd.command(), None)
        if not handler:
            evt = event.echo(cmd, ECHO.NOT_IMPLEMENTED, origin=self.__origin)
        else:
            evt = event.echo(cmd, ECHO.OK, origin=self.__origin)
            try:
                handler(backend, cmd, evt)
            except:
                self.handle_exception("Handling %s raised an exception." %
                        cmd.command())
                dict_update(evt.args(),
                        rc=ECHO.EXCEPTION,
                        exception=format_exc())
        log.debug("Controller: echo(%r)", evt)
        backend.proc_evt(evt, explicit=True)
Exemplo n.º 7
0
 def handle_exception(self, message="Exception raised."):
     log.error("Controller: %s %s", message, format_exc())
Exemplo n.º 8
0
 def proc_input(self, obj):
     try:
         self.main.controller_input(obj)
     except:
         self.main.send_evt(event.lose_item(format_exc()))
Exemplo n.º 9
0
    def __init__(self, task_path, env):
        self.process = None
        self.listener = None
        self.task_path = task_path
        self.__done = False
        self.__waits_for = []

        # FIXME: is inheriting the whole environment desirable?
        if env is not USE_DEFAULT:
            self.env = dict(env)
        else:
            self.env = dict(os.environ)

        # FIXME: Any other env.variables to set?
        # FIXME: What values should be used here?
        # - some values could be received from LC when task is scheduled, but
        #   it would create a dependency!
        #   - let's use fake values, and let the Backend translate it (if
        #     supported)
        #     - e.g. JOBID, RECIPESETID, RECIPEID are not interesting at all
        #     - use task_id for RECIPESETID, and BE (or LC eventually) should
        #       be able to find about the rest...

        taskid = "J%(JOBID)s-S%(RECIPESETID)s-R%(RECIPEID)s-T%(TASKID)s" % self.env

        # FIXME! use tempfile and upload log when process ends.
        log = logging.getLogger('rhts_task')
        twmisc.twisted_logging(log, level=logging.WARNING)
        ll = self.env.get('BEAH_TASK_LOG', "warning")
        log.setLevel(str2log_level(ll))
        make_log_handler(log,
                         LOG_PATH,
                         "rhts_task_%s.log" % (taskid, ),
                         syslog=True,
                         console=self.env.get('BEAH_TASK_CONSOLE', False))

        # parse task's metadata:
        try:
            from rhts import testinfo
            ti = testinfo.parse_file(os.path.join(self.env['TESTPATH'],
                                                  'testinfo.desc'),
                                     raise_errors=False)
        except:
            log.error("Error in tasks metadata: %s" % format_exc())
            ti = None
        if ti is not None:
            for k, v in getattr(ti, 'environment', {}).iteritems():
                self.env.setdefault(k, v)
            for o in getattr(ti, 'options', []):
                opt_lower = o.lower()
                if opt_lower[0] == '-':
                    opt_lower = opt_lower[1:]
                    value = ''
                else:
                    value = 'yes'
                if opt_lower.startswith('compatible'):
                    self.env.setdefault('RHTS_OPTION_COMPATIBLE', value)
                elif opt_lower.startswith('compatservice'):
                    self.env.setdefault('RHTS_OPTION_COMPAT_SERVICE', value)
                elif opt_lower.startswith('strongeravc'):
                    self.env.setdefault('RHTS_OPTION_STRONGER_AVC', value)

        # update log level if necessary:
        ll2 = self.env.get('BEAH_TASK_LOG', ll)
        if ll2 != ll:
            log.setLevel(str2log_level(ll2))

        # No point in storing everything in one big file. Use one file per task
        rt = runtimes.ShelveRuntime(RUNTIME_PATHNAME_TEMPLATE % taskid)
        self.__files = runtimes.TypeDict(rt, 'files')

        # FIXME: use configurable range of ports.
        self.variables = runtimes.TypeDict(rt, 'variables')
        port = self.variables.setdefault(
            'port', int(self.env.get('RHTS_PORT', random.randint(7080, 7099))))
        self.variables.setdefault('nohup', False)
        self.variables.setdefault('has_result', False)

        self.env.setdefault(
            'DIGEST_METHOD', 'no_digest'
        )  # use no digests by default... Seems waste of time on localhost.
        self.env.setdefault('TESTORDER', '123')  # FIXME: More sensible default

        # update defaults:
        for k, v in self.ENV_DEFAULTS.iteritems():
            self.env.setdefault(k, v)

        # provide sensible defaults for selected system env.variables:
        self.env.setdefault('HOME', '/root')
        self.env.setdefault('LANG', 'en_US.UTF-8')

        # FIXME: should any checks go here?
        # e.g. does Makefile PURPOSE exist? try running `make testinfo.desc`? ...
        self.controller = ControllerLink(self)
        stdio.StandardIO(self.controller)
        self.task = RHTSTask(self)
        self.server = RHTSServer(self)

        # If IPv6 has not been disabled, attempt to listen on IPv6
        # otherwise fall back to IPv4
        def listen_tcp(interface):
            return reactor.listenTCP(port, self.server, interface=interface)

        conf = beah.config.get_conf('beah')
        if not parse_bool(conf.get('DEFAULT', 'IPV6_DISABLED')):
            try:
                listen_tcp('::1')
                self.env['RESULT_SERVER'] = '[::1]:%s' % port
            except CannotListenError:
                listen_tcp('127.0.0.1')
                self.env['RESULT_SERVER'] = '127.0.0.1:%s' % port
        else:
            listen_tcp('127.0.0.1')
            self.env['RESULT_SERVER'] = '127.0.0.1:%s' % port
        # save env:
        env_file = ENV_PATHNAME_TEMPLATE % taskid
        self.env['RHTS_ENV'] = env_file
        jsonenv.export_env(env_file, self.env)

        # Execute rhts-test-runner.sh
        self.server_started()
Exemplo n.º 10
0
 def proc_input(self, obj):
     try:
         self.main.controller_input(obj)
     except:
         self.main.send_evt(event.lose_item(format_exc()))
Exemplo n.º 11
0
    def __init__(self, task_path, env):
        self.process = None
        self.listener = None
        self.task_path = task_path
        self.__done = False
        self.__waits_for = []

        # FIXME: is inheriting the whole environment desirable?
        if env is not USE_DEFAULT:
            self.env = dict(env)
        else:
            self.env = dict(os.environ)

        # FIXME: Any other env.variables to set?
        # FIXME: What values should be used here?
        # - some values could be received from LC when task is scheduled, but
        #   it would create a dependency!
        #   - let's use fake values, and let the Backend translate it (if
        #     supported)
        #     - e.g. JOBID, RECIPESETID, RECIPEID are not interesting at all
        #     - use task_id for RECIPESETID, and BE (or LC eventually) should
        #       be able to find about the rest...

        taskid = "J%(JOBID)s-S%(RECIPESETID)s-R%(RECIPEID)s-T%(TASKID)s" % self.env

        # FIXME! use tempfile and upload log when process ends.
        log = logging.getLogger('rhts_task')
        twmisc.twisted_logging(log, level=logging.WARNING)
        ll = self.env.get('BEAH_TASK_LOG', "warning")
        log.setLevel(str2log_level(ll))
        make_log_handler(log, LOG_PATH, "rhts_task_%s.log" % (taskid,),
                syslog=True,
                console=self.env.get('BEAH_TASK_CONSOLE', False))

        # parse task's metadata:
        try:
            from rhts import testinfo
            ti = testinfo.parse_file(os.path.join(self.env['TESTPATH'], 'testinfo.desc'), raise_errors=False)
        except:
            log.error("Error in tasks metadata: %s" % format_exc())
            ti = None
        if ti is not None:
            for k,v in getattr(ti, 'environment', {}).iteritems():
                self.env.setdefault(k, v)
            for o in getattr(ti, 'options', []):
                opt_lower = o.lower()
                if opt_lower[0] == '-':
                    opt_lower = opt_lower[1:]
                    value = ''
                else:
                    value = 'yes'
                if opt_lower.startswith('compatible'):
                    self.env.setdefault('RHTS_OPTION_COMPATIBLE', value)
                elif opt_lower.startswith('compatservice'):
                    self.env.setdefault('RHTS_OPTION_COMPAT_SERVICE', value)
                elif opt_lower.startswith('strongeravc'):
                    self.env.setdefault('RHTS_OPTION_STRONGER_AVC', value)

        # update log level if necessary:
        ll2 = self.env.get('BEAH_TASK_LOG', ll)
        if ll2 != ll:
            log.setLevel(str2log_level(ll2))

        # No point in storing everything in one big file. Use one file per task
        rt = runtimes.ShelveRuntime(RUNTIME_PATHNAME_TEMPLATE % taskid)
        self.__files = runtimes.TypeDict(rt, 'files')

        # FIXME: use configurable range of ports.
        self.variables = runtimes.TypeDict(rt, 'variables')
        port = self.variables.setdefault('port', int(self.env.get('RHTS_PORT', random.randint(7080, 7099))))
        self.variables.setdefault('nohup', False)
        self.variables.setdefault('has_result', False)


        self.env.setdefault('DIGEST_METHOD', 'no_digest') # use no digests by default... Seems waste of time on localhost.
        self.env.setdefault('TESTORDER', '123') # FIXME: More sensible default

        # update defaults:
        for k, v in self.ENV_DEFAULTS.iteritems():
            self.env.setdefault(k, v)

        # provide sensible defaults for selected system env.variables:
        self.env.setdefault('HOME', '/root')
        self.env.setdefault('LANG', 'en_US.UTF-8')

        # FIXME: should any checks go here?
        # e.g. does Makefile PURPOSE exist? try running `make testinfo.desc`? ...
        self.controller = ControllerLink(self)
        stdio.StandardIO(self.controller)
        self.task = RHTSTask(self)
        self.server = RHTSServer(self)
        # If IPv6 has not been disabled, attempt to listen on IPv6 
        # otherwise fall back to IPv4
        def listen_tcp(interface):
            return reactor.listenTCP(port, self.server, 
                                     interface=interface)
        conf = beah.config.get_conf('beah')
        if not parse_bool(conf.get('DEFAULT', 'IPV6_DISABLED')):
            try:
                listen_tcp('::1')
                self.env['RESULT_SERVER'] = '[::1]:%s' % port
            except CannotListenError:
                listen_tcp('127.0.0.1')
                self.env['RESULT_SERVER'] = '127.0.0.1:%s' % port
        else:
            listen_tcp('127.0.0.1')
            self.env['RESULT_SERVER'] = '127.0.0.1:%s' % port
        # save env:
        env_file = ENV_PATHNAME_TEMPLATE % taskid
        self.env['RHTS_ENV'] = env_file
        jsonenv.export_env(env_file, self.env)

        # Execute rhts-test-runner.sh
        self.server_started()