autotest: Move servo-fw-update logic to the servo_updater.py

Add option 'force_update' to force update firmware.
Moving the logic to reuse it in repair process before start servod.

BUG=b/158616208
TEST=run local

./site_utils/admin_audit/main.py --hostname chromeos1-row4-rack4-host4   --results-dir /tr --host-info-file /tr/host_info_store/chromeos1-row4-rack4-host4.store   verify-dut-storage verify-servo-fw
./site_utils/admin_audit/main.py --hostname chromeos1-row4-rack4-host3   --results-dir /tr --host-info-file /tr/host_info_store/chromeos1-row4-rack4-host3.store   verify-dut-storage verify-servo-fw

Change-Id: I2035c23bf3f083dd5ab82bec3af712d3c677dbf6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2277382
Tested-by: Otabek Kasimov <otabek@google.com>
Commit-Queue: Otabek Kasimov <otabek@google.com>
Reviewed-by: Garry Wang <xianuowang@chromium.org>
diff --git a/site_utils/admin_audit/servo_updater.py b/site_utils/admin_audit/servo_updater.py
index 849a9ae..35f8a07 100644
--- a/site_utils/admin_audit/servo_updater.py
+++ b/site_utils/admin_audit/servo_updater.py
@@ -236,3 +236,46 @@
         if self._get_product() != 'Servo Micro':
             return False
         return True
+
+
+# List servo firmware updaters
+SERVO_UPDATERS = (
+    UpdateServoV4Fw,
+    UpdateServoMicroFw,
+)
+
+
+def update_servo_firmware(host, force_update=False):
+    """Update firmware on servo devices.
+
+    @params host: ServoHost instance to run all required commands
+    @params dut_hostname: hostname of the DUT for track errors
+    @params force_update: run updater with force option
+    """
+    # to run updater we need make sure the servod is not running
+    host.stop_servod()
+    # initialize all updaters
+    updaters = [updater(host) for updater in SERVO_UPDATERS]
+
+    for updater in updaters:
+        # check if we need update
+        need_update = updater.check_needs()
+        board = updater.get_board()
+        if not need_update:
+            # We do not need update when:
+            #  - the board is not present
+            #  - not configuration info for device to run updater
+            #  - device already has latest version
+            logging.info('The board %s does not need update.', board)
+            continue
+        logging.info('Updating board %s firmware.', board)
+        try:
+            updater.update(force_update)
+        except Exception as e:
+            data = {'host': host.get_dut_hostname() or '',
+                    'board': board}
+            metrics.Counter(
+                'chromeos/autotest/audit/servo/fw/update/error'
+                ).increment(fields=data)
+            logging.info('Fail update firmware for %s', board)
+            logging.debug('Fail update firmware for %s: %s', board, str(e))
diff --git a/site_utils/admin_audit/verifiers.py b/site_utils/admin_audit/verifiers.py
index 971a3db..45e6fcd 100644
--- a/site_utils/admin_audit/verifiers.py
+++ b/site_utils/admin_audit/verifiers.py
@@ -157,35 +157,10 @@
     when servod started. This should ensure that the servo_v4 and
     servo_micro is up-to-date.
     """
-
-    UPDATERS = [
-        servo_updater.UpdateServoV4Fw,
-        servo_updater.UpdateServoMicroFw,
-    ]
-
     def _verify(self):
         if not self.servo_host_is_up():
             logging.info('Servo host is down; Skipping the verification')
             return
-        host = self.get_host()
-        # create all updater
-        updaters = [updater(host) for updater in self.UPDATERS]
-        # run checker for all updaters
-        for updater in updaters:
-            supported = updater.check_needs()
-            logging.debug('The board %s is supported: %s',
-                          updater.get_board(), supported)
-        # to run updater we need make sure the servod is not running
-        host.stop_servod()
-        #  run update
-        for updater in updaters:
-            try:
-                updater.update(force_update=True)
-            except Exception as e:
-                metrics.Counter(
-                    'chromeos/autotest/audit/servo/fw/update/error'
-                    ).increment(fields={'host': self._dut_host.hostname})
-                logging.info('Fail update firmware for %s',
-                             updater.get_board())
-                logging.debug('Fail update firmware for %s: %s',
-                              updater.get_board(), str(e))
+        servo_updater.update_servo_firmware(
+            self.get_host(),
+            force_update=True)