[autotest] Add rule to reboot DUT when failing to get the lid_open value

Some servo controls, like lid_open, requires communicating with DUT
through EC UART console. Failure of this kinds of controls can be
recovered by rebooting the DUT.

BUG=chromium:755678
TEST=manual
Injectting code to set lid_open to 'no' in order to trigger the failure
of verifying lid_open, executed the repair process, saw the new added
repair action executed to reboot DUT, and the state of servo host become
good.

Change-Id: I44b14d89c6872e8b5620b320249403f69896132e
Reviewed-on: https://chromium-review.googlesource.com/617447
Commit-Ready: Wai-Hong Tam <waihong@google.com>
Tested-by: Wai-Hong Tam <waihong@google.com>
Reviewed-by: Shelley Chen <shchen@chromium.org>
Reviewed-by: Dan Shi <dshi@google.com>
diff --git a/server/hosts/servo_repair.py b/server/hosts/servo_repair.py
index 5ad70f4..99407a4 100644
--- a/server/hosts/servo_repair.py
+++ b/server/hosts/servo_repair.py
@@ -322,6 +322,28 @@
         return 'Wait for update, then reboot servo host.'
 
 
+class _DutRebootRepair(hosts.RepairAction):
+    """
+    Reboot DUT to recover some servo controls depending on EC console.
+
+    Some servo controls, like lid_open, requires communicating with DUT through
+    EC UART console. Failure of this kinds of controls can be recovered by
+    rebooting the DUT.
+    """
+
+    def repair(self, host):
+        host.get_servo().get_power_state_controller().reset()
+        # Get the lid_open value which requires EC console.
+        lid_open = host.get_servo().get('lid_open')
+        if lid_open != 'yes' and lid_open != 'not_applicable':
+            raise hosts.AutoservVerifyError(
+                    'Still fail to contact EC console after rebooting DUT')
+
+    @property
+    def description(self):
+        return 'Reset the DUT via servo'
+
+
 def create_servo_repair_strategy():
     """
     Return a `RepairStrategy` for a `ServoHost`.
@@ -346,10 +368,11 @@
         # ServoInstallRepair rather than add a verifier.
     ]
 
-    servod_deps = ['job', 'servod', 'pwr_button', 'lid_open']
+    servod_deps = ['job', 'servod', 'pwr_button']
     repair_actions = [
         (repair.RPMCycleRepair, 'rpm', [], ['servo_ssh']),
         (_RestartServod, 'restart', ['servo_ssh'], config + servod_deps),
-        (_ServoRebootRepair, 'reboot', ['servo_ssh'], servod_deps),
+        (_ServoRebootRepair, 'servo_reboot', ['servo_ssh'], servod_deps),
+        (_DutRebootRepair, 'dut_reboot', ['servod'], ['lid_open']),
     ]
     return hosts.RepairStrategy(verify_dag, repair_actions)