xixuan | bea010f | 2017-03-27 10:10:19 -0700 | [diff] [blame] | 1 | # Copyright 2017 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. |
xixuan | bea010f | 2017-03-27 10:10:19 -0700 | [diff] [blame] | 4 | """Module for fetching files used by suite scheduler.""" |
| 5 | |
Brigit Rossbach | 50d086f | 2020-09-17 13:29:49 -0600 | [diff] [blame^] | 6 | import logging |
xixuan | bea010f | 2017-03-27 10:10:19 -0700 | [diff] [blame] | 7 | import os |
Brigit Rossbach | 50d086f | 2020-09-17 13:29:49 -0600 | [diff] [blame^] | 8 | import tempfile |
xixuan | bea010f | 2017-03-27 10:10:19 -0700 | [diff] [blame] | 9 | |
xixuan | bea010f | 2017-03-27 10:10:19 -0700 | [diff] [blame] | 10 | # The path to save credentials. |
| 11 | CREDENTIALS_PATH = os.path.join(os.path.dirname(__file__), 'credentials') |
| 12 | |
xixuan | bea010f | 2017-03-27 10:10:19 -0700 | [diff] [blame] | 13 | # The path to save configs. |
| 14 | CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'configs') |
| 15 | |
| 16 | # Suite scheduler event config file |
Prathmesh Prabhu | 8dff3e2 | 2020-06-23 13:49:45 -0700 | [diff] [blame] | 17 | SUITE_SCHEDULER_CONFIG_FILE = os.path.join(CONFIG_PATH, 'suite_scheduler.ini') |
Xixuan Wu | 26d06e0 | 2017-09-20 14:50:28 -0700 | [diff] [blame] | 18 | |
| 19 | # The suite scheduler config file for testing. |
Brigit Rossbach | 50d086f | 2020-09-17 13:29:49 -0600 | [diff] [blame^] | 20 | TEST_SUITE_SCHEDULER_CONFIG_FILE = os.path.join(CONFIG_PATH, |
| 21 | 'fake_suite_scheduler.ini') |
xixuan | bea010f | 2017-03-27 10:10:19 -0700 | [diff] [blame] | 22 | |
| 23 | # Lab config file |
| 24 | LAB_CONFIG_FILE = os.path.join(CONFIG_PATH, 'lab_config.ini') |
| 25 | |
Brigit Rossbach | 50d086f | 2020-09-17 13:29:49 -0600 | [diff] [blame^] | 26 | # Test lab config file |
| 27 | TEST_LAB_CONFIG_FILE = os.path.join(CONFIG_PATH, 'fake_lab_config.ini') |
| 28 | |
| 29 | # Suite scheduler config repo |
| 30 | NEW_SUITE_SCHEDULER_CONFIG_FILE = None |
| 31 | NEW_LAB_CONFIG_FILE = None |
| 32 | |
| 33 | |
| 34 | def clone_config(): |
| 35 | """Function to clone the config for suite scheduler from the config-internal repo.""" |
| 36 | temp_dir = tempfile.mkdtemp() |
| 37 | cmd = 'git clone --depth 1 https://chrome-internal.googlesource.com/chromeos/config-internal {}'.format( |
| 38 | temp_dir) |
| 39 | logging.info('Cloning internal config repo.') |
| 40 | if (NEW_SUITE_SCHEDULER_CONFIG_FILE is None or NEW_LAB_CONFIG_FILE is None): |
| 41 | try: |
| 42 | os.system(cmd) |
| 43 | suite_scheduler_path = os.path.join(temp_dir, 'test', 'suite_scheduler', |
| 44 | 'generated') |
| 45 | NEW_SUITE_SCHEDULER_CONFIG_FILE = os.path.join(suite_scheduler_path, |
| 46 | 'suite_scheduler.ini') |
| 47 | NEW_LAB_CONFIG_FILE = os.path.join(suite_scheduler_path, |
| 48 | 'lab_config.ini') |
| 49 | except Exception as e: |
| 50 | logging.error(str(e)) |
| 51 | |
Xixuan Wu | 26d06e0 | 2017-09-20 14:50:28 -0700 | [diff] [blame] | 52 | # Service account secret json file used for staging project. |
| 53 | STAGING_CLIENT_SECRETS_FILE = os.path.join( |
Xixuan Wu | 865fa28 | 2017-09-05 15:23:19 -0700 | [diff] [blame] | 54 | CREDENTIALS_PATH, |
| 55 | 'suite-scheduler-staging_client_secret_service_account.json') |
Xixuan Wu | 26d06e0 | 2017-09-20 14:50:28 -0700 | [diff] [blame] | 56 | |
| 57 | # Service account secret json file used for prod project. |
| 58 | PROD_CLIENT_SECRETS_FILE = os.path.join( |
Prathmesh Prabhu | 8dff3e2 | 2020-06-23 13:49:45 -0700 | [diff] [blame] | 59 | CREDENTIALS_PATH, 'suite-scheduler_client_secret_service_account.json') |