[autotest] Extract buildbot poke

BUG=chromium:672348
TEST=None

Change-Id: Ie39feb1648c3d8ae371930abb657f47648e3b775
Reviewed-on: https://chromium-review.googlesource.com/565810
Commit-Ready: Allen Li <ayatane@chromium.org>
Tested-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Prathmesh Prabhu <pprabhu@chromium.org>
diff --git a/site_utils/run_suite.py b/site_utils/run_suite.py
index 38484a7..6af4373 100755
--- a/site_utils/run_suite.py
+++ b/site_utils/run_suite.py
@@ -1736,15 +1736,10 @@
     rpc_helper = diagnosis_utils.RPCHelper(afe)
     instance_server = afe.server
     while not afe.get_jobs(id=job_id, finished=True):
-        # Note that this call logs output, preventing buildbot's
-        # 9000 second silent timeout from kicking in. Let there be no
-        # doubt, this is a hack. The timeout is from upstream buildbot and
-        # this is the easiest work around.
-        if job_timer.first_past_halftime():
-            rpc_helper.diagnose_job(job_id, instance_server)
+        _poke_buildbot_with_output(afe, job_id, job_timer)
         if job_timer.debug_output_timer.poll():
             logging.info('The suite job has another %s till timeout.',
-                            job_timer.timeout_hours - job_timer.elapsed_time())
+                         job_timer.timeout_hours - job_timer.elapsed_time())
         time.sleep(10)
     logging.info('%s Suite job is finished.',
                  diagnosis_utils.JobTimer.format_time(datetime.now()))
@@ -1765,7 +1760,7 @@
 
     # Extract the original suite name to record timing.
     original_suite_name = get_original_suite_name(options.name,
-                                                    options.suite_args)
+                                                  options.suite_args)
     # Start collecting test results.
     logging.info('%s Start collecting test results and dump them to json.',
                  diagnosis_utils.JobTimer.format_time(datetime.now()))
@@ -1889,6 +1884,23 @@
             min_rpc_timeout=_MIN_RPC_TIMEOUT)
 
 
+def _poke_buildbot_with_output(afe, job_id, job_timer):
+    """Poke buildbot so it doesn't timeout from silence.
+
+    @param afe              AFE instance.
+    @param job_id           Suite job id.
+    @param job_timer        JobTimer for suite job.
+    """
+    rpc_helper = diagnosis_utils.RPCHelper(afe)
+    # Note that this call logs output, preventing buildbot's
+    # 9000 second silent timeout from kicking in. Let there be no
+    # doubt, this is a hack. The timeout is from upstream buildbot and
+    # this is the easiest work around.
+    if job_timer.first_past_halftime():
+        rpc_helper.diagnose_job(job_id, afe.server)
+
+
+
 def _run_task(options):
     """Perform this script's function minus setup.