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 |
Dhanya Ganesh | 2b29ad1 | 2020-09-22 22:18:58 +0000 | [diff] [blame] | 8 | import subprocess |
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.""" |
Brigit Rossbach | f951d8d | 2020-09-22 11:22:01 -0600 | [diff] [blame] | 36 | global NEW_SUITE_SCHEDULER_CONFIG_FILE |
| 37 | global NEW_LAB_CONFIG_FILE |
Brigit Rossbach | 9d12444 | 2020-09-23 09:31:36 -0600 | [diff] [blame^] | 38 | temp_dir = '/tmp/config-internal' |
Brigit Rossbach | 50d086f | 2020-09-17 13:29:49 -0600 | [diff] [blame] | 39 | cmd = 'git clone --depth 1 https://chrome-internal.googlesource.com/chromeos/config-internal {}'.format( |
| 40 | temp_dir) |
| 41 | logging.info('Cloning internal config repo.') |
| 42 | if (NEW_SUITE_SCHEDULER_CONFIG_FILE is None or NEW_LAB_CONFIG_FILE is None): |
| 43 | try: |
Dhanya Ganesh | 2b29ad1 | 2020-09-22 22:18:58 +0000 | [diff] [blame] | 44 | stdout = subprocess.check_output([cmd], shell=True) |
| 45 | logging.info(stdout) |
Brigit Rossbach | 50d086f | 2020-09-17 13:29:49 -0600 | [diff] [blame] | 46 | suite_scheduler_path = os.path.join(temp_dir, 'test', 'suite_scheduler', |
| 47 | 'generated') |
| 48 | NEW_SUITE_SCHEDULER_CONFIG_FILE = os.path.join(suite_scheduler_path, |
| 49 | 'suite_scheduler.ini') |
| 50 | NEW_LAB_CONFIG_FILE = os.path.join(suite_scheduler_path, |
| 51 | 'lab_config.ini') |
Dhanya Ganesh | 98e6603 | 2020-09-22 21:19:12 +0000 | [diff] [blame] | 52 | if not os.path.exists(NEW_SUITE_SCHEDULER_CONFIG_FILE): |
Dhanya Ganesh | e57ac45 | 2020-09-22 20:58:04 +0000 | [diff] [blame] | 53 | logging.error('suite_scheduler.ini does not exist.') |
Dhanya Ganesh | 98e6603 | 2020-09-22 21:19:12 +0000 | [diff] [blame] | 54 | if not os.path.exists(NEW_LAB_CONFIG_FILE): |
Dhanya Ganesh | e57ac45 | 2020-09-22 20:58:04 +0000 | [diff] [blame] | 55 | logging.error('lab_config.ini does not exist.') |
Brigit Rossbach | 50d086f | 2020-09-17 13:29:49 -0600 | [diff] [blame] | 56 | except Exception as e: |
| 57 | logging.error(str(e)) |
| 58 | |
Xixuan Wu | 26d06e0 | 2017-09-20 14:50:28 -0700 | [diff] [blame] | 59 | # Service account secret json file used for staging project. |
| 60 | STAGING_CLIENT_SECRETS_FILE = os.path.join( |
Xixuan Wu | 865fa28 | 2017-09-05 15:23:19 -0700 | [diff] [blame] | 61 | CREDENTIALS_PATH, |
| 62 | 'suite-scheduler-staging_client_secret_service_account.json') |
Xixuan Wu | 26d06e0 | 2017-09-20 14:50:28 -0700 | [diff] [blame] | 63 | |
| 64 | # Service account secret json file used for prod project. |
| 65 | PROD_CLIENT_SECRETS_FILE = os.path.join( |
Prathmesh Prabhu | 8dff3e2 | 2020-06-23 13:49:45 -0700 | [diff] [blame] | 66 | CREDENTIALS_PATH, 'suite-scheduler_client_secret_service_account.json') |