1# Copyright 2018 The Chromium OS Authors. 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 5import logging 6import random 7import tempfile 8 9from autotest_lib.client.common_lib import file_utils 10 11_URL_BASE = ('https://sites.google.com/a/chromium.org/dev/chromium-os' 12 '/testing/power-testing/pltp') 13_PLTG_URL = _URL_BASE + '/pltg' 14_PLTU_URL = _URL_BASE + '/pltu_rand' 15_PLTP_URL = _URL_BASE + '/pltp_rand' 16_MEETU_URL = _URL_BASE + '/meetu' 17_MEETP_URL = _URL_BASE + '/meetp' 18 19 20def _get_content(url): 21 """Reads the content of the file at the given |URL|. 22 23 Args: 24 url: URL to be fetched. 25 26 Return: 27 The content of the fetched file. 28 """ 29 with tempfile.NamedTemporaryFile() as named_file: 30 file_utils.download_file(url, named_file.name) 31 # Need decode() since tempfile is opened as binary file 32 return named_file.read().rstrip().decode() 33 34 35def use_gaia_login(): 36 """Returns whether Gaia login should be used by default for load testing.""" 37 res = _get_content(_PLTG_URL) 38 return res == 'True' or res == 'true' 39 40 41def get_username(): 42 """Returns username for load testing.""" 43 names = _get_content(_PLTU_URL).splitlines() 44 name = random.choice(names).rstrip() 45 logging.info('power_load_util.get_username: %s', name) 46 return name 47 48 49def get_password(): 50 """Returns password for load testing.""" 51 return _get_content(_PLTP_URL) 52 53 54def get_meet_username(): 55 """Returns username for meet testing.""" 56 return _get_content(_MEETU_URL) 57 58 59def get_meet_password(): 60 """Returns password for meet testing.""" 61 return _get_content(_MEETP_URL) 62