1*9c5db199SXin Li#!/usr/bin/env python3 2*9c5db199SXin Li# Copyright 2015 The Chromium OS Authors. All rights reserved. 3*9c5db199SXin Li# Use of this source code is governed by a BSD-style license that can be 4*9c5db199SXin Li# found in the LICENSE file. 5*9c5db199SXin Li 6*9c5db199SXin Li"""Main routine for the `deploy` command line tool. 7*9c5db199SXin Li 8*9c5db199SXin Li# Purpose 9*9c5db199SXin LiThis command automates key steps for several use cases relating to DUTs 10*9c5db199SXin Liin the Autotest Test Lab: 11*9c5db199SXin Li * Deploying a DUT+Servo assembly with a DUT that is fresh from the 12*9c5db199SXin Li factory. 13*9c5db199SXin Li * Redeploying an existing DUT+Servo assembly to a new location. 14*9c5db199SXin Li * Manually repairing a DUT+Servo assembly that has failed automated 15*9c5db199SXin Li repair. 16*9c5db199SXin Li 17*9c5db199SXin Li# Syntax 18*9c5db199SXin Li 19*9c5db199SXin Lideploy <subcommand> [options] [HOSTNAME ...] 20*9c5db199SXin Li 21*9c5db199SXin Li## Available subcommands: 22*9c5db199SXin Li servo: Validate that the servo is in working order, and then install 23*9c5db199SXin Li the repair image for the target DUTs on the servo's USB stick. 24*9c5db199SXin Li firmware: Install dev-signed RO+RW firmware on the target DUTs, and 25*9c5db199SXin Li then install the image from the servo USB stick to the target 26*9c5db199SXin Li DUTs. 27*9c5db199SXin Li test-image: Install the image from the servo USB stick to the target 28*9c5db199SXin Li DUTs. 29*9c5db199SXin Li repair: Install the image from the servo USB stick to the target 30*9c5db199SXin Li DUTs. Differs from the 'test-image' subcommand in that certain 31*9c5db199SXin Li default behaviors are different. 32*9c5db199SXin Li 33*9c5db199SXin LiFor all subcommands, the servo part of the assembly must be fully 34*9c5db199SXin Lifunctional for deployment to succeed. 35*9c5db199SXin Li 36*9c5db199SXin LiFor all subcommands except the `servo` subcommand, installing the 37*9c5db199SXin Licurrent repair imge on the servo's USB stick may be skipped to save 38*9c5db199SXin Litime. If this step is skipped, the user is responsible for making 39*9c5db199SXin Lisure the correct image is on the stick prior to running the command. 40*9c5db199SXin Li 41*9c5db199SXin LiFor the `servo` subcommand, the DUT need not be present or in working 42*9c5db199SXin Liorder. Other subcommands require the DUT to meet certain requirements, 43*9c5db199SXin Lioutlined below. 44*9c5db199SXin Li 45*9c5db199SXin LiFor the `firmware` subcommand, the DUT must begin in dev-mode, with 46*9c5db199SXin Lihardware write-protect disabled. At successful completion, the DUT is 47*9c5db199SXin Liin verified boot mode. 48*9c5db199SXin Li 49*9c5db199SXin LiFor the `test-image` and `repair` subcommands, the DUT must already have 50*9c5db199SXin Lidev-signed firmware installed, and must be in verified boot mode. 51*9c5db199SXin Li 52*9c5db199SXin Li## Available options: 53*9c5db199SXin Li 54*9c5db199SXin Li-w / --web SERVER 55*9c5db199SXin Li Specify an alternative AFE RPC service. 56*9c5db199SXin Li 57*9c5db199SXin Li-d / --dir DIRECTORY 58*9c5db199SXin Li Specify a directory where logs from the command will be stored. 59*9c5db199SXin Li By default, a new directory will be created under ~/Documents. 60*9c5db199SXin Li 61*9c5db199SXin Li-i / --build BUILD 62*9c5db199SXin Li Install the given BUILD onto the servo USB stick, and update the AFE 63*9c5db199SXin Li to make that build the default repair image for the target DUTS. 64*9c5db199SXin Li BUILD is specified in a form like 'R66-10447.0.0'. 65*9c5db199SXin Li 66*9c5db199SXin Li-f / --hostname_file FILE 67*9c5db199SXin Li Specifies a CSV formatted file with information about the target DUTs. 68*9c5db199SXin Li When supplied, this overrides any HOSTNAME arguments on the command 69*9c5db199SXin Li line. 70*9c5db199SXin Li 71*9c5db199SXin Li-b / --board BOARD 72*9c5db199SXin Li Specifies the board to assume for all target DUTs. 73*9c5db199SXin Li 74*9c5db199SXin Li-m / --model MODEL 75*9c5db199SXin Li Specifies the model to assume for all target DUTs. 76*9c5db199SXin Li 77*9c5db199SXin Li--[no]stageusb 78*9c5db199SXin Li This option isn't available for the `servo` subcommand. For other 79*9c5db199SXin Li subcommands, when true this option enables the servo validation and 80*9c5db199SXin Li installation steps performed by the `servo` subcommand. 81*9c5db199SXin Li 82*9c5db199SXin Li## Command line arguments: 83*9c5db199SXin Li 84*9c5db199SXin LiHOSTNAME ... 85*9c5db199SXin Li If no `-f` option is supplied, the command line must have a list of 86*9c5db199SXin Li the hostnames of the target DUTs. 87*9c5db199SXin Li""" 88*9c5db199SXin Li 89*9c5db199SXin Liimport sys 90*9c5db199SXin Li 91*9c5db199SXin Liimport common 92*9c5db199SXin Lifrom autotest_lib.site_utils.deployment import cmdparse 93*9c5db199SXin Lifrom autotest_lib.site_utils.deployment import install 94*9c5db199SXin Li 95*9c5db199SXin Li 96*9c5db199SXin Lidef main(argv): 97*9c5db199SXin Li """Standard main routine. 98*9c5db199SXin Li 99*9c5db199SXin Li @param argv Command line arguments including `sys.argv[0]`. 100*9c5db199SXin Li """ 101*9c5db199SXin Li install.install_duts(cmdparse.parse_command(argv)) 102*9c5db199SXin Li 103*9c5db199SXin Li 104*9c5db199SXin Liif __name__ == '__main__': 105*9c5db199SXin Li try: 106*9c5db199SXin Li main(sys.argv) 107*9c5db199SXin Li except KeyboardInterrupt: 108*9c5db199SXin Li pass 109*9c5db199SXin Li except EnvironmentError as e: 110*9c5db199SXin Li sys.stderr.write('Unexpected OS error:\n %s\n' % e) 111*9c5db199SXin Li except Exception as e: 112*9c5db199SXin Li sys.stderr.write('Unexpected exception:\n %s\n' % e) 113