[autotest] Move result_utils to its own package

This change moves result_utils.py to its own package. More code will be added to
enable result throttling. So it's more manageable to put all related files to a
single folder.

This change also push the result tools modules to client before trying to build
result summary. This removes the client side dependency. So all result
throttling logic will be kept on the server side.

BUG=chromium:716218
TEST=unittest, local run dummy tests

Change-Id: Icc3542af99439fd39b1dba36ac45aab6effd1080
Reviewed-on: https://chromium-review.googlesource.com/544049
Commit-Ready: Dan Shi <dshi@google.com>
Tested-by: Dan Shi <dshi@google.com>
Reviewed-by: Dan Shi <dshi@google.com>
diff --git a/server/autotest.py b/server/autotest.py
index 335a3e3..b6cc6e6 100644
--- a/server/autotest.py
+++ b/server/autotest.py
@@ -11,7 +11,10 @@
 import traceback
 
 import common
-from autotest_lib.client.common_lib import base_job, error, autotemp
+from autotest_lib.client.bin.result_tools import runner as result_tools_runner
+from autotest_lib.client.common_lib import autotemp
+from autotest_lib.client.common_lib import base_job
+from autotest_lib.client.common_lib import error
 from autotest_lib.client.common_lib import packages
 from autotest_lib.client.common_lib import global_config
 from autotest_lib.client.common_lib import utils as client_utils
@@ -28,10 +31,6 @@
 AUTOTEST_SVN = 'svn://test.kernel.org/autotest/trunk/client'
 AUTOTEST_HTTP = 'http://test.kernel.org/svn/autotest/trunk/client'
 
-THROTTLE_OPTION_FMT = '-m %s'
-BUILD_DIR_SUMMARY_CMD = '%s/bin/result_utils.py -p %s %s'
-BUILD_DIR_SUMMARY_TIMEOUT = 120
-
 CONFIG = global_config.global_config
 AUTOSERV_PREBUILD = CONFIG.get_config_value(
         'AUTOSERV', 'enable_server_prebuild', type=bool, default=False)
@@ -1008,27 +1007,10 @@
 
         # Copy all dirs in default to results_dir
         try:
-            with metrics.SecondsTimer(
-                    'chromeos/autotest/job/dir_summary_collection_duration',
-                    fields={'dut_host_name': self.host.hostname}):
-                try:
-                    # Build test result directory summary
-                    logging.debug('Getting directory summary for %s.',
-                                  self.client_results_dir)
-                    if ENABLE_RESULT_THROTTLING:
-                        throttle_option = (THROTTLE_OPTION_FMT %
-                                           self.host.job.max_result_size_KB)
-                    else:
-                        throttle_option = ''
-                    cmd = (BUILD_DIR_SUMMARY_CMD %
-                           (self.host.autodir, self.client_results_dir + '/',
-                            throttle_option))
-                    self.host.run(cmd, ignore_status=False,
-                                  timeout=BUILD_DIR_SUMMARY_TIMEOUT)
-                except error.AutoservRunError:
-                    logging.exception(
-                            'Failed to create directory summary for %s.',
-                            self.client_results_dir)
+            # Build test result directory summary
+            result_tools_runner.run_on_client(
+                    self.host, self.client_results_dir,
+                    ENABLE_RESULT_THROTTLING)
 
             with metrics.SecondsTimer(
                     'chromeos/autotest/job/log_collection_duration',