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