[LNT] r311364 - api: Implement machines put method
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 21 12:09:45 PDT 2017
Author: matze
Date: Mon Aug 21 12:09:45 2017
New Revision: 311364
URL: http://llvm.org/viewvc/llvm-project?rev=311364&view=rev
Log:
api: Implement machines put method
This allows to change the parameters of a machine (while this is also
possible when uploading a run, this method allows to do so without
uploading a run at the same time).
Modified:
lnt/trunk/lnt/server/db/testsuitedb.py
lnt/trunk/lnt/server/ui/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=311364&r1=311363&r2=311364&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/testsuitedb.py (original)
+++ lnt/trunk/lnt/server/db/testsuitedb.py Mon Aug 21 12:09:45 2017
@@ -115,6 +115,11 @@ class TestSuiteDB(object):
result[field.name] = value
return result
+ def set_fields_pop(self, data_dict):
+ for field in self.fields:
+ value = data_dict.pop(field.name, None)
+ self.set_field(field, value)
+
db_key_name = self.test_suite.db_key_name
class Machine(self.base, ParameterizedMixin):
@@ -200,6 +205,15 @@ class TestSuiteDB(object):
return closest_run
+ def set_from_dict(self, data):
+ data_name = data.pop('name', None)
+ # This function is not meant for renaming. Abort on mismatch.
+ if data_name is not None and data_name != self.name:
+ raise ValueError("Mismatching machine name")
+ data.pop('id', None)
+ self.set_fields_pop(data)
+ self.parameters = data
+
def __json__(self):
result = dict()
result['name'] = self.name
Modified: lnt/trunk/lnt/server/ui/api.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/api.py?rev=311364&r1=311363&r2=311364&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/api.py (original)
+++ lnt/trunk/lnt/server/ui/api.py Mon Aug 21 12:09:45 2017
@@ -178,6 +178,17 @@ class Machine(Resource):
@staticmethod
@requires_auth_token
+ def put(machine_spec):
+ machine = Machine._get_machine(machine_spec)
+ machine_name = "%s:%s" % (machine.name, machine.id)
+ data = json.loads(request.data)
+ machine_data = data['machine']
+ machine.set_from_dict(machine_data)
+ ts = request.get_testsuite()
+ ts.commit()
+
+ @staticmethod
+ @requires_auth_token
def post(machine_spec):
ts = request.get_testsuite()
machine = Machine._get_machine(machine_spec)
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=311364&r1=311363&r2=311364&view=diff
==============================================================================
--- lnt/trunk/tests/server/ui/test_api_modify.py (original)
+++ lnt/trunk/tests/server/ui/test_api_modify.py Mon Aug 21 12:09:45 2017
@@ -36,6 +36,38 @@ class JSONAPIDeleteTester(unittest.TestC
self.client = app.test_client()
self.shared_inputs = shared_inputs
+ def test_00_update_machine(self):
+ """Check PUT request to /machines/n"""
+ client = self.client
+
+ # We are going to set the 'os' field to none, remove the 'uname'
+ # parameter and add the 'new_parameter' parameter.
+ # Make sure none of those things happened yet:
+ machine_before = check_json(client, 'api/db_default/v4/nts/machines/1')
+ machine_before = machine_before['machine']
+ self.assertIsNotNone(machine_before.get('os', None))
+ self.assertIsNone(machine_before.get('new_parameter', None))
+ self.assertIsNotNone(machine_before.get('uname', None))
+
+ data = {
+ 'machine': {
+ 'hardware': 'hal 9000',
+ 'os': None,
+ 'hostname': 'localhost',
+ 'new_parameter': True,
+ },
+ }
+ json_data = json.dumps(data)
+ resp = client.put('api/db_default/v4/nts/machines/1', data=json_data,
+ headers={'AuthToken': 'test_token'})
+ self.assertEqual(resp.status_code, 200)
+
+ machine_after = check_json(client, 'api/db_default/v4/nts/machines/1')
+ machine_after = machine_after['machine']
+ for key in ('hardware', 'os', 'hostname', 'new_parameter', 'uname'):
+ self.assertEquals(machine_after.get(key, None),
+ data['machine'].get(key, None))
+
def test_00_rename_machine(self):
"""Check rename POST request to /machines/n"""
client = self.client
More information about the llvm-commits
mailing list