Fix timeout failure workflow

If timeout for device to come up from USB fails
we still continue to the install command. Fixing this
by adding it under condition timeout check to succeed.

BUG=chromium:881093
TEST=None

Change-Id: I0b833dd7daf1bdd8f3500e6ef774e2244be5ea01
Reviewed-on: https://chromium-review.googlesource.com/1228300
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Kalin Stoyanov <kalin@chromium.org>
Reviewed-by: Sridhar Sonti <sontis@google.com>
Reviewed-by: Harpreet Grewal <harpreet@chromium.org>
diff --git a/server/site_tests/platform_StageAndRecover/platform_StageAndRecover.py b/server/site_tests/platform_StageAndRecover/platform_StageAndRecover.py
index ac3ce0a..d3d5b4d 100644
--- a/server/site_tests/platform_StageAndRecover/platform_StageAndRecover.py
+++ b/server/site_tests/platform_StageAndRecover/platform_StageAndRecover.py
@@ -13,7 +13,7 @@
     version = 1
 
     _INSTALL_DELAY_TIMEOUT = 540
-    _TEST_IMAGE_BOOT_DELAY = 60
+    _TEST_IMAGE_BOOT_DELAY = 120
 
     def cleanup(self):
         """ Clean up by switching servo usb towards servo host. """
@@ -73,12 +73,14 @@
         logging.info('Started %s. Will wait up to %d seconds to complete' %
                      (process, timeout))
         start_time = time.time()
-        if self.host.ping_wait_up(timeout=timeout):
+        result = self.host.ping_wait_up(timeout=timeout)
+        if result:
             logging.info('Device came back up successfully in %d seconds.',
                          time.time() - start_time)
         else:
             self.error_messages.append('Host failed to come back after %s '
                                        'in %d seconds.' % (process, timeout))
+        return result
 
 
     def run_once(self, host):
@@ -92,13 +94,13 @@
         self.wait_for_dut_ping_after('RECOVERY', self._INSTALL_DELAY_TIMEOUT)
 
         self.stage_copy_recover_with('test_image')
-        self.wait_for_dut_ping_after('TEST_IMAGE RECOVERY BOOT FROM USB',
-                                  self._TEST_IMAGE_BOOT_DELAY)
 
-        # Install the test image back on DUT
-        self.host.run('chromeos-install --yes',
-                      timeout=self._INSTALL_DELAY_TIMEOUT)
-        self.host.reboot()
+        # Install the test image back on DUT and reboot
+        if self.wait_for_dut_ping_after('TEST_IMAGE RECOVERY BOOT FROM USB',
+                                        self._TEST_IMAGE_BOOT_DELAY):
+            self.host.run('chromeos-install --yes',
+                        timeout=self._INSTALL_DELAY_TIMEOUT)
+            self.host.reboot()
 
         if self.error_messages:
             raise error.TestFail('Failures: %s' % ' '.join(self.error_messages))