servo: enforce keyboard on after hwinit when reflashing

This change forces the keyboard to be on after a hwinit when reflashing
a DUT, the same way it does for initialize_dut, as hwinit might turn it
off from underneath us.

BUG=chromium:992094
TEST=test_that platform_InstallTestImage -b krane

Change-Id: Idfa26b850a445eb430578d819b214f5cf2f14a21
Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1745516
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Hsin-Yi Wang <hsinyi@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
diff --git a/server/cros/servo/servo.py b/server/cros/servo/servo.py
index de796e3..e076801 100644
--- a/server/cros/servo/servo.py
+++ b/server/cros/servo/servo.py
@@ -757,6 +757,19 @@
         # to do to the device after hotplug.  To avoid surprises,
         # force the DUT to be off.
         self._server.hwinit()
+        try:
+            # TODO(coconutruben): change this back to set() about a month
+            # after crrev.com/c/1586239 has been merged (or whenever that
+            # logic is in the labstation images).
+            self.set_nocheck('init_keyboard','on')
+        except error.TestFail as err:
+            if 'No control named' in str(err):
+                # This indicates the servod version does not
+                # have explicit keyboard initialization yet.
+                # Ignore this.
+                pass
+            else:
+                raise err
         self._power_state.power_off()
 
         if image_path: