autotest: Add counter for image download

BUG=b:172886823
TEST=run local

./server/autoserv -s --host-info-subdir host_info_store -m chromeos6-row11-rack3-host15 --lab True --local-only-host-info True -R -r /tr/

Change-Id: Ia9ed30e57c65011177a2d574fd3ac5cf96078591
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2600656
Commit-Queue: Otabek Kasimov <otabek@google.com>
Tested-by: Otabek Kasimov <otabek@google.com>
Reviewed-by: Garry Wang <xianuowang@chromium.org>
diff --git a/server/hosts/cros_host.py b/server/hosts/cros_host.py
index 9110442..77b0b24 100644
--- a/server/hosts/cros_host.py
+++ b/server/hosts/cros_host.py
@@ -11,6 +11,7 @@
 import os
 import re
 import sys
+import six
 import time
 
 import common
@@ -1056,8 +1057,21 @@
 
         with metrics.SecondsTimer(
                 'chromeos/autotest/provision/servo_install/boot_duration'):
+            self.servo._power_state.power_off()
+            try:
+                self.servo.image_to_servo_usb(image_path=image_url,
+                                              power_off_dut=False)
+            except error.AutotestError as e:
+                metrics.Counter('chromeos/autotest/repair/image_to_usb_error'
+                                ).increment(
+                                        fields={'host': self.hostname or ''})
+                six.reraise(error.AutotestError, str(e), sys.exc_info()[2])
+            # Give the DUT some time to power_off if we skip
+            # download image to usb. (crbug.com/982993)
+            if not image_url:
+                time.sleep(10)
             need_snk = self.require_snk_mode_in_recovery()
-            self.servo.install_recovery_image(image_url, snk_mode=need_snk)
+            self.servo.boot_in_recovery_mode(snk_mode=need_snk)
             if not self.wait_up(timeout=usb_boot_timeout):
                 if need_snk:
                     # Attempt to restore servo_v4 role to 'src' mode.