[autotest] Add sponge url to tko_job_keyvals

This is for Autotest to retrieve the url to Sponge invocation.
Also added more logging in Sponge upload failure.

BUG=None
TEST=local test

Change-Id: I6e1d6c269b810a3f235e7b94d635fe2882fe07cd
Reviewed-on: https://chromium-review.googlesource.com/398521
Commit-Ready: Dan Shi <dshi@google.com>
Tested-by: Dan Shi <dshi@google.com>
Reviewed-by: Kevin Cheng <kevcheng@chromium.org>
diff --git a/tko/parse.py b/tko/parse.py
index 4cd2641..b3b1074 100755
--- a/tko/parse.py
+++ b/tko/parse.py
@@ -255,6 +255,11 @@
             db.delete('tko_test_labels_tests', {'test_id': test_idx})
             db.delete('tko_tests', where)
 
+    # Upload job details to Sponge.
+    sponge_url = sponge_utils.upload_results(job, log=tko_utils.dprint)
+    if sponge_url:
+        job.keyval_dict['sponge_url'] = sponge_url
+
     # check for failures
     message_lines = [""]
     job_successful = True
@@ -330,9 +335,6 @@
 
     db.commit()
 
-    # Upload job details to Sponge.
-    sponge_utils.upload_results(job)
-
     # Mark GS_OFFLOADER_NO_OFFLOAD in gs_offloader_instructions at the end of
     # the function, so any failure, e.g., db connection error, will stop
     # gs_offloader_instructions being updated, and logs can be uploaded for