blob: 29413394c3004aae43567bc565daf516576e356a [file] [log] [blame]
xixuanbea010f2017-03-27 10:10:19 -07001# 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.
xixuanbea010f2017-03-27 10:10:19 -07004"""Module for fetching files used by suite scheduler."""
5
Brigit Rossbach50d086f2020-09-17 13:29:49 -06006import logging
xixuanbea010f2017-03-27 10:10:19 -07007import os
Dhanya Ganesh2b29ad12020-09-22 22:18:58 +00008import subprocess
Brigit Rossbach50d086f2020-09-17 13:29:49 -06009import tempfile
xixuanbea010f2017-03-27 10:10:19 -070010
xixuanbea010f2017-03-27 10:10:19 -070011# The path to save credentials.
12CREDENTIALS_PATH = os.path.join(os.path.dirname(__file__), 'credentials')
13
xixuanbea010f2017-03-27 10:10:19 -070014# The path to save configs.
15CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'configs')
16
17# Suite scheduler event config file
Prathmesh Prabhu8dff3e22020-06-23 13:49:45 -070018SUITE_SCHEDULER_CONFIG_FILE = os.path.join(CONFIG_PATH, 'suite_scheduler.ini')
Xixuan Wu26d06e02017-09-20 14:50:28 -070019
20# The suite scheduler config file for testing.
Brigit Rossbach50d086f2020-09-17 13:29:49 -060021TEST_SUITE_SCHEDULER_CONFIG_FILE = os.path.join(CONFIG_PATH,
22 'fake_suite_scheduler.ini')
xixuanbea010f2017-03-27 10:10:19 -070023
24# Lab config file
25LAB_CONFIG_FILE = os.path.join(CONFIG_PATH, 'lab_config.ini')
26
Brigit Rossbach50d086f2020-09-17 13:29:49 -060027# Test lab config file
28TEST_LAB_CONFIG_FILE = os.path.join(CONFIG_PATH, 'fake_lab_config.ini')
29
30# Suite scheduler config repo
31NEW_SUITE_SCHEDULER_CONFIG_FILE = None
32NEW_LAB_CONFIG_FILE = None
33
34
35def clone_config():
36 """Function to clone the config for suite scheduler from the config-internal repo."""
Brigit Rossbachf951d8d2020-09-22 11:22:01 -060037 global NEW_SUITE_SCHEDULER_CONFIG_FILE
38 global NEW_LAB_CONFIG_FILE
Brigit Rossbach50d086f2020-09-17 13:29:49 -060039 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 Ganesh2b29ad12020-09-22 22:18:58 +000045 stdout = subprocess.check_output([cmd], shell=True)
46 logging.info(stdout)
Brigit Rossbach50d086f2020-09-17 13:29:49 -060047 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 Ganesh98e66032020-09-22 21:19:12 +000053 if not os.path.exists(NEW_SUITE_SCHEDULER_CONFIG_FILE):
Dhanya Ganeshe57ac452020-09-22 20:58:04 +000054 logging.error('suite_scheduler.ini does not exist.')
Dhanya Ganesh98e66032020-09-22 21:19:12 +000055 if not os.path.exists(NEW_LAB_CONFIG_FILE):
Dhanya Ganeshe57ac452020-09-22 20:58:04 +000056 logging.error('lab_config.ini does not exist.')
Brigit Rossbach50d086f2020-09-17 13:29:49 -060057 except Exception as e:
58 logging.error(str(e))
59
Xixuan Wu26d06e02017-09-20 14:50:28 -070060# Service account secret json file used for staging project.
61STAGING_CLIENT_SECRETS_FILE = os.path.join(
Xixuan Wu865fa282017-09-05 15:23:19 -070062 CREDENTIALS_PATH,
63 'suite-scheduler-staging_client_secret_service_account.json')
Xixuan Wu26d06e02017-09-20 14:50:28 -070064
65# Service account secret json file used for prod project.
66PROD_CLIENT_SECRETS_FILE = os.path.join(
Prathmesh Prabhu8dff3e22020-06-23 13:49:45 -070067 CREDENTIALS_PATH, 'suite-scheduler_client_secret_service_account.json')