blob: 7842876d14a9fad72d4a0d8bd9e7d4b058e88aca [file] [log] [blame]
Chris Sosac1932172013-10-16 13:28:53 -07001# 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
Chris Sosac1932172013-10-16 13:28:53 -07007import common
8from autotest_lib.client.common_lib import error
9from autotest_lib.client.common_lib.cros import autoupdater, dev_server
Dan Shi8190eb82016-02-11 17:15:58 -080010from autotest_lib.server import afe_utils
Chris Sosac1932172013-10-16 13:28:53 -070011from 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:
Gwendal Grignoud8b90932016-04-21 14:39:17 -070035 job_repo_url = afe_utils.get_host_attribute(
36 host, host.job_repo_url_attribute)
Chris Sosac1932172013-10-16 13:28:53 -070037 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)