1 # Copyright 2017 Google Inc. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 """Stub host object for Libiota devices.""" 6 7 import common 8 9 from autotest_lib.client.common_lib import error 10 from autotest_lib.client.common_lib.cros import dev_server 11 from autotest_lib.server import afe_utils 12 from autotest_lib.server.cros.dynamic_suite import constants as ds_constants 13 from autotest_lib.server.cros.dynamic_suite import tools 14 from autotest_lib.server.hosts import abstract_ssh 15 16 17 ARCHIVE_URL = ('https://pantheon.corp.google.com/storage/browser/' 18 'abuildbot-build-archive/bbuildbot/libiota') 19 20 21 class IotaHost(abstract_ssh.AbstractSSHHost): 22 """Provides a stub for downloading the Libiota autotest package.""" 23 24 VERSION_PREFIX = 'iota-version' 25 26 def stage_server_side_package(self, image=None): 27 """Stage autotest server-side package on devserver. 28 29 @param image: Full path of an OS image to install or a build name. 30 31 @return: A url to the autotest server-side package. 32 33 @raise: error.AutoservError if fail to locate the build to test with, or 34 fail to stage server-side package. 35 """ 36 if image: 37 image_name = tools.get_build_from_image(image) 38 if not image_name: 39 raise error.AutoservError( 40 'Failed to parse build name from %s' % image) 41 ds = dev_server.ImageServer.resolve(image_name) 42 else: 43 job_repo_url = afe_utils.get_host_attribute( 44 self, ds_constants.JOB_REPO_URL) 45 if job_repo_url: 46 devserver_url, image_name = ( 47 tools.get_devserver_build_from_package_url(job_repo_url) 48 ) 49 ds = dev_server.ImageServer.resolve(image_name) 50 else: 51 labels = afe_utils.get_labels(self, self.VERSION_PREFIX) 52 if not labels: 53 raise error.AutoservError( 54 'Failed to stage server-side package. The host has ' 55 'no job_report_url attribute or version label.') 56 image_name = labels[0][len(self.VERSION_PREFIX + ':'):] 57 ds = dev_server.ImageServer.resolve(image_name) 58 59 ds.stage_artifacts(image_name, ['autotest_server_package'], 60 archive_url=ARCHIVE_URL+image_name) 61 return '%s/static/%s/%s' % (ds.url(), image_name, 62 'autotest_server_package.tar.bz2') 63