Merge "Add job name to recent failed test results"
This commit is contained in:
commit
7e51dd3a08
|
@ -531,35 +531,40 @@ def get_recent_test_status(status):
|
|||
def _get_recent(status):
|
||||
with session_scope() as session:
|
||||
failed_runs = api.get_recent_failed_runs(num_runs, session)
|
||||
global classifier
|
||||
if classifier:
|
||||
for run in failed_runs:
|
||||
metadata = api.get_run_metadata(run, session=session)
|
||||
short_uuid = None
|
||||
change_num = None
|
||||
patch_num = None
|
||||
for meta in metadata:
|
||||
if meta.key == 'build_short_uuid':
|
||||
short_uuid = meta.value
|
||||
elif meta.key == 'build_change':
|
||||
change_num = meta.value
|
||||
elif meta.key == 'build_patchset':
|
||||
patch_num = meta.value
|
||||
# NOTE(mtreinish): If the required metadata fields aren't
|
||||
# present skip ES lookup
|
||||
if not short_uuid or not change_num or not patch_num:
|
||||
continue
|
||||
query_thread = threading.Thread(
|
||||
target=_populate_bug_dict, args=(change_num, patch_num,
|
||||
short_uuid, run))
|
||||
query_threads.append(query_thread)
|
||||
query_thread.start()
|
||||
job_names = {}
|
||||
for run in failed_runs:
|
||||
metadata = api.get_run_metadata(run, session=session)
|
||||
short_uuid = None
|
||||
change_num = None
|
||||
patch_num = None
|
||||
for meta in metadata:
|
||||
if meta.key == 'build_short_uuid':
|
||||
short_uuid = meta.value
|
||||
elif meta.key == 'build_change':
|
||||
change_num = meta.value
|
||||
elif meta.key == 'build_patchset':
|
||||
patch_num = meta.value
|
||||
elif meta.key == 'build_name':
|
||||
job_names[run] = meta.value
|
||||
global classifier
|
||||
if classifier:
|
||||
# NOTE(mtreinish): If the required metadata fields
|
||||
# aren't present skip ES lookup
|
||||
if not short_uuid or not change_num or not patch_num:
|
||||
continue
|
||||
query_thread = threading.Thread(
|
||||
target=_populate_bug_dict, args=(change_num,
|
||||
patch_num,
|
||||
short_uuid, run))
|
||||
query_threads.append(query_thread)
|
||||
query_thread.start()
|
||||
test_runs = api.get_test_runs_by_status_for_run_ids(
|
||||
status, failed_runs, session=session, include_run_id=True)
|
||||
output = []
|
||||
for run in test_runs:
|
||||
run['start_time'] = run['start_time'].isoformat()
|
||||
run['stop_time'] = run['stop_time'].isoformat()
|
||||
run['job_name'] = job_names.get(run['uuid'])
|
||||
output.append(run)
|
||||
for thread in query_threads:
|
||||
thread.join()
|
||||
|
|
|
@ -864,9 +864,18 @@ class TestRestAPI(base.TestCase):
|
|||
'link': u'fake_url',
|
||||
'start_time': timestamp_a,
|
||||
'stop_time': timestamp_b,
|
||||
'uuid': 'a_convincing_id',
|
||||
}
|
||||
])
|
||||
def test_get_recent_test_failures_no_es(self, db_mock, recent_mock):
|
||||
@mock.patch('subunit2sql.db.api.get_run_metadata',
|
||||
return_value=[
|
||||
models.RunMetadata(key='build_short_uuid', value='abcd'),
|
||||
models.RunMetadata(key='build_change', value='1234'),
|
||||
models.RunMetadata(key='build_patchset', value='3'),
|
||||
models.RunMetadata(key='build_name', value='job_name_foo'),
|
||||
])
|
||||
def test_get_recent_test_failures_no_es(self, meta_mock,
|
||||
db_mock, recent_mock):
|
||||
setup_mock = mock.patch('openstack_health.api.setup')
|
||||
setup_mock.start()
|
||||
self.addCleanup(setup_mock.stop)
|
||||
|
@ -883,10 +892,12 @@ class TestRestAPI(base.TestCase):
|
|||
expected_resp = {
|
||||
'bugs': {},
|
||||
'test_runs': [{
|
||||
'job_name': 'job_name_foo',
|
||||
'test_id': u'fake_test',
|
||||
'link': u'fake_url',
|
||||
'start_time': timestamp_a.isoformat(),
|
||||
'stop_time': timestamp_b.isoformat(),
|
||||
'uuid': 'a_convincing_id',
|
||||
}]}
|
||||
self.assertEqual(expected_resp, response_data)
|
||||
|
||||
|
@ -899,6 +910,7 @@ class TestRestAPI(base.TestCase):
|
|||
'link': u'fake_url',
|
||||
'start_time': timestamp_a,
|
||||
'stop_time': timestamp_b,
|
||||
'uuid': 'a_convincing_id',
|
||||
}
|
||||
])
|
||||
@mock.patch('subunit2sql.db.api.get_run_metadata',
|
||||
|
@ -906,6 +918,7 @@ class TestRestAPI(base.TestCase):
|
|||
models.RunMetadata(key='build_short_uuid', value='abcd'),
|
||||
models.RunMetadata(key='build_change', value='1234'),
|
||||
models.RunMetadata(key='build_patchset', value='3'),
|
||||
models.RunMetadata(key='build_name', value='fake_job'),
|
||||
])
|
||||
def test_get_recent_test_failures_with_es(self, meta_mock, db_mock,
|
||||
recent_mock):
|
||||
|
@ -927,10 +940,12 @@ class TestRestAPI(base.TestCase):
|
|||
expected_resp = {
|
||||
'bugs': {'a_convincing_id': ['12345']},
|
||||
'test_runs': [{
|
||||
'job_name': 'fake_job',
|
||||
'test_id': u'fake_test',
|
||||
'link': u'fake_url',
|
||||
'start_time': timestamp_a.isoformat(),
|
||||
'stop_time': timestamp_b.isoformat(),
|
||||
'uuid': 'a_convincing_id',
|
||||
}]}
|
||||
self.assertEqual(expected_resp, response_data)
|
||||
|
||||
|
@ -943,12 +958,14 @@ class TestRestAPI(base.TestCase):
|
|||
'link': u'fake_url',
|
||||
'start_time': timestamp_a,
|
||||
'stop_time': timestamp_b,
|
||||
'uuid': 'a_convincing_id',
|
||||
}
|
||||
])
|
||||
@mock.patch('subunit2sql.db.api.get_run_metadata',
|
||||
return_value=[
|
||||
models.RunMetadata(key='build_short_uuid', value='abcd'),
|
||||
models.RunMetadata(key='build_patchset', value='3'),
|
||||
models.RunMetadata(key='build_name', value='job_name_foo'),
|
||||
])
|
||||
def test_get_recent_test_failures_with_missing_meta(self, meta_mock,
|
||||
db_mock, recent_mock):
|
||||
|
@ -971,10 +988,60 @@ class TestRestAPI(base.TestCase):
|
|||
expected_resp = {
|
||||
'bugs': {},
|
||||
'test_runs': [{
|
||||
'job_name': 'job_name_foo',
|
||||
'test_id': u'fake_test',
|
||||
'link': u'fake_url',
|
||||
'start_time': timestamp_a.isoformat(),
|
||||
'stop_time': timestamp_b.isoformat(),
|
||||
'uuid': 'a_convincing_id',
|
||||
}]}
|
||||
self.assertEqual(expected_resp, response_data)
|
||||
|
||||
@mock.patch('subunit2sql.db.api.get_recent_failed_runs',
|
||||
return_value=['a_convincing_id'])
|
||||
@mock.patch('subunit2sql.db.api.get_test_runs_by_status_for_run_ids',
|
||||
return_value=[
|
||||
{
|
||||
'test_id': u'fake_test',
|
||||
'link': u'fake_url',
|
||||
'start_time': timestamp_a,
|
||||
'stop_time': timestamp_b,
|
||||
'uuid': 'a_convincing_id',
|
||||
}
|
||||
])
|
||||
@mock.patch('subunit2sql.db.api.get_run_metadata',
|
||||
return_value=[
|
||||
models.RunMetadata(key='build_short_uuid', value='abcd'),
|
||||
models.RunMetadata(key='build_patchset', value='3'),
|
||||
])
|
||||
def test_get_recent_test_failures_with_missing_build_name(self, meta_mock,
|
||||
db_mock,
|
||||
recent_mock):
|
||||
setup_mock = mock.patch('openstack_health.api.setup')
|
||||
setup_mock.start()
|
||||
self.addCleanup(setup_mock.stop)
|
||||
api.region = mock.MagicMock()
|
||||
api.region.cache_on_arguments = mock.MagicMock()
|
||||
api.region.cache_on_arguments.return_value = lambda x: x
|
||||
api.classifier = mock.MagicMock()
|
||||
api.classifier.classify = mock.MagicMock()
|
||||
api.classifier.classify.return_value = ['12345']
|
||||
res = self.app.get('/tests/recent/fail')
|
||||
self.assertEqual(200, res.status_code)
|
||||
self.assertEqual(0, api.classifier.classify.call_count)
|
||||
db_mock.assert_called_once_with('fail', ['a_convincing_id'],
|
||||
session=api.Session(),
|
||||
include_run_id=True)
|
||||
response_data = json.loads(res.data.decode('utf-8'))
|
||||
expected_resp = {
|
||||
'bugs': {},
|
||||
'test_runs': [{
|
||||
'job_name': None,
|
||||
'test_id': u'fake_test',
|
||||
'link': u'fake_url',
|
||||
'start_time': timestamp_a.isoformat(),
|
||||
'stop_time': timestamp_b.isoformat(),
|
||||
'uuid': 'a_convincing_id',
|
||||
}]}
|
||||
self.assertEqual(expected_resp, response_data)
|
||||
|
||||
|
|
Loading…
Reference in New Issue