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