1# Lint as: python3 2# Copyright 2021 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import common 7import logging 8 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.common_lib.cros import dev_server 11from autotest_lib.utils import labellib 12from autotest_lib.server import test 13 14 15class platform_FetchCloudConfig(test.test): 16 """Reload fresh performance CUJ cloud configuration from cloud.""" 17 version = 1 18 19 def run_once(self, host): 20 devservers = dev_server.ImageServer.get_available_devservers() 21 devserver_url = devservers[0][0] 22 if devserver_url: 23 logging.info('Using devserver: %s', devserver_url) 24 labels = host.host_info_store.get().labels 25 build = labellib.LabelsMapping(labels).get( 26 labellib.Key.CROS_VERSION) 27 if not build: 28 # Not able to detect build, means not running on Moblab. 29 raise error.TestFail('Unable to stage config on devserver %s, ' 30 'probably not running in Moblab.' % 31 devserver_url) 32 ds = dev_server.ImageServer(devserver_url) 33 gs_bucket = dev_server._get_image_storage_server() 34 if gs_bucket: 35 config_path = 'config/perf_cuj/' 36 config_file = 'perf_cuj.config' 37 archive_url = gs_bucket + config_path 38 logging.info('Staging configuration from %s.', gs_bucket) 39 kwargs = {'clean': True} 40 ds.stage_artifacts(build, 41 archive_url=archive_url, 42 files=[config_file], 43 **kwargs) 44 else: 45 raise error.TestFail( 46 'Invalid GS bucket %s for devserver %s.' % gs_bucket, 47 devserver_url) 48