Home | History | Annotate | Download | only in platform_InstallTestImage
      1 # Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import logging
      6 
      7 from autotest_lib.client.common_lib import error
      8 from autotest_lib.client.common_lib import utils
      9 from autotest_lib.client.common_lib.cros import dev_server
     10 from autotest_lib.server import host_attributes
     11 
     12 AUTHOR = "Chrome OS Team"
     13 NAME = "platform_InstallTestImage"
     14 TIME = "MEDIUM"
     15 TEST_CATEGORY = "Install"
     16 TEST_CLASS = "platform"
     17 TEST_TYPE = "server"
     18 
     19 DOC = """
     20 This test installs a specified test image onto a servo-connected DUT.
     21 The principle purpose is to allow installing a known-good image onto
     22 a wedged unit that would otherwise have to be re-imaged manually.
     23 
     24 Here is the command to install a recovery image with a locally attached
     25 servo:
     26     test_that -b ${BOARD} ${IP_ADDRESS} \
     27         --args="image=$IMAGE_PATH" platform_InstallTestImage
     28 
     29 """
     30 
     31 args_dict = utils.args_to_dict(args)
     32 servo_args = hosts.CrosHost.get_servo_arguments(args_dict)
     33 
     34 def run(machine):
     35     # Setup the client machine.
     36     host = hosts.create_host(machine, servo_args=servo_args)
     37     # If we're invoked from test_that, the user can pass an
     38     # optional "image" argument.  If it's omitted, we want to pass
     39     # `None` to the test.  That will cause the test to assume
     40     # there's an image pre-installed on USB.  This is convenient,
     41     # because it can save the time of a long download.
     42     #
     43     # If we're called from the AFE, there won't be an "image"
     44     # argument, and we want to ask the dev server to stage a test
     45     # image.
     46     #
     47     # To distinguish the two cases above, we ask the host for
     48     # the name of the default image we should stage.  When we're
     49     # called from test_that, this call should fail when we
     50     # try to look the host up in the AFE database.  Otherwise, if we
     51     # get a valid image name, we use it to stage a build.
     52     image_url = args_dict.get("image")
     53     if image_url is None:
     54         try:
     55             # This fails if the board type can't be determined.
     56             image_name = host._get_cros_repair_image_name()
     57         except error.AutoservError as e:
     58             # Failed, so assume this is test_that.
     59             logging.info("Can't find build to stage: %s.", e)
     60             logging.info("Assuming this is an invocation from test_that "
     61                          "with a pre-installed USB image")
     62         else:
     63             # Succeeded, so stage the build and get its URL.
     64             # N.B. Failures from staging the build at this point
     65             # are fatal by design.
     66             image_url = host.stage_image_for_servo(image_name)
     67             logging.info("Using staged image:  %s", image_url)
     68     job.run_test("platform_InstallTestImage", host=host,
     69                  disable_sysinfo=True, image_url=image_url)
     70 
     71 parallel_simple(run, machines)
     72