Add stage and recover (to same build) test
BUG=chromium:716225
Test=Staging successfully tested. Copy image to servo USB and recovery
to be tested on selected lab board after checked-in.
Change-Id: Ia55842616c0e5957f5788c095f1471fb2685618e
Reviewed-on: https://chromium-review.googlesource.com/1055620
Commit-Ready: Kalin Stoyanov <kalin@chromium.org>
Tested-by: Kalin Stoyanov <kalin@chromium.org>
Reviewed-by: danny chan <dchan@chromium.org>
diff --git a/server/cros/servo/servo.py b/server/cros/servo/servo.py
index 3b317d1..aca0582 100644
--- a/server/cros/servo/servo.py
+++ b/server/cros/servo/servo.py
@@ -623,6 +623,11 @@
logging.error('Failed to make image noninteractive. '
'Please take a look at Servo Logs.')
+ def boot_in_recovery_mode(self):
+ """Boot host DUT in recovery mode."""
+ self._power_state.power_on(rec_mode=self._power_state.REC_ON)
+ self.switch_usbkey('dut')
+
def install_recovery_image(self, image_path=None,
make_image_noninteractive=False):
@@ -639,8 +644,7 @@
after installation.
"""
self.image_to_servo_usb(image_path, make_image_noninteractive)
- self._power_state.power_on(rec_mode=self._power_state.REC_ON)
- self.switch_usbkey('dut')
+ self.boot_in_recovery_mode()
def _scp_image(self, image_path):
diff --git a/server/hosts/cros_host.py b/server/hosts/cros_host.py
index dc6f529..685b295 100644
--- a/server/hosts/cros_host.py
+++ b/server/hosts/cros_host.py
@@ -566,10 +566,12 @@
logging.debug('No autotest installed directory found.')
- def stage_image_for_servo(self, image_name=None):
+ def stage_image_for_servo(self, image_name=None, artifact='test_image'):
"""Stage a build on a devserver and return the update_url.
@param image_name: a name like lumpy-release/R27-3837.0.0
+ @param artifact: a string like 'test_image'. Requests
+ appropriate image to be staged.
@returns an update URL like:
http://172.22.50.205:8082/update/lumpy-release/R27-3837.0.0
"""
@@ -577,8 +579,13 @@
image_name = self.get_cros_repair_image_name()
logging.info('Staging build for servo install: %s', image_name)
devserver = dev_server.ImageServer.resolve(image_name, self.hostname)
- devserver.stage_artifacts(image_name, ['test_image'])
- return devserver.get_test_image_url(image_name)
+ devserver.stage_artifacts(image_name, [artifact])
+ if artifact == 'test_image':
+ return devserver.get_test_image_url(image_name)
+ elif artifact == 'recovery_image':
+ return devserver.get_recovery_image_url(image_name)
+ else:
+ raise error.AutoservError("Bad artifact!")
def stage_factory_image_for_servo(self, image_name):
diff --git a/server/site_tests/platform_StageAndRecover/control b/server/site_tests/platform_StageAndRecover/control
new file mode 100644
index 0000000..fad280a
--- /dev/null
+++ b/server/site_tests/platform_StageAndRecover/control
@@ -0,0 +1,32 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from autotest_lib.client.common_lib import utils
+
+AUTHOR = "Chrome OS Team"
+NAME = "platform_StageAndRecover"
+TIME = "MEDIUM"
+TEST_CATEGORY = "Install"
+TEST_CLASS = "platform"
+TEST_TYPE = "server"
+DEPENDENCIES = "servo, recovery_test"
+ATTRIBUTES = "suite:usb_detect"
+
+DOC = """
+This test stages and installs the same build recovery image onto a
+servo-connected DUT. This is useful for testing the recovery process,
+imaging servo-connected Devices under Test (DUTs), and verifying recovery
+build image is installed.
+"""
+
+args_dict = utils.args_to_dict(args)
+servo_args = hosts.CrosHost.get_servo_arguments(args_dict)
+
+def run(machine):
+ # Setup the client machine.
+ host = hosts.create_host(machine, servo_args=servo_args)
+ job.run_test("platform_StageAndRecover", host=host,
+ disable_sysinfo=True)
+
+parallel_simple(run, machines)
diff --git a/server/site_tests/platform_StageAndRecover/platform_StageAndRecover.py b/server/site_tests/platform_StageAndRecover/platform_StageAndRecover.py
new file mode 100644
index 0000000..d4d07c6
--- /dev/null
+++ b/server/site_tests/platform_StageAndRecover/platform_StageAndRecover.py
@@ -0,0 +1,65 @@
+# Copyright 2018 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import logging
+import time
+
+from autotest_lib.server import test
+from autotest_lib.client.common_lib import error
+
+class platform_StageAndRecover(test.test):
+ """Installs the same version recovery image onto a servo-connected DUT."""
+ version = 1
+
+ _RECOVERY_INSTALL_DELAY = 540
+
+ def cleanup(self):
+ """ Clean up by switching servo usb towards servo host. """
+ self.switch_usbkey('host')
+
+
+ def set_servo_usb_reimage(self):
+ """ Turns USB_HUB_2 servo port to DUT, and disconnects servo from DUT.
+ Avoiding peripherals plugged at this servo port.
+ """
+ self.host.servo.set('usb_mux_sel3', 'dut_sees_usbkey')
+ self.host.servo.set('dut_hub1_rst1','on')
+
+ def set_servo_usb_recover(self):
+ """ Turns USB_HUB_2 servo port to servo, and connects servo to DUT.
+ Avoiding peripherals plugged at this servo port.
+ """
+ self.host.servo.set('usb_mux_sel3', 'servo_sees_usbkey')
+ self.host.servo.set('dut_hub1_rst1','off')
+
+ def run_once(self, host):
+ self.host = host
+
+ # Stage the recovery image on dev server
+ image_path = self.host.stage_image_for_servo(
+ self.host.get_release_builder_path(),
+ artifact='recovery_image')
+ logging.info('Image staged at %s', image_path)
+
+ # Make sermo sees only DUT_HUB1
+ self.set_servo_usb_reimage()
+ # Reimage servo USB
+ self.host.servo.image_to_servo_usb(image_path,
+ make_image_noninteractive=True)
+ self.set_servo_usb_recover()
+
+ # Boot DUT in recovery mode for image to install
+ self.host.servo.boot_in_recovery_mode()
+
+ logging.info('Running the recovery process on the DUT. '
+ 'Will wait up to %d seconds for recovery to '
+ 'complete.', self._RECOVERY_INSTALL_DELAY)
+ start_time = time.time()
+ # Wait for the host to come up.
+ if host.ping_wait_up(timeout=self._RECOVERY_INSTALL_DELAY):
+ logging.info('Recovery process completed successfully in '
+ '%d seconds.', time.time() - start_time)
+ else:
+ raise error.TestFail('Host failed to come back up after '
+ '%d seconds.' % self._RECOVERY_INSTALL_DELAY)