Change Triage View's tables to ScrollTable, and implement bulk triage

Signed-off-by: James Ren <jamesren@google.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@4450 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/frontend/planner/rpc_utils.py b/frontend/planner/rpc_utils.py
index 7195921..51ec9c0 100644
--- a/frontend/planner/rpc_utils.py
+++ b/frontend/planner/rpc_utils.py
@@ -3,6 +3,7 @@
 from autotest_lib.frontend.afe import models as afe_models, model_logic
 from autotest_lib.frontend.planner import models, model_attributes
 from autotest_lib.frontend.planner import failure_actions
+from autotest_lib.frontend.tko import models as tko_models
 from autotest_lib.client.common_lib import global_config, utils, global_config
 
 
@@ -169,11 +170,58 @@
     test_run.save()
 
 
+def process_failure(failure_id, host_action, test_action, labels, keyvals,
+                    bugs, reason, invalidate):
+    if keyvals is None:
+        keyvals = {}
+
+    failure = models.TestRun.objects.get(id=failure_id)
+
+    _process_host_action(failure.host, host_action)
+    _process_test_action(failure.test_job, test_action)
+
+    # Add the test labels
+    for label in labels:
+        tko_test_label, _ = (
+                tko_models.TestLabel.objects.get_or_create(name=label))
+        failure.tko_test.testlabel_set.add(tko_test_label)
+
+    # Set the job keyvals
+    for key, value in keyvals.iteritems():
+        keyval, created = tko_models.JobKeyval.objects.get_or_create(
+                job=failure.tko_test.job, key=key)
+        if not created:
+            tko_models.JobKeyval.objects.create(job=failure.tko_test.job,
+                                                key='original_' + key,
+                                                value=keyval.value)
+        keyval.value = value
+        keyval.save()
+
+    # Add the bugs
+    for bug_id in bugs:
+        bug, _ = models.Bug.objects.get_or_create(external_uid=bug_id)
+        failure.bugs.add(bug)
+
+    # Set the failure reason
+    if reason is not None:
+        tko_models.TestAttribute.objects.create(test=failure.tko_test,
+                                                attribute='original_reason',
+                                                value=failure.tko_test.reason)
+        failure.tko_test.reason = reason
+        failure.tko_test.save()
+
+    # Set 'invalidated', 'seen', and 'triaged'
+    failure.invalidated = invalidate
+    failure.seen = True
+    failure.triaged = True
+    failure.save()
+
+
 def _site_process_host_action_dummy(host, action):
     return False
 
 
-def process_host_action(host, action):
+def _process_host_action(host, action):
     """
     Takes the specified action on the host
     """
@@ -199,7 +247,7 @@
         host.save()
 
 
-def process_test_action(planner_job, action):
+def _process_test_action(planner_job, action):
     """
     Takes the specified action for this planner job
     """