blob: 9ee0a273ca7daef9ffb1d65907e22c5142963d5b [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
7import logging
8
9import common
10from autotest_lib.client.common_lib import error
11from autotest_lib.client.common_lib.cros import autoupdater, dev_server
Dan Shi8190eb82016-02-11 17:15:58 -080012from autotest_lib.server import afe_utils
Chris Sosac1932172013-10-16 13:28:53 -070013from autotest_lib.server.cros.dynamic_suite import tools
14
15
16def get_updater_from_repo_url(host, job_repo_url=None):
17 """Returns the autoupdater instance to use for a given autoupdate test.
18
19 All server-side tests that run in the lab have an associated job_repo_url
20 assigned to their host that is associated with the version of the build that
21 is currently installed on them. Given most autoupdate tests need to
22 update to some build as part of the test, we conveniently re-update to the
23 same version installed. This method serves as a helper to get the
24 instantiated autoupdater instance for that build.
25
26 This method guarantees that the devserver associated with the autoupdater
27 has already staged the necessary files for autoupdate.
28
29 @param host: The host for the DUT of the server-side test.
30 @param job_repo_url: If set, the job_repo_url to use.
31
32 @raise error.TestError: If we fail to get a job_repo_url.
33 """
34 # Get the job_repo_url -- if not present, attempt to use the one
35 # specified in the host attributes for the host.
36 if not job_repo_url:
37 try:
Dan Shi8190eb82016-02-11 17:15:58 -080038 job_repo_url = afe_utils.lookup_job_repo_url(host)
Chris Sosac1932172013-10-16 13:28:53 -070039 except KeyError:
40 logging.fatal('Could not lookup job_repo_url from afe.')
41
42 if not job_repo_url:
43 raise error.TestError(
44 'Could not find a job_repo_url for the given host.')
45
46 # Get the devserver url and build (image) from the repo url e.g.
47 # 'http://mydevserver:8080', 'x86-alex-release/R27-123.0.0'
48 ds_url, build = tools.get_devserver_build_from_package_url(job_repo_url)
49 devserver = dev_server.ImageServer(ds_url)
50 devserver.stage_artifacts(build, ['full_payload', 'stateful'])
51
52 # We only need to update stateful to do this test.
53 return autoupdater.ChromiumOSUpdater(devserver.get_update_url(build),
54 host=host)