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 5import logging 6from autotest_lib.client.common_lib import error, utils 7from autotest_lib.client.cros import constants 8from autotest_lib.server import host_attributes 9 10AUTHOR = "Chromium OS" 11NAME = "autoupdate_EndToEndTest" 12TIME = "MEDIUM" 13TEST_CATEGORY = "Functional" 14TEST_CLASS = "platform" 15TEST_TYPE = "server" 16JOB_RETRIES = 1 17BUG_TEMPLATE = { 18 'cc': ['chromeos-installer-alerts@google.com'], 19 'labels': ['Cr-Internals-Installer'], 20} 21 22# Disable server-side packaging support for this test. 23# This control file is used as the template for paygen_au_canary suite, which 24# creates the control files during paygen. Therefore, autotest server package 25# does not have these test control files for paygen_au_canary suite. 26REQUIRE_SSP = False 27 28DOC = """ 29This is an end-to-end update test of Chrome OS releases. Given a test 30configuration, it will perform an end-to-end test of a Chrome OS update 31payload. A test configuration can be given as command-line arguments (see 32below) or instantiated inline as local varibles. 33 34To invoke this test locally: 35 36 test_that --args="<ARGLIST>" <DUT-IPADDR> autoupdate_EndToEndTest 37 38where ARGLIST is a whitespace separated list of the following key=value pairs. 39Values pertaining to the test case include: 40 41 name=TAG name tag for the test (e.g. 'nmo', 'npo' or 'fsi') 42 update_type=full|delta type of update being applied, either 'full' or 'delta' 43 source_release=REL source image release version (e.g. 2672.0.0) 44 target_release=REL target image release version (e.g. 2673.0.0) 45 source_payload_uri=URI URI of the source full payload. None means don't 46 install a source image (assume it's preinstalled). 47 source_archive_uri=URI (optional) URI of where the artifacts for the source 48 image (e.g. stateful update) are located. If not 49 provided, the test will attempt using the same 50 location as source_payload_uri. This is required for 51 any test where the location of the full (source) 52 payload is separate from that of its build artifacts 53 (e.g. it is in gs://chromeos-releases/). 54 target_payload_uri=URI URI of the target payload 55 target_archive_uri=URI (optional) URI of where the artifacts for the target 56 image (e.g. stateful update) are located. If not 57 provided, the test will attempt using the test job's 58 repo ID (if present), otherwise default to the same 59 location as target_payload_uri. Normally, this is 60 only needed for local (non-AFE) runs where the 61 payload location is separate from that of the build 62 artifacts (e.g. it is in gs://chromeos-releases). 63 64Please note, this test spawns omaha server instances (devserver) on a devserver 65configured in your global_config using autotest's ssh mechanism. This means that 66if you are running this locally and intend to use a local devserver, you will 67need to setup your ssh keys for public key authentication e.g. create keys, 68ssh-add the private key, add the public key to your authorized keys and finally 69enable public key authentication in your sshd config. 70 71To run locally: 72 Create src/third_party/autotest/files/shadow_config.ini: 73 [CROS] 74 devserver_dir = <full repo path>/src/platform/dev 75 dev_server = http://<hostname>:8080 76 77 Configure SSH for passwordless loopback access to your account. 78 ssh-keygen (If you don't already have SSH keys setup) 79 cp ~/.ssh/id_rsa chroot/home/<user>/.ssh/ 80 81 # This is NOT permanent, you'll have to redo it about once a day. 82 sudo sed -i 's/PubkeyAuthentication no/PubkeyAuthentication yes/' \ 83 /etc/ssh/sshd_config 84 sudo /etc/init.d/ssh restart 85 86 Enter a chroot, and ssh to <hostname>. If it doesn't work, fix that. 87 88 Make sure you have your gsutil permissions (your .boto file). 89 Your .boto file must be available inside the chroot. 90 cp ~/.boto chroot/home/<user>/ 91 92 Make sure the gsutil command is available outside the chroot (note: 93 the gsutil package in Ubuntu is not what you're looking for.) 94 95 Start a devserver (outside the chroot): 96 src/platform/dev/devserver.py 97 98 (Note: DO NOT use start_devserver! Even though it gives the impression of 99 running the server outside the chroot, it actually starts a chroot and runs 100 the server inside of it.) 101 102 To make sure your test edits are used: 103 cros_sdk 104 cros_workon start autotest 105 106 Example: 107 cros_sdk 108 test_that <dut_ip> autoupdate_EndToEndTest \ 109 --args="target_release=<Target Build Id> \ 110 source_payload_uri=<Full Payload URI> \ 111 target_payload_uri=<Tested Payload URI>" 112 113 Sample full payload URL: 114 gs://chromeos-image-archive/lumpy-release/R30-4462.0.0/ 115 chromeos_R30-4462.0.0_lumpy_full_dev.bin 116 117 Sample target build id: 118 4463.0.0 119 120 Sample test payload URL: 121 gs://chromeos-image-archive/lumpy-release/R30-4463.0.0/ 122 chromeos_R30-4462.0.0_R30-4463.0.0_lumpy_delta_dev.bin 123""" 124 125TEST_CONF_KEYS = ( 126 'name', 'update_type', 'source_release', 'target_release', 127 'source_payload_uri', 'source_archive_uri', 'target_payload_uri', 128 'target_archive_uri') 129 130 131args_dict = utils.args_to_dict(args) 132 133# Create test configuration based on command-line arguments (higher precedence, 134# for test_that invocation) and local variables (lower precedence, 135# for Autotest front-end invocation). 136test_conf = {} 137for key in TEST_CONF_KEYS: 138 test_conf[key] = args_dict.get(key) or locals().get(key) 139 140 141def run_test(machine): 142 """Execute a test configuration on a given machine.""" 143 host = hosts.create_host(machine) 144 # Save preserved log after autoupdate is completed. 145 job.sysinfo.add_logdir(constants.AUTOUPDATE_PRESERVE_LOG) 146 try: 147 job.run_test( 148 "autoupdate_EndToEndTest", 149 tag='%s_%s' % (test_conf['name'], test_conf['update_type']), 150 host=host, test_conf=test_conf) 151 except Exception as e: 152 if not issubclass(type(e), error.TestBaseException): 153 error_msg = 'Received test error: %s' % e 154 logging.error(error_msg) 155 raise error.TestError(error_msg) 156 157 raise 158 159 160# Invoke parallel tests. 161parallel_simple(run_test, machines) 162