[autotest] Fix test_push with new changes from afe_utils

BUG=None
TEST=None

Change-Id: I4b682dbba7d782d8ea786b0805c9c8fd925cc437
Reviewed-on: https://chromium-review.googlesource.com/325507
Commit-Ready: Dan Shi <[email protected]>
Tested-by: Dan Shi <[email protected]>
Reviewed-by: Fang Deng <[email protected]>
Reviewed-by: Kevin Cheng <[email protected]>
diff --git a/site_utils/test_push.py b/site_utils/test_push.py
index 2776f6f..7258879 100755
--- a/site_utils/test_push.py
+++ b/site_utils/test_push.py
@@ -37,18 +37,18 @@
     # Unittest may not have Django database configured and will fail to import.
     pass
 from autotest_lib.client.common_lib import global_config
-from autotest_lib.server import afe_utils
 from autotest_lib.server import site_utils
 from autotest_lib.server.cros import provision
 from autotest_lib.server.cros.dynamic_suite import frontend_wrappers
 from autotest_lib.server.cros.dynamic_suite import reporting
-from autotest_lib.server.hosts import cros_host
 from autotest_lib.server.hosts import factory
 from autotest_lib.site_utils import gmail_lib
 from autotest_lib.site_utils.suite_scheduler import constants
 
 CONFIG = global_config.global_config
 
+AFE = frontend_wrappers.RetryingAFE(timeout_min=0.5, delay_sec=2)
+
 MAIL_FROM = '[email protected]'
 DEVSERVERS = CONFIG.get_config_value('CROS', 'dev_server', type=list,
                                      default=[])
@@ -226,12 +226,11 @@
         build = arguments.shard_build
 
     # Remove cros-version label to force provision.
-    afe = frontend_wrappers.RetryingAFE(timeout_min=0.5, delay_sec=2)
-    hosts = afe.get_hosts(label=constants.Labels.BOARD_PREFIX+board)
+    hosts = AFE.get_hosts(label=constants.Labels.BOARD_PREFIX+board)
     for host in hosts:
         for label in [l for l in host.labels
                       if l.startswith(provision.CROS_VERSION_PREFIX)]:
-            afe.run('host_remove_labels', id=host.id, labels=[label])
+            AFE.run('host_remove_labels', id=host.id, labels=[label])
 
         if use_shard and not create_and_return:
             # Let's verify the repair flow and powerwash the duts.  We can
@@ -243,7 +242,7 @@
                 raise TestPushException('Failed to powerwash dut %s. Make '
                                         'sure the dut is working first. '
                                         'Error: %s' % (host.hostname, e))
-            afe.reverify_hosts(hostnames=[host.hostname])
+            AFE.reverify_hosts(hostnames=[host.hostname])
 
     current_dir = os.path.dirname(os.path.realpath(__file__))
     cmd = [os.path.join(current_dir, RUN_SUITE_COMMAND),
@@ -281,11 +280,11 @@
     # If create_and_return specified, wait for the suite to finish.
     if create_and_return:
         end = time.time() + arguments.timeout_min * 60
-        while not afe.get_jobs(id=suite_job_id, finished=True):
+        while not AFE.get_jobs(id=suite_job_id, finished=True):
             if time.time() < end:
                 time.sleep(10)
             else:
-                afe.run('abort_host_queue_entries', job=suite_job_id)
+                AFE.run('abort_host_queue_entries', job=suite_job_id)
                 raise TestPushException(
                         'Asynchronous suite triggered by create_and_return '
                         'flag has timed out after %d mins. Aborting it.' %
@@ -309,8 +308,7 @@
             for job_id in job_ids]
     hostnames = set([hqe.host.hostname for hqe in hqes])
     for hostname in hostnames:
-        host = cros_host.CrosHost(hostname)
-        found_build = afe_utils.get_build(hostname)
+        found_build = site_utils.get_build_from_afe(hostname, AFE)
         if found_build != build:
             raise TestPushException('DUT is not imaged properly. Host %s has '
                                     'build %s, while build %s is expected.' %