power_load_util.py revision 2cdff1919ab4867b79410f1e2c6d92a2af3fcbf3
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 tempfile
6
7from autotest_lib.client.common_lib import file_utils
8
9
10_URL_BASE = ('https://sites.google.com/a/chromium.org/dev/chromium-os'
11             '/testing/power-testing/pltp')
12_PLTU_URL = _URL_BASE + '/pltu'
13_PLTP_URL = _URL_BASE + '/pltp'
14
15
16def _get_content(url):
17    """Reads the content of the file at the given |URL|.
18
19    Args:
20        url: URL to be fetched.
21
22    Return:
23        The content of the fetched file.
24    """
25    with tempfile.NamedTemporaryFile() as named_file:
26        file_utils.download_file(url, named_file.name)
27        return named_file.read().rstrip()
28
29
30def get_username():
31    """Returns username for load testing."""
32    return _get_content(_PLTU_URL)
33
34
35def get_password():
36    """Returns password for load testing."""
37    return _get_content(_PLTP_URL)
38