[LNT] r308565 - LNT API run roundtrips
Chris Matthews via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 19 17:09:11 PDT 2017
Author: cmatthews
Date: Wed Jul 19 17:09:11 2017
New Revision: 308565
URL: http://llvm.org/viewvc/llvm-project?rev=308565&view=rev
Log:
LNT API run roundtrips
Allow LNT runs to be downloaded from the API in a format that they can
be inserted back into the same or other LNT instances. This can be used
to move runs between LNT instances, or modify them.
I make some changes to the REST API to make the format closer to what we
expect, then ignore some fields (like ID) when importing.
Modified:
lnt/trunk/lnt/server/db/testsuitedb.py
lnt/trunk/lnt/server/ui/api.py
lnt/trunk/tests/server/ui/test_api.py
lnt/trunk/tests/server/ui/test_api_modify.py
Modified: lnt/trunk/lnt/server/db/testsuitedb.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/testsuitedb.py?rev=308565&r1=308564&r2=308565&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/testsuitedb.py (original)
+++ lnt/trunk/lnt/server/db/testsuitedb.py Wed Jul 19 17:09:11 2017
@@ -832,6 +832,9 @@ class TestSuiteDB(object):
# Ignore incoming ids; we will create our own
run_parameters.pop('id', None)
+ # Added by REST API, we will replace as well.
+ run_parameters.pop('order_by', None)
+
# Find the order record.
order, inserted = self._getOrCreateOrder(run_parameters)
Modified: lnt/trunk/lnt/server/ui/api.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/api.py?rev=308565&r1=308564&r2=308565&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/api.py (original)
+++ lnt/trunk/lnt/server/ui/api.py Wed Jul 19 17:09:11 2017
@@ -78,14 +78,6 @@ def add_common_fields(to_update):
to_update.update(common_fields_factory())
-def common_machine_format(machine):
- serializable = machine.__json__()
- del serializable['parameters_data']
- final = machine.parameters.copy()
- final.update(serializable)
- return final
-
-
class Machines(Resource):
"""List all the machines and give summary information."""
method_decorators = [in_db]
@@ -107,15 +99,27 @@ class Machines(Resource):
def common_run_format(run):
serializable_run = run.__json__()
+ del serializable_run['order']
# Replace orders with text order.
- serializable_run['order'] = run.order.name
- # Embed the parameters right into the run dict.
+
+ # Embed the parameters and order right into the run dict.
serializable_run.update(run.parameters)
+ serializable_run.update(dict((item.name, run.order.get_field(item))
+ for item in run.order.fields))
+ serializable_run['order_by'] = ', '.join([f.name for f in run.order.fields])
del serializable_run['machine']
del serializable_run['parameters_data']
return serializable_run
+def common_machine_format(machine):
+ serializable_machine = machine.__json__()
+ # Embed the parameters and order right into the run dict.
+ serializable_machine.update(machine.parameters)
+ del serializable_machine['parameters_data']
+ return serializable_machine
+
+
class Machine(Resource):
"""Detailed results about a particular machine, including runs on it."""
method_decorators = [in_db]
@@ -226,10 +230,10 @@ class Run(Resource):
except sqlalchemy.orm.exc.NoResultFound:
abort(404, msg="Did not find run " + str(run_id))
- full_run['runs'] = [common_run_format(run)]
+ full_run['run'] = common_run_format(run)
+ full_run['machine'] = common_machine_format(run.machine)
- to_get = [ts.Sample.id, ts.Sample.run_id, ts.Test.name,
- ts.Order.fields[0].column]
+ to_get = [ts.Sample.id, ts.Sample.run_id, ts.Test.name]
for f in ts.sample_fields:
to_get.append(f.column)
@@ -242,7 +246,7 @@ class Run(Resource):
# noinspection PyProtectedMember
ret = [sample._asdict() for sample in q.all()]
- full_run['samples'] = ret
+ full_run['tests'] = ret
return jsonify(full_run)
@staticmethod
Modified: lnt/trunk/tests/server/ui/test_api.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/ui/test_api.py?rev=308565&r1=308564&r2=308565&view=diff
==============================================================================
--- lnt/trunk/tests/server/ui/test_api.py (original)
+++ lnt/trunk/tests/server/ui/test_api.py Wed Jul 19 17:09:11 2017
@@ -81,6 +81,7 @@ possible_run_keys = {u'__report_version_
u'ENABLE_HASHED_PROGRAM_OUTPUT',
u'cc_name',
u'order_id',
+ u'order_by',
u'start_time',
u'cc_version_number',
u'cc_alt_src_branch',
@@ -97,8 +98,8 @@ possible_run_keys = {u'__report_version_
u'TEST',
u'LLC_OPTFLAGS',
u'machine_id',
- u'order',
u'cc_exec_hash',
+ u'llvm_project_revision'
}
possible_machine_keys = {u'name',
@@ -125,8 +126,10 @@ class JSONAPITester(unittest.TestCase):
self.assertEqual(type(response), dict)
# There should be no unexpected top level keys.
- all_top_level_keys = {'generated_by', 'machines', 'runs', 'orders', 'samples'}
- self.assertTrue(set(response.keys()).issubset(all_top_level_keys))
+ all_top_level_keys = {'generated_by', 'machine', 'machines', 'runs', 'run', 'orders', 'tests', 'samples'}
+ keys = set(response.keys())
+ self.assertTrue(keys.issubset(all_top_level_keys),
+ "{} not subset of {}".format(keys, all_top_level_keys))
# All API calls should return as generated by.
self.assertIn("LNT Server v", response['generated_by'])
@@ -172,9 +175,9 @@ class JSONAPITester(unittest.TestCase):
"start_time": "2012-04-11T16:28:23",
"machine_id": 1,
"id": 1,
- "order": u'154331'}
- self.assertDictContainsSubset(expected, j['runs'][0])
- self.assertEqual(len(j['samples']), 2)
+ "llvm_project_revision": u'154331'}
+ self.assertDictContainsSubset(expected, j['run'])
+ self.assertEqual(len(j['tests']), 2)
# This should not be a run.
check_json(client, 'api/db_default/v4/nts/runs/100', expected_code=404)
Modified: lnt/trunk/tests/server/ui/test_api_modify.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/ui/test_api_modify.py?rev=308565&r1=308564&r2=308565&view=diff
==============================================================================
--- lnt/trunk/tests/server/ui/test_api_modify.py (original)
+++ lnt/trunk/tests/server/ui/test_api_modify.py Wed Jul 19 17:09:11 2017
@@ -62,7 +62,7 @@ class JSONAPIDeleteTester(unittest.TestC
client = self.client
j = check_json(client, 'api/db_default/v4/nts/runs/1')
- sample_ids = [s['id'] for s in j['samples']]
+ sample_ids = [s['id'] for s in j['tests']]
self.assertNotEqual(len(sample_ids), 0)
for sid in sample_ids:
resp = client.get('api/db_default/v4/nts/samples/{}'.format(sid))
@@ -97,7 +97,9 @@ class JSONAPIDeleteTester(unittest.TestC
for run_id in run_ids:
resp = check_json(client,
'api/db_default/v4/nts/runs/{}'.format(run_id))
- sample_ids.append([s['id'] for s in resp['samples']])
+ import pprint
+ pprint.pprint(resp['tests'])
+ sample_ids.append([s['id'] for s in resp['tests']])
self.assertNotEqual(len(sample_ids), 0)
resp = client.delete('api/db_default/v4/nts/machines/2')
@@ -130,7 +132,7 @@ Deleted machine 2
"""Check POST to /runs."""
client = self.client
- resp = client.get('api/db_default/v4/nts/runs/5')
+ resp = client.get('api/db_default/v4/nts/runs/999')
self.assertEqual(resp.status_code, 404)
data = open('%s/sample-report.json' % self.shared_inputs).read()
@@ -141,8 +143,7 @@ Deleted machine 2
resp = client.post('api/db_default/v4/nts/runs', data=data,
headers={'AuthToken': 'test_token'})
self.assertEqual(resp.status_code, 301)
- self.assertEqual(resp.headers['Location'],
- 'http://localhost/api/db_default/v4/nts/runs/5')
+ self.assertIn('http://localhost/api/db_default/v4/nts/runs/', resp.headers['Location'])
resp_json = json.loads(resp.data)
self.assertEqual(resp_json['run_id'], 5)
More information about the llvm-commits
mailing list