Ejemplo n.º 1
0
    def _safe_call(self, fn, *args, **kwargs):
        class update_timestamps:
            '''Context manager to set the start and finish timestamps.'''

            # We use `this` to refer to the update_timestamps object, because
            # we don't want to masquerade the self argument of our containing
            # function
            def __enter__(this):
                if fn.__name__ != 'poll':
                    stage = self._current_stage
                    self._timestamps[f'{stage}_start'] = time.time()

            def __exit__(this, exc_type, exc_value, traceback):
                stage = self._current_stage
                self._timestamps[f'{stage}_finish'] = time.time()
                self._timestamps['pipeline_end'] = time.time()

        if fn.__name__ != 'poll':
            self._current_stage = fn.__name__

        try:
            with logging.logging_context(self.check) as logger:
                logger.debug(f'Entering stage: {self._current_stage}')
                with update_timestamps():
                    return fn(*args, **kwargs)

        except ABORT_REASONS:
            self.fail()
            raise
        except BaseException as e:
            self.fail()
            raise TaskExit from e
Ejemplo n.º 2
0
    def cleanup(self, remove_files=False, unload_env=True):
        self._current_stage = 'cleanup'
        with logging.logging_context(check=self._check) as logger:
            logger.debug('entering cleanup stage')
            self._check.cleanup(remove_files, unload_env)

        self._current_stage = 'completed'
Ejemplo n.º 3
0
    def test_logging_context(self):
        rlog.configure_logging(self.logging_config)
        with rlog.logging_context() as logger:
            self.assertIs(logger, rlog.getlogger())
            self.assertIsNot(logger, rlog.null_logger)
            rlog.getlogger().error('error from context')

        self.assertTrue(self.found_in_logfile('reframe'))
        self.assertTrue(self.found_in_logfile('error from context'))
Ejemplo n.º 4
0
    def check_sanity(self):
        # check_sanity() may be overriden by the user tests; we log this phase
        # here then
        self._current_stage = 'sanity'
        with logging.logging_context(check=self._check) as logger:
            logger.debug('entering sanity checking stage')
            ret = self._check.check_sanity()

        return ret
Ejemplo n.º 5
0
def test_logging_context(default_exec_ctx, logfile):
    rlog.configure_logging(rt.runtime().site_config)
    with rlog.logging_context() as logger:
        assert logger is rlog.getlogger()
        assert logger is not rlog.null_logger
        rlog.getlogger().error('error from context')

    assert _found_in_logfile('reframe', logfile)
    assert _found_in_logfile('error from context', logfile)
Ejemplo n.º 6
0
    def test_logging_context(self):
        rlog.configure_logging(self.logging_config)
        with rlog.logging_context() as logger:
            assert logger is rlog.getlogger()
            assert logger is not rlog.null_logger
            rlog.getlogger().error('error from context')

        assert self.found_in_logfile('reframe')
        assert self.found_in_logfile('error from context')
Ejemplo n.º 7
0
def test_logging_context_check(default_exec_ctx, logfile, fake_check):
    rlog.configure_logging(rt.runtime().site_config)
    with rlog.logging_context(check=fake_check):
        rlog.getlogger().error('error from context')

    rlog.getlogger().error('error outside context')
    assert _found_in_logfile(f'_FakeCheck: {sys.argv[0]}: error from context',
                             logfile)
    assert _found_in_logfile(f'reframe: {sys.argv[0]}: error outside context',
                             logfile)
Ejemplo n.º 8
0
    def test_logging_context_check(self):
        rlog.configure_logging(self.logging_config)
        with rlog.logging_context(check=self.check):
            rlog.getlogger().error('error from context')

        rlog.getlogger().error('error outside context')
        assert self.found_in_logfile('_FakeCheck: %s: error from context' %
                                     sys.argv[0])
        assert self.found_in_logfile('reframe: %s: error outside context' %
                                     sys.argv[0])
Ejemplo n.º 9
0
    def test_logging_context_check(self):
        rlog.configure_logging(self.logging_config)
        with rlog.logging_context(check=self.check):
            rlog.getlogger().error('error from context')

        rlog.getlogger().error('error outside context')

        self.assertTrue(
            self.found_in_logfile('random_check: error from context'))
        self.assertTrue(
            self.found_in_logfile('reframe: error outside context'))
Ejemplo n.º 10
0
def test_logging_context_error(default_exec_ctx, logfile):
    rlog.configure_logging(rt.runtime().site_config)
    try:
        with rlog.logging_context(level=rlog.ERROR):
            raise ReframeError('error from context')

        pytest.fail('logging_context did not propagate the exception')
    except ReframeError:
        pass

    assert _found_in_logfile('reframe', logfile)
    assert _found_in_logfile('error from context', logfile)
Ejemplo n.º 11
0
 def _safe_call(self, fn, *args, **kwargs):
     self._current_stage = fn.__name__
     try:
         with logging.logging_context(self._check) as logger:
             logger.debug('entering stage: %s' % self._current_stage)
             return fn(*args, **kwargs)
     except ABORT_REASONS:
         self.fail()
         raise
     except BaseException as e:
         self.fail()
         raise TaskExit from e
Ejemplo n.º 12
0
    def test_logging_context_error(self):
        rlog.configure_logging(self.logging_config)
        try:
            with rlog.logging_context(level=rlog.ERROR):
                raise ReframeError('error from context')

            self.fail('logging_context did not propagate the exception')
        except ReframeError:
            pass

        self.assertTrue(self.found_in_logfile('reframe'))
        self.assertTrue(self.found_in_logfile('error from context'))
Ejemplo n.º 13
0
 def check_performance(self):
     # check_performance() may be overriden by the user tests; we log this
     # phase here then
     self._current_stage = 'performance'
     try:
         # FIXME: the logic has become a bit ugly here in order to support
         # both sanity syntaxes. It should be simplified again as soon as
         # the old syntax is dropped.
         with logging.logging_context(check=self._check) as logger:
             logger.debug('entering performance checking stage')
             ret = self._check.check_performance()
     except SanityError:
         # This is to handle the new sanity systax
         if self._check.strict_check:
             raise
         else:
             return True
     else:
         return True if not self._check.strict_check else ret
Ejemplo n.º 14
0
    def _safe_call(self, fn, *args, **kwargs):
        class update_timestamps:
            '''Context manager to set the start and finish timestamps.'''

            # We use `this` to refer to the update_timestamps object, because
            # we don't want to masquerade the self argument of our containing
            # function
            def __enter__(this):
                if fn.__name__ not in ('poll', 'run_complete',
                                       'compile_complete'):
                    stage = self._current_stage
                    self._timestamps[f'{stage}_start'] = time.time()

            def __exit__(this, exc_type, exc_value, traceback):
                stage = self._current_stage
                self._timestamps[f'{stage}_finish'] = time.time()
                self._timestamps['pipeline_end'] = time.time()

        if fn.__name__ not in ('poll', 'run_complete', 'compile_complete'):
            self._current_stage = fn.__name__

        try:
            with logging.logging_context(self.check) as logger:
                logger.debug(f'Entering stage: {self._current_stage}')
                with update_timestamps():
                    # Pick the configuration of the current partition
                    with runtime.temp_config(self.testcase.partition.fullname):
                        return fn(*args, **kwargs)
        except SkipTestError as e:
            if not self.succeeded:
                # Only skip a test if it hasn't finished yet;
                # This practically ignores skipping during the cleanup phase
                self.skip()
                raise TaskExit from e
        except ABORT_REASONS:
            self.fail()
            raise
        except BaseException as e:
            self.fail()
            raise TaskExit from e
Ejemplo n.º 15
0
 def run(self):
     self._current_stage = 'run'
     with logging.logging_context(check=self._check) as logger:
         logger.debug('entering running stage')
         self._check.run()
Ejemplo n.º 16
0
 def wait(self):
     self._current_stage = 'wait'
     with logging.logging_context(check=self._check) as logger:
         logger.debug('entering waiting stage')
         self._check.wait()
Ejemplo n.º 17
0
 def poll(self):
     with logging.logging_context(check=self._check) as logger:
         logger.debug('polling check')
         ret = self._check.poll()
         return ret
Ejemplo n.º 18
0
 def setup(self, partition, environ, **job_opts):
     self._current_stage = 'setup'
     with logging.logging_context(check=self._check) as logger:
         logger.debug('entering setup stage')
         self._check.setup(partition, environ, **job_opts)
Ejemplo n.º 19
0
 def compile(self):
     self._current_stage = 'compile'
     with logging.logging_context(check=self._check) as logger:
         logger.debug('entering compilation stage')
         self._check.compile()