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 ATTRIBUTES = "suite:push_to_prod"
     19 SUITE = "push_to_prod"
     20 
     21 DOC = """
     22 This test installs a specified test image onto a servo-connected DUT.
     23 The principle purpose is to allow installing a known-good image onto
     24 a wedged unit that would otherwise have to be re-imaged manually.
     25 
     26 Here is the command to install a recovery image with a locally attached
     27 servo:
     28     test_that -b ${BOARD} ${IP_ADDRESS} \
     29         --args="image=$IMAGE_PATH" platform_InstallTestImage
     30 
     31 """
     32 
     33 args_dict = utils.args_to_dict(args)
     34 servo_args = hosts.CrosHost.get_servo_arguments(args_dict)
     35 
     36 def run(machine):
     37     # Setup the client machine.
     38     host = hosts.create_host(machine, servo_args=servo_args)
     39     # If we're invoked from test_that, the user can pass an
     40     # optional "image" argument.  If it's omitted, we want to pass
     41     # `None` to the test.  That will cause the test to assume
     42     # there's an image pre-installed on USB.  This is convenient,
     43     # because it can save the time of a long download.
     44     #
     45     # If we're called from the AFE, there won't be an "image"
     46     # argument, and we want to ask the dev server to stage a test
     47     # image.
     48     #
     49     # To distinguish the two cases above, we ask the host for
     50     # the name of the default image we should stage.  When we're
     51     # called from test_that, this call should fail when we
     52     # try to look the host up in the AFE database.  Otherwise, if we
     53     # get a valid image name, we use it to stage a build.
     54     image_url = args_dict.get("image")
     55     if image_url is None:
     56         try:
     57             # This fails if the board type can't be determined.
     58             image_name = host.get_repair_image_name()
     59         except error.AutoservError as e:
     60             # Failed, so assume this is test_that.
     61             logging.info("Can't find build to stage: %s.", e)
     62             logging.info("Assuming this is an invocation from test_that "
     63                          "with a pre-installed USB image")
     64         else:
     65             # Succeeded, so stage the build and get its URL.
     66             # N.B. Failures from staging the build at this point
     67             # are fatal by design.
     68             image_url = host.stage_image_for_servo(image_name)
     69             logging.info("Using staged image:  %s", image_url)
     70     job.run_test("platform_InstallTestImage", host=host,
     71                  disable_sysinfo=True, image_url=image_url)
     72 
     73 parallel_simple(run, machines)
     74