Esempio n. 1
0
def process_results(results):
    session = api.get_session()
    run_time = results.pop('run_time')
    totals = get_run_totals(results)
    if CONF.run_at:
        run_at = date_parser.parse(CONF.run_at)
    else:
        run_at = None
    db_run = api.create_run(totals['skips'], totals['fails'],
                            totals['success'], run_time, CONF.artifacts,
                            id=CONF.run_id, run_at=run_at, session=session)
    if CONF.run_meta:
        api.add_run_metadata(CONF.run_meta, db_run.id, session)
    for test in results:
        db_test = api.get_test_by_test_id(test, session)
        if not db_test:
            if results[test]['status'] == 'success':
                success = 1
                fails = 0
            elif results[test]['status'] == 'fail':
                fails = 1
                success = 0
            else:
                fails = 0
                success = 0
            run_time = subunit.get_duration(results[test]['start_time'],
                                            results[test]['end_time'])
            db_test = api.create_test(test, (success + fails), success,
                                      fails, run_time,
                                      session)
        else:
            test_values = increment_counts(db_test, results[test])
            # If skipped nothing to update
            if test_values:
                api.update_test(test_values, db_test.id, session)
        test_run = api.create_test_run(db_test.id, db_run.id,
                                       results[test]['status'],
                                       results[test]['start_time'],
                                       results[test]['end_time'],
                                       session)
        if results[test]['metadata']:
            if CONF.test_attr_prefix:
                attrs = results[test]['metadata'].get('attrs')
                test_attr_list = _get_test_attrs_list(attrs)
                test_metadata = api.get_test_metadata(db_test.id, session)
                test_metadata = [(meta.key, meta.value) for meta in
                                 test_metadata]
                if test_attr_list:
                    for attr in test_attr_list:
                        if ('attr', attr) not in test_metadata:
                            test_meta_dict = {'attr': attr}
                            api.add_test_metadata(test_meta_dict, db_test.id,
                                                  sesion=session)
            api.add_test_run_metadata(results[test]['metadata'], test_run.id,
                                      session)
        if results[test]['attachments']:
            api.add_test_run_attachments(results[test]['attachments'],
                                         test_run.id, session)
    session.close()
Esempio n. 2
0
 def test_get_all_test_run_metadata_keys(self):
     run = api.create_run()
     test = api.create_test('fake_test')
     test_run = api.create_test_run(test.id, run.id, 'skip')
     meta_dict = {
         'test_a': 'a',
         'test_a': 'b',
         'test_b': 'a',
         'test_c': 'a',
         'test_d': 'a',
         'test_c': 'b',
     }
     api.add_test_run_metadata(meta_dict, test_run.id)
     keys = api.get_all_test_run_metadata_keys()
     self.assertEqual(sorted(['test_a', 'test_b', 'test_c', 'test_d']),
                      sorted(keys))
Esempio n. 3
0
 def test_get_all_test_run_metadata_keys(self):
     run = api.create_run()
     test = api.create_test('fake_test')
     test_run = api.create_test_run(test.id, run.id, 'skip')
     meta_dict = {
         'test_a': 'a',
         'test_a': 'b',
         'test_b': 'a',
         'test_c': 'a',
         'test_d': 'a',
         'test_c': 'b',
     }
     api.add_test_run_metadata(meta_dict, test_run.id)
     keys = api.get_all_test_run_metadata_keys()
     self.assertEqual(sorted(['test_a', 'test_b', 'test_c', 'test_d']),
                      sorted(keys))
Esempio n. 4
0
 def test_get_test_runs_dicts_with_meta(self):
     run = api.create_run()
     test_a = api.create_test('fake_test')
     test_run = api.create_test_run(test_a.id, run.id, 'success',
                                    datetime.datetime.utcnow(),
                                    datetime.datetime.utcnow())
     run_meta = {
         'key_a': 'value_b',
         'key_b': 'value_a',
         'attrs': 'test,smoke,notatest',
     }
     api.add_test_run_metadata(run_meta, test_run.id)
     test_run_dict = api.get_tests_run_dicts_from_run_id(run.uuid)
     self.assertEqual(3, len(test_run_dict['fake_test']['metadata']))
     for meta in run_meta:
         self.assertIn(meta, test_run_dict['fake_test']['metadata'])
         self.assertEqual(run_meta[meta],
                          test_run_dict['fake_test']['metadata'][meta])
Esempio n. 5
0
 def test_delete_old_test_runs(self):
     run_a = api.create_run()
     run_b = api.create_run()
     test = api.create_test('fake_test')
     test_run_a = api.create_test_run(test.id, run_a.id, 'fail',
                                      start_time=datetime.datetime(
                                          1914, 6, 28, 10, 45, 0))
     test_run_b = api.create_test_run(test.id, run_b.id, 'fail',
                                      start_time=datetime.datetime.utcnow())
     api.add_test_run_metadata({'key': 'value'}, test_run_b.id)
     api.add_test_run_metadata({'key': 'not_so_much_a_value'},
                               test_run_a.id)
     api.delete_old_test_runs()
     test_runs = api.get_all_test_runs()
     self.assertEqual(1, len(test_runs))
     self.assertEqual(test_run_b.id, test_runs[0].id)
     self.assertEqual(1, len(api.get_test_run_metadata(test_run_b.id)))
     self.assertEqual(0, len(api.get_test_run_metadata(test_run_a.id)))
Esempio n. 6
0
 def test_get_test_runs_dicts_with_meta(self):
     run = api.create_run()
     test_a = api.create_test('fake_test')
     test_run = api.create_test_run(test_a.id, run.id, 'success',
                                    datetime.datetime.utcnow(),
                                    datetime.datetime.utcnow())
     run_meta = {
         'key_a': 'value_b',
         'key_b': 'value_a',
         'attrs': 'test,smoke,notatest',
     }
     api.add_test_run_metadata(run_meta, test_run.id)
     test_run_dict = api.get_tests_run_dicts_from_run_id(run.uuid)
     self.assertEqual(3, len(test_run_dict['fake_test']['metadata']))
     for meta in run_meta:
         self.assertIn(meta, test_run_dict['fake_test']['metadata'])
         self.assertEqual(run_meta[meta],
                          test_run_dict['fake_test']['metadata'][meta])
Esempio n. 7
0
def process_results(results):
    session = api.get_session()
    run_time = results.pop('run_time')
    totals = get_run_totals(results)
    db_run = api.create_run(totals['skips'], totals['fails'],
                            totals['success'], run_time, CONF.artifacts,
                            id=CONF.run_id, session=session)
    if CONF.run_meta:
        api.add_run_metadata(CONF.run_meta, db_run.id, session)
    for test in results:
        db_test = api.get_test_by_test_id(test, session)
        if not db_test:
            if results[test]['status'] == 'success':
                success = 1
                fails = 0
            elif results[test]['status'] == 'fail':
                fails = 1
                success = 0
            else:
                fails = 0
                success = 0
            run_time = subunit.get_duration(results[test]['start_time'],
                                            results[test]['end_time'])
            db_test = api.create_test(test, (success + fails), success,
                                      fails, run_time,
                                      session)
        else:
            test_values = increment_counts(db_test, results[test])
            # If skipped nothing to update
            if test_values:
                api.update_test(test_values, db_test.id, session)
        test_run = api.create_test_run(db_test.id, db_run.id,
                                       results[test]['status'],
                                       results[test]['start_time'],
                                       results[test]['end_time'],
                                       session)
        if results[test]['metadata']:
            api.add_test_run_metadata(results[test]['metadata'], test_run.id,
                                      session)
        if results[test]['attachments']:
            api.add_test_run_attachments(results[test]['attachment'],
                                         test_run.id, session)
    session.close()
Esempio n. 8
0
 def _handle_test(self, test_dict):
     start, end = test_dict.pop('timestamps')
     if test_dict['status'] == 'exists' or None in (start, end):
         return
     elif test_dict['id'] == 'process-returncode':
         return
     session = self.session_factory()
     try:
         # Update the run counts
         if test_dict['status'] not in self.totals:
             self.totals[test_dict['status']] = 1
         else:
             self.totals[test_dict['status']] += 1
         values = {}
         if test_dict['status'] in ('success', 'xfail'):
             values['passes'] = self.totals['success']
         elif test_dict['status'] in ('fail', 'uxsuccess'):
             values['fails'] = self.totals['fail']
         elif test_dict['status'] == 'skip':
             values['skips'] = self.totals['skip']
         db_api.update_run(values, self.run.id, session=session)
         # Update the test totals
         db_test = self._update_test(test_dict, session, start, end)
         # Add the test run
         test_run = db_api.create_test_run(db_test.id, self.run.id,
                                           test_dict['status'], start, end,
                                           session)
         metadata = {}
         attrs = self._get_attrs(test_dict['id'])
         if attrs:
             metadata['attrs'] = attrs
         if test_dict.get('tags', None):
             metadata['tags'] = ",".join(test_dict['tags'])
         if metadata:
             db_api.add_test_run_metadata(metadata, test_run.id, session)
         # TODO(mtreinish): Add attachments support to the DB.
         session.close()
     except Exception:
         session.rollback()
         raise
Esempio n. 9
0
 def test_delete_old_test_runs(self):
     run_a = api.create_run()
     run_b = api.create_run()
     test = api.create_test('fake_test')
     test_run_a = api.create_test_run(test.id,
                                      run_a.id,
                                      'fail',
                                      start_time=datetime.datetime(
                                          1914, 6, 28, 10, 45, 0))
     test_run_b = api.create_test_run(test.id,
                                      run_b.id,
                                      'fail',
                                      start_time=datetime.datetime.utcnow())
     api.add_test_run_metadata({'key': 'value'}, test_run_b.id)
     api.add_test_run_metadata({'key': 'not_so_much_a_value'},
                               test_run_a.id)
     api.delete_old_test_runs()
     test_runs = api.get_all_test_runs()
     self.assertEqual(1, len(test_runs))
     self.assertEqual(test_run_b.id, test_runs[0].id)
     self.assertEqual(1, len(api.get_test_run_metadata(test_run_b.id)))
     self.assertEqual(0, len(api.get_test_run_metadata(test_run_a.id)))
Esempio n. 10
0
def process_results(results, run_at=None, artifacts=None, run_id=None,
                    run_meta=None, test_attr_prefix=None):
    """Insert converted subunit data into the database.

    Allows for run-specific information to be passed in via kwargs,
    checks CONF if no run-specific information is supplied.

    :param results: subunit stream to be inserted
    :param run_at: Optional time at which the run was started.
    :param artifacts: Link to any artifacts from the test run.
    :param run_id: The run id for the new run. Must be unique.
    :param run_meta: Metadata corresponding to the new run.
    :param test_attr_prefix: Optional test attribute prefix.
    """
    run_at = _override_conf(run_at, 'run_at')
    artifacts = _override_conf(artifacts, 'artifacts')
    run_id = _override_conf(run_id, 'run_id')
    run_meta = _override_conf(run_meta, 'run_meta')
    test_attr_prefix = _override_conf(test_attr_prefix, 'test_attr_prefix')

    if run_at:
        if not isinstance(run_at, datetime.datetime):
            run_at = date_parser.parse(run_at)
    else:
        run_at = None
    session = api.get_session()
    run_time = results.pop('run_time')
    totals = get_run_totals(results)
    db_run = api.create_run(totals['skips'], totals['fails'],
                            totals['success'], run_time, artifacts,
                            id=run_id, run_at=run_at, session=session)
    if run_meta:
        api.add_run_metadata(run_meta, db_run.id, session)
    for test in results:
        db_test = api.get_test_by_test_id(test, session)
        if not db_test:
            if results[test]['status'] in ['success', 'xfail']:
                success = 1
                fails = 0
            elif results[test]['status'] in ['fail', 'uxsuccess']:
                fails = 1
                success = 0
            else:
                fails = 0
                success = 0
            run_time = subunit.get_duration(results[test]['start_time'],
                                            results[test]['end_time'])
            db_test = api.create_test(test, (success + fails), success,
                                      fails, run_time,
                                      session)
        else:
            test_values = increment_counts(db_test, results[test])
            # If skipped nothing to update
            if test_values:
                api.update_test(test_values, db_test.id, session)
        test_run = api.create_test_run(db_test.id, db_run.id,
                                       results[test]['status'],
                                       results[test]['start_time'],
                                       results[test]['end_time'],
                                       session)
        if results[test]['metadata']:
            if test_attr_prefix:
                attrs = results[test]['metadata'].get('attrs')
                test_attr_list = _get_test_attrs_list(attrs)
                test_metadata = api.get_test_metadata(db_test.id, session)
                test_metadata = [(meta.key, meta.value) for meta in
                                 test_metadata]
                if test_attr_list:
                    for attr in test_attr_list:
                        if CONF.remove_test_attr_prefix:
                            normalized_attr = attr[len(
                                CONF.test_attr_prefix):]
                        else:
                            normalized_attr = attr
                        if ('attr', normalized_attr) not in test_metadata:
                            test_meta_dict = {'attr': normalized_attr}
                            api.add_test_metadata(test_meta_dict, db_test.id,
                                                  session=session)
            api.add_test_run_metadata(results[test]['metadata'], test_run.id,
                                      session)
        if results[test]['attachments']:
            api.add_test_run_attachments(results[test]['attachments'],
                                         test_run.id, session)
    session.close()
    return db_run