Merge "Add recent/detail openstack-health api."
This commit is contained in:
commit
9f95c43f97
|
@ -276,25 +276,40 @@ def get_runs_by_run_metadata_key(run_metadata_key, value):
|
||||||
@app.route('/runs/key/<path:run_metadata_key>/<path:value>/recent',
|
@app.route('/runs/key/<path:run_metadata_key>/<path:value>/recent',
|
||||||
methods=['GET'])
|
methods=['GET'])
|
||||||
def get_recent_runs(run_metadata_key, value):
|
def get_recent_runs(run_metadata_key, value):
|
||||||
|
runs = get_recent_runs_data(run_metadata_key, value)
|
||||||
|
return jsonify(runs)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/runs/key/<path:run_metadata_key>/<path:value>/recent/detail',
|
||||||
|
methods=['GET'])
|
||||||
|
def get_recent_runs_detail(run_metadata_key, value):
|
||||||
|
runs = get_recent_runs_data(run_metadata_key, value, detail=True)
|
||||||
|
return jsonify(runs)
|
||||||
|
|
||||||
|
|
||||||
|
def get_recent_runs_data(run_metadata_key, value, detail=False):
|
||||||
num_runs = flask.request.args.get('num_runs', 10)
|
num_runs = flask.request.args.get('num_runs', 10)
|
||||||
with session_scope() as session:
|
with session_scope() as session:
|
||||||
results = api.get_recent_runs_by_key_value_metadata(
|
results = api.get_recent_runs_by_key_value_metadata(
|
||||||
run_metadata_key, value, num_runs, session)
|
run_metadata_key, value, num_runs, session)
|
||||||
runs = []
|
runs = []
|
||||||
for result in results:
|
for result in results:
|
||||||
if result.passes > 0 and result.fails == 0:
|
if detail:
|
||||||
status = 'success'
|
run = result.to_dict()
|
||||||
elif result.fails > 0:
|
|
||||||
status = 'fail'
|
|
||||||
else:
|
else:
|
||||||
continue
|
if result.passes > 0 and result.fails == 0:
|
||||||
|
status = 'success'
|
||||||
|
elif result.fails > 0:
|
||||||
|
status = 'fail'
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
run = {
|
run = {
|
||||||
'id': result.uuid,
|
'id': result.uuid,
|
||||||
'status': status,
|
'status': status,
|
||||||
'start_date': result.run_at.isoformat(),
|
'start_date': result.run_at.isoformat(),
|
||||||
'link': result.artifacts,
|
'link': result.artifacts,
|
||||||
}
|
}
|
||||||
|
|
||||||
run_meta = api.get_run_metadata(result.uuid, session)
|
run_meta = api.get_run_metadata(result.uuid, session)
|
||||||
for meta in run_meta:
|
for meta in run_meta:
|
||||||
|
@ -302,7 +317,7 @@ def get_recent_runs(run_metadata_key, value):
|
||||||
run['build_name'] = meta.value
|
run['build_name'] = meta.value
|
||||||
break
|
break
|
||||||
runs.append(run)
|
runs.append(run)
|
||||||
return jsonify(runs)
|
return runs
|
||||||
|
|
||||||
|
|
||||||
@app.route('/tests/recent/<string:status>', methods=['GET'])
|
@app.route('/tests/recent/<string:status>', methods=['GET'])
|
||||||
|
|
|
@ -768,6 +768,36 @@ class TestRestAPI(base.TestCase):
|
||||||
}]
|
}]
|
||||||
self.assertEqual(expected_res, response_data)
|
self.assertEqual(expected_res, response_data)
|
||||||
|
|
||||||
|
@mock.patch('subunit2sql.db.api.get_run_metadata',
|
||||||
|
return_value=[models.RunMetadata(key='build_name',
|
||||||
|
value='job')])
|
||||||
|
@mock.patch('subunit2sql.db.api.get_recent_runs_by_key_value_metadata',
|
||||||
|
return_value=[
|
||||||
|
models.Run(uuid='uuid', run_at=timestamp_a,
|
||||||
|
artifacts='http://fake_url', passes=2, fails=0,
|
||||||
|
id='a_id', run_time=174, skips=10),
|
||||||
|
])
|
||||||
|
def test_get_recent_runs_detail(self, api_mock, api_meta_mock):
|
||||||
|
api.Session = mock.MagicMock()
|
||||||
|
res = self.app.get('/runs/key/a_key/a_value/recent/detail')
|
||||||
|
self.assertEqual(200, res.status_code)
|
||||||
|
api_mock.assert_called_once_with('a_key', 'a_value',
|
||||||
|
10, api.Session())
|
||||||
|
response_data = json.loads(res.data.decode('utf-8'))
|
||||||
|
format_time = timestamp_a.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
||||||
|
expected_res = [{
|
||||||
|
u'artifacts': u'http://fake_url',
|
||||||
|
u'id': u'a_id',
|
||||||
|
u'build_name': u'job',
|
||||||
|
u'fails': 0,
|
||||||
|
u'passes': 2,
|
||||||
|
u'skips': 10,
|
||||||
|
u'run_at': format_time,
|
||||||
|
u'run_time': 174,
|
||||||
|
u'uuid': u'uuid'
|
||||||
|
}]
|
||||||
|
self.assertEqual(expected_res, response_data)
|
||||||
|
|
||||||
@mock.patch('subunit2sql.db.api.get_recent_failed_runs',
|
@mock.patch('subunit2sql.db.api.get_recent_failed_runs',
|
||||||
return_value=['a_convincing_id'])
|
return_value=['a_convincing_id'])
|
||||||
@mock.patch('subunit2sql.db.api.get_test_runs_by_status_for_run_ids',
|
@mock.patch('subunit2sql.db.api.get_test_runs_by_status_for_run_ids',
|
||||||
|
|
Loading…
Reference in New Issue