Add power_action to run_shutdown_process to skip power_key presses.

- if pre_power_action is lid_open:yes, the subsequent power_key presses
  will result in turning DUT off which will cause the last test in
  firmware_FwScreenCloseLid to fail.

BUG=chrome-os-partner:48216
TEST=Run firmware_FwScreenCloseLid and firmware_FwScreenPressPower on link.

Change-Id: I2bf7fdb5049fa72d2ca5f18c1d254de7eadb0c12
Reviewed-on: https://chromium-review.googlesource.com/315776
Commit-Ready: danny chan <dchan@chromium.org>
Tested-by: danny chan <dchan@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@chromium.org>
diff --git a/server/cros/faft/firmware_test.py b/server/cros/faft/firmware_test.py
index fd8136c..f31e228 100644
--- a/server/cros/faft/firmware_test.py
+++ b/server/cros/faft/firmware_test.py
@@ -1074,12 +1074,13 @@
         return ret
 
     def run_shutdown_process(self, shutdown_action, pre_power_action=None,
-            post_power_action=None, shutdown_timeout=None):
+            run_power_action=True, post_power_action=None, shutdown_timeout=None):
         """Run shutdown_action(), which makes DUT shutdown, and power it on.
 
         @param shutdown_action: function which makes DUT shutdown, like
                                 pressing power key.
         @param pre_power_action: function which is called before next power on.
+        @param power_action: power_key press by default, set to None to skip.
         @param post_power_action: function which is called after next power on.
         @param shutdown_timeout: a timeout to confirm DUT shutdown.
         @raise TestFail: if the shutdown_action() failed to turn DUT off.
@@ -1099,7 +1100,8 @@
 
         if pre_power_action:
             self._call_action(pre_power_action)
-        self.servo.power_key(self.faft_config.hold_pwr_button_poweron)
+        if run_power_action:
+            self.servo.power_key(self.faft_config.hold_pwr_button_poweron)
         if post_power_action:
             self._call_action(post_power_action)
 
diff --git a/server/site_tests/firmware_FwScreenCloseLid/firmware_FwScreenCloseLid.py b/server/site_tests/firmware_FwScreenCloseLid/firmware_FwScreenCloseLid.py
index c6c1806..e064b0c 100644
--- a/server/site_tests/firmware_FwScreenCloseLid/firmware_FwScreenCloseLid.py
+++ b/server/site_tests/firmware_FwScreenCloseLid/firmware_FwScreenCloseLid.py
@@ -86,8 +86,8 @@
                           }))
         self.switcher.mode_aware_reboot(wait_for_dut_up=False)
         self.run_shutdown_process(self.wait_fw_screen_and_close_lid,
-                                  self.servo.lid_open,
-                                  self.switcher.bypass_dev_mode)
+                                  pre_power_action=self.servo.lid_open,
+                                  post_power_action=self.switcher.bypass_dev_mode)
         self.switcher.wait_for_client()
 
         logging.info("Reboot. When the developer screen shown, press "
@@ -100,9 +100,9 @@
                           }))
         self.switcher.mode_aware_reboot(wait_for_dut_up=False)
         self.run_shutdown_process(self.wait_second_screen_and_close_lid,
-                                  self.servo.lid_open,
-                                  self.switcher.bypass_dev_mode,
-                                  self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
+                                  pre_power_action=self.servo.lid_open,
+                                  post_power_action=self.switcher.bypass_dev_mode,
+                                  shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
         self.switcher.wait_for_client()
 
         logging.info("Request recovery boot. When the RECOVERY INSERT "
@@ -114,9 +114,9 @@
         self.faft_client.system.request_recovery_boot()
         self.switcher.mode_aware_reboot(wait_for_dut_up=False)
         self.run_shutdown_process(self.wait_longer_fw_screen_and_close_lid,
-                                  self.servo.lid_open,
-                                  self.switcher.bypass_dev_mode,
-                                  self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
+                                  pre_power_action=self.servo.lid_open,
+                                  post_power_action=self.switcher.bypass_dev_mode,
+                                  shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
         self.switcher.wait_for_client()
 
         logging.info("Request recovery boot again. When the recovery "
@@ -129,9 +129,9 @@
         self.faft_client.system.request_recovery_boot()
         self.switcher.mode_aware_reboot(wait_for_dut_up=False)
         self.run_shutdown_process(self.wait_yuck_screen_and_close_lid,
-                                  self.servo.lid_open,
-                                  self.switcher.bypass_dev_mode,
-                                  self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
+                                  pre_power_action=self.servo.lid_open,
+                                  post_power_action=self.switcher.bypass_dev_mode,
+                                  shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
         self.switcher.wait_for_client()
 
         logging.info("Switch back to normal mode.")
@@ -151,9 +151,9 @@
         self.faft_client.system.request_recovery_boot()
         self.switcher.mode_aware_reboot(wait_for_dut_up=False)
         self.run_shutdown_process(self.wait_longer_fw_screen_and_close_lid,
-                                  self.servo.lid_open,
-                                  None,
-                                  self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
+                                  pre_power_action=self.servo.lid_open,
+                                  run_power_action=False,
+                                  shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
         self.switcher.wait_for_client()
         self.check_state((self.checkers.crossystem_checker, {
                           'devsw_boot': '0',
diff --git a/server/site_tests/firmware_FwScreenPressPower/firmware_FwScreenPressPower.py b/server/site_tests/firmware_FwScreenPressPower/firmware_FwScreenPressPower.py
index 5f95fb6..3450e9f 100644
--- a/server/site_tests/firmware_FwScreenPressPower/firmware_FwScreenPressPower.py
+++ b/server/site_tests/firmware_FwScreenPressPower/firmware_FwScreenPressPower.py
@@ -82,8 +82,7 @@
                               }))
         self.switcher.mode_aware_reboot(wait_for_dut_up=False)
         self.run_shutdown_process(self.wait_fw_screen_and_press_power,
-                                  None,
-                                  self.switcher.bypass_dev_mode)
+                                  post_power_action=self.switcher.bypass_dev_mode)
         self.switcher.wait_for_client()
 
         logging.info("Reboot. When the developer screen shown, press "
@@ -96,9 +95,8 @@
                               }))
         self.switcher.mode_aware_reboot(wait_for_dut_up=False)
         self.run_shutdown_process(self.wait_second_screen_and_press_power,
-                                  None,
-                                  self.switcher.bypass_dev_mode,
-                                  self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
+                                  post_power_action=self.switcher.bypass_dev_mode,
+                                  shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
         self.switcher.wait_for_client()
 
         logging.info("Request recovery boot. When the RECOVERY INSERT "
@@ -110,9 +108,8 @@
         self.faft_client.system.request_recovery_boot()
         self.switcher.mode_aware_reboot(wait_for_dut_up=False)
         self.run_shutdown_process(self.wait_longer_fw_screen_and_press_power,
-                                  None,
-                                  self.switcher.bypass_dev_mode,
-                                  self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
+                                  post_power_action=self.switcher.bypass_dev_mode,
+                                  shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
         self.switcher.wait_for_client()
 
         logging.info("Request recovery boot again. When the recovery "
@@ -126,9 +123,8 @@
         self.faft_client.system.request_recovery_boot()
         self.switcher.mode_aware_reboot(wait_for_dut_up=False)
         self.run_shutdown_process(self.wait_yuck_screen_and_press_power,
-                                  None,
-                                  self.switcher.bypass_dev_mode,
-                                  self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
+                                  post_power_action=self.switcher.bypass_dev_mode,
+                                  shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
         self.switcher.wait_for_client()
 
         logging.info("Switch back to normal mode.")
@@ -148,9 +144,7 @@
         self.faft_client.system.request_recovery_boot()
         self.switcher.mode_aware_reboot(wait_for_dut_up=False)
         self.run_shutdown_process(self.wait_longer_fw_screen_and_press_power,
-                                  None,
-                                  None,
-                                  self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
+                                  shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD)
         self.switcher.wait_for_client()
 
         logging.info("Check and done.")