Ejemplo n.º 1
0
    def _add_message(self, test, err=None, status=None):
        data = {'status': status, 'time_taken': self.taken}
        data['title'], data['description'], data['duration'] = \
            nose_utils.get_description(test)
        if err:
            exc_type, exc_value, exc_traceback = err
            data['step'], data['message'] = None, u''
            if not status == 'error':
                data['step'], data['message'] = \
                    nose_utils.format_failure_message(exc_value)
            data['traceback'] = u''
        else:
            data['step'], data['message'] = None, u''
            data['traceback'] = u''

        session = engine.get_session()

        with session.begin(subtransactions=True):

            if isinstance(test, ContextSuite):
                for sub_test in test._tests:
                    data['title'], data['description'], data['duration'] = \
                        nose_utils.get_description(test)
                    models.Test.add_result(session, self.test_run_id,
                                           sub_test.id(), data)
            else:
                models.Test.add_result(session, self.test_run_id, test.id(),
                                       data)
Ejemplo n.º 2
0
    def _add_message(
            self, test, err=None, status=None):
        data = {
            'status': status,
            'time_taken': self.taken
        }
        data['title'], data['description'], data['duration'] = \
            nose_utils.get_description(test)
        if err:
            exc_type, exc_value, exc_traceback = err
            data['step'], data['message'] = None, u''
            if not status == 'error':
                data['step'], data['message'] = \
                    nose_utils.format_failure_message(exc_value)
            data['traceback'] = u''
        else:
            data['step'], data['message'] = None, u''
            data['traceback'] = u''

        session = engine.get_session()

        with session.begin(subtransactions=True):

            if isinstance(test, ContextSuite):
                for sub_test in test._tests:
                    data['title'], data['description'], data['duration'] = \
                        nose_utils.get_description(test)
                    models.Test.add_result(
                        session, self.test_run_id, sub_test.id(), data)
            else:
                models.Test.add_result(
                    session, self.test_run_id, test.id(), data)
Ejemplo n.º 3
0
 def get_test_results(cls):
     session = engine.get_session()
     test_runs = session.query(cls). \
         options(joinedload('tests')). \
         order_by(desc(cls.id))
     session.commit()
     session.close()
     return test_runs
Ejemplo n.º 4
0
 def _run_tests(self, test_run_id, cluster_id, argv_add):
     session = engine.get_session()
     try:
         nose_test_runner.SilentTestProgram(
             addplugins=[nose_storage_plugin.StoragePlugin(
                 test_run_id, str(cluster_id))],
             exit=False,
             argv=['ostf_tests'] + argv_add)
         self._named_threads.pop(int(test_run_id), None)
     except Exception, e:
         LOG.exception('Test run: %s\n', test_run_id)
Ejemplo n.º 5
0
 def afterImport(self, filename, module):
     module = __import__(module, fromlist=[module])
     LOG.info('Inspecting %s', filename)
     if hasattr(module, '__profile__'):
         session = engine.get_session()
         with session.begin(subtransactions=True):
             LOG.info('%s discovered.', module.__name__)
             test_set = models.TestSet(**module.__profile__)
             test_set = session.merge(test_set)
             session.add(test_set)
             self.test_sets[test_set.id] = test_set
Ejemplo n.º 6
0
    def _clean_up(self, test_run_id, external_id, cleanup):
        session = engine.get_session()
        try:
            module_obj = __import__(cleanup, -1)

            os.environ['NAILGUN_HOST'] = str(conf.nailgun.host)
            os.environ['NAILGUN_PORT'] = str(conf.nailgun.port)
            os.environ['CLUSTER_ID'] = str(external_id)

            module_obj.cleanup.cleanup()

        except Exception:
            LOG.exception('EXCEPTION IN CLEANUP')

        finally:
            models.TestRun.update_test_run(
                session, test_run_id, status='finished')
Ejemplo n.º 7
0
    def kill(self, test_run_id, cluster_id, cleanup=None):
        session = engine.get_session()
        if test_run_id in self._named_threads:

            self._named_threads[test_run_id].terminate()
            self._named_threads.pop(test_run_id, None)

            if cleanup:
                nose_utils.run_proc(
                    self._clean_up,
                    test_run_id,
                    cluster_id,
                    cleanup)
            else:
                models.TestRun.update_test_run(
                    session, test_run_id, status='finished')

            return True
        return False
Ejemplo n.º 8
0
 def addSuccess(self, test):
     test_id = test.id()
     for test_set_id in self.test_sets.keys():
         if test_set_id in test_id:
             session = engine.get_session()
             with session.begin(subtransactions=True):
                 LOG.info('%s added for %s', test_id, test_set_id)
                 data = dict()
                 data['title'], data['description'], data['duration'] = \
                     nose_utils.get_description(test)
                 old_test_obj = session.query(models.Test).filter_by(
                     name=test_id, test_set_id=test_set_id,
                     test_run_id=None).\
                     update(data, synchronize_session=False)
                 if not old_test_obj:
                     data.update({'test_set_id': test_set_id,
                                  'name': test_id})
                     test_obj = models.Test(**data)
                     session.add(test_obj)
Ejemplo n.º 9
0
 def __init__(self):
     self._named_threads = {}
     session = engine.get_session()
     with session.begin(subtransactions=True):
         storage_utils.update_all_running_test_runs(session)
Ejemplo n.º 10
0
 def before(self, state):
     state.request.session = engine.get_session()
Ejemplo n.º 11
0
 def before(self, state):
     state.request.session = engine.get_session()