• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 autoupdater, dev_server
10from autotest_lib.server.cros.dynamic_suite import tools
11
12
13def get_updater_from_repo_url(host, job_repo_url=None):
14    """Returns the autoupdater instance to use for a given autoupdate test.
15
16    All server-side tests that run in the lab have an associated job_repo_url
17    assigned to their host that is associated with the version of the build that
18    is currently installed on them. Given most autoupdate tests need to
19    update to some build as part of the test, we conveniently re-update to the
20    same version installed. This method serves as a helper to get the
21    instantiated autoupdater instance for that build.
22
23    This method guarantees that the devserver associated with the autoupdater
24    has already staged the necessary files for autoupdate.
25
26    @param host: The host for the DUT of the server-side test.
27    @param job_repo_url: If set, the job_repo_url to use.
28
29    @raise error.TestError: If we fail to get a job_repo_url.
30    """
31    # Get the job_repo_url -- if not present, attempt to use the one
32    # specified in the host attributes for the host.
33    if not job_repo_url:
34        info = host.host_info_store.get()
35        job_repo_url = info.attributes.get(host.job_repo_url_attribute, '')
36        if not job_repo_url:
37            raise error.TestError(
38                    'Could not find a job_repo_url for the given host.')
39
40    # Get the devserver url and build (image) from the repo url e.g.
41    # 'http://mydevserver:8080', 'x86-alex-release/R27-123.0.0'
42    ds_url, build = tools.get_devserver_build_from_package_url(job_repo_url)
43    devserver = dev_server.ImageServer(ds_url)
44    devserver.stage_artifacts(build, ['full_payload', 'stateful'])
45
46    # We only need to update stateful to do this test.
47    return autoupdater.ChromiumOSUpdater(devserver.get_update_url(build),
48                                         host=host)
49