1# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 1 2# Use of this source code is governed by a BSD-style license that can be 2 3# found in the LICENSE file. 4 5"Module containing common utilities for server-side autoupdate tests." 6 7import common 8from autotest_lib.client.common_lib import error 9from autotest_lib.client.common_lib.cros import dev_server 10from autotest_lib.server.cros import autoupdater 11from autotest_lib.server.cros.dynamic_suite import tools 12 13 14def get_updater_from_repo_url(host, job_repo_url=None): 15 """Returns the autoupdater instance to use for a given autoupdate test. 16 17 All server-side tests that run in the lab have an associated job_repo_url 18 assigned to their host that is associated with the version of the build that 19 is currently installed on them. Given most autoupdate tests need to 20 update to some build as part of the test, we conveniently re-update to the 21 same version installed. This method serves as a helper to get the 22 instantiated autoupdater instance for that build. 23 24 This method guarantees that the devserver associated with the autoupdater 25 has already staged the necessary files for autoupdate. 26 27 @param host: The host for the DUT of the server-side test. 28 @param job_repo_url: If set, the job_repo_url to use. 29 30 @raise error.TestError: If we fail to get a job_repo_url. 31 """ 32 # Get the job_repo_url -- if not present, attempt to use the one 33 # specified in the host attributes for the host. 34 if not job_repo_url: 35 info = host.host_info_store.get() 36 job_repo_url = info.attributes.get(host.job_repo_url_attribute, '') 37 if not job_repo_url: 38 raise error.TestError( 39 'Could not find a job_repo_url for the given host.') 40 41 # Get the devserver url and build (image) from the repo url e.g. 42 # 'http://mydevserver:8080', 'x86-alex-release/R27-123.0.0' 43 ds_url, build = tools.get_devserver_build_from_package_url(job_repo_url) 44 devserver = dev_server.ImageServer(ds_url) 45 devserver.stage_artifacts(build, ['full_payload', 'stateful']) 46 47 # We only need to update stateful to do this test. 48 return autoupdater.ChromiumOSUpdater(devserver.get_update_url(build), 49 host=host) 50