gooftool: Allow report upload fail and continue finalize

Add an argument to allow report upload fail in finalize. When the flag
is set and upload fails, skip upload and continue finalze instead of
raising an exception.

BUG=chromium:877002
TEST=make test; manually test on DUT

Change-Id: Iecb355d89cbc68ca81c7c83aef90844dab1af1d5
Reviewed-on: https://chromium-review.googlesource.com/1188061
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Cheng-Han Yang <chenghan@chromium.org>
Reviewed-by: Wei-Han Chen <stimim@chromium.org>
diff --git a/py/gooftool/commands.py b/py/gooftool/commands.py
index 0375340..58011cf 100755
--- a/py/gooftool/commands.py
+++ b/py/gooftool/commands.py
@@ -621,6 +621,9 @@
 _upload_retry_interval_arg = CmdArg(
     '--upload_retry_interval', type=int, default=None,
     help='Retry interval in seconds.')
+_upload_allow_fail_arg = CmdArg(
+    '--upload_allow_fail', action='store_true',
+    help='Continue finalize if report upload fails.')
 _add_file_cmd_arg = CmdArg(
     '--add_file', metavar='FILE', action='append',
     help='Extra file to include in report (must be an absolute path)')
@@ -630,6 +633,7 @@
          _upload_method_cmd_arg,
          _upload_max_retry_times_arg,
          _upload_retry_interval_arg,
+         _upload_allow_fail_arg,
          _add_file_cmd_arg)
 def UploadReport(options):
   """Create a report containing key device details."""
@@ -656,19 +660,23 @@
         target_path, param,
         'GRT' if options.command_name == 'finalize' else None,
         max_retry_times=options.upload_max_retry_times,
-        retry_interval=retry_interval)
+        retry_interval=retry_interval,
+        allow_fail=options.upload_allow_fail)
   elif method == 'ftp':
     report_upload.FtpUpload(target_path, 'ftp:' + param,
                             max_retry_times=options.upload_max_retry_times,
-                            retry_interval=retry_interval)
+                            retry_interval=retry_interval,
+                            allow_fail=options.upload_allow_fail)
   elif method == 'ftps':
     report_upload.CurlUrlUpload(target_path, '--ftp-ssl-reqd ftp:%s' % param,
                                 max_retry_times=options.upload_max_retry_times,
-                                retry_interval=retry_interval)
+                                retry_interval=retry_interval,
+                                allow_fail=options.upload_allow_fail)
   elif method == 'cpfe':
     report_upload.CpfeUpload(target_path, pipes.quote(param),
                              max_retry_times=options.upload_max_retry_times,
-                             retry_interval=retry_interval)
+                             retry_interval=retry_interval,
+                             allow_fail=options.upload_allow_fail)
   else:
     raise Error('unknown report upload method %r' % method)
 
@@ -684,6 +692,7 @@
          _upload_method_cmd_arg,
          _upload_max_retry_times_arg,
          _upload_retry_interval_arg,
+         _upload_allow_fail_arg,
          _add_file_cmd_arg,
          _probe_results_cmd_arg,
          _hwid_cmd_arg,