blob: 2b0f27d6090170a0fea4c6e836e8c09eb7ce37e2 [file] [log] [blame]
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
AUTHOR = "Chromium OS"
NAME = "Auto Update Host"
TIME = "MEDIUM"
TEST_CATEGORY = "Functional"
TEST_CLASS = "platform"
TEST_TYPE = "server"
DOC = """
A test that reimages the assigned machines and checks for success.
Can only be used by test suites based on server.cros.dynamic_suite.Suite.
Assumes that a label including the image name has already been created.
@param image_url: the devserver URL at which the image to install is served.
@param image_name: the name of the image, used to label the device
"""
from autotest_lib.server import frontend
vers = 'cros-version:'
repo_url = None
if 'image_name' in locals():
from autotest_lib.server.cros import dynamic_suite
vers = dynamic_suite.VERSION_PREFIX
repo_url = dynamic_suite._package_url_pattern() % image_name
AFE = frontend.AFE(debug=False)
def clear_version_labels(machine):
"""Clear all build-specific labels, attributes from the target.
Copied from server/cros/dynamic_suite.py, because we can't be sure that
code will be available in all contexts in which this control file is
currently used.
@param machine: the host to clear labels, attributes from.
"""
labels = AFE.get_labels(name__startswith=vers)
for label in labels: label.remove_hosts(hosts=[machine])
AFE.set_host_attribute('job_repo_url', None, hostname=machine)
def run(machine):
clear_version_labels(machine)
host = hosts.create_host(machine, initialize=False)
if job.run_test('autoupdate', host=host, update_url=image_url):
label = AFE.get_labels(name=vers+image_name)[0]
label.add_hosts([machine])
AFE.set_host_attribute('job_repo_url', repo_url, hostname=machine)
job.parallel_simple(run, machines)