blob: cf1583c107115cdc51b1883b9a511cd4e0cf7ba7 [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 Rossbacheb611ac2020-09-24 14:55:24 -06006import base64
Brigit Rossbach50d086f2020-09-17 13:29:49 -06007import logging
xixuanbea010f2017-03-27 10:10:19 -07008import os
Dhanya Ganesh2b29ad12020-09-22 22:18:58 +00009import subprocess
Brigit Rossbacheb611ac2020-09-24 14:55:24 -060010import urllib2
xixuanbea010f2017-03-27 10:10:19 -070011
xixuanbea010f2017-03-27 10:10:19 -070012# The path to save credentials.
13CREDENTIALS_PATH = os.path.join(os.path.dirname(__file__), 'credentials')
14
xixuanbea010f2017-03-27 10:10:19 -070015# The path to save configs.
16CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'configs')
17
Xixuan Wu26d06e02017-09-20 14:50:28 -070018# The suite scheduler config file for testing.
Brigit Rossbach50d086f2020-09-17 13:29:49 -060019TEST_SUITE_SCHEDULER_CONFIG_FILE = os.path.join(CONFIG_PATH,
20 'fake_suite_scheduler.ini')
xixuanbea010f2017-03-27 10:10:19 -070021
Brigit Rossbach50d086f2020-09-17 13:29:49 -060022# Test lab config file
23TEST_LAB_CONFIG_FILE = os.path.join(CONFIG_PATH, 'fake_lab_config.ini')
24
Jack Neus8f0edb42022-03-17 20:21:39 +000025# Test rubik boards config file
26TEST_RUBIK_CONFIG_FILE = os.path.join(CONFIG_PATH, 'fake_rubik_config.ini')
27
Brigit Rossbach50d086f2020-09-17 13:29:49 -060028# Suite scheduler config repo
29NEW_SUITE_SCHEDULER_CONFIG_FILE = None
30NEW_LAB_CONFIG_FILE = None
Jack Neus8f0edb42022-03-17 20:21:39 +000031NEW_RUBIK_CONFIG_FILE = None
Brigit Rossbach50d086f2020-09-17 13:29:49 -060032
Dhanya Ganesh643a49e2020-09-25 18:14:22 +000033def _write_config(config_name):
34 tot_response = urllib2.urlopen(
Brigit Rossbach30497242021-02-17 10:57:44 -070035 'https://chromium.googlesource.com/chromiumos/infra/suite_scheduler/+/refs/heads/main/generated_configs/{}?format=text'.format(config_name)
Dhanya Ganesh643a49e2020-09-25 18:14:22 +000036 ).read()
Dhanya Ganesh626da112020-09-25 18:42:20 +000037 config_text = base64.b64decode(tot_response)
Dhanya Ganesh643a49e2020-09-25 18:14:22 +000038 logging.info('Writing %s as: %s', config_name, config_text)
Dhanya Ganesh643a49e2020-09-25 18:14:22 +000039 filename = '/tmp/{}'.format(config_name)
40 with open(filename, 'w') as f:
41 f.write(config_text)
42 return filename
Brigit Rossbach50d086f2020-09-17 13:29:49 -060043
44def clone_config():
Brigit Rossbacheb611ac2020-09-24 14:55:24 -060045 """Function to clone the config for suite scheduler from the current head."""
Brigit Rossbachf951d8d2020-09-22 11:22:01 -060046 global NEW_SUITE_SCHEDULER_CONFIG_FILE
47 global NEW_LAB_CONFIG_FILE
Jack Neus8f0edb42022-03-17 20:21:39 +000048 global NEW_RUBIK_CONFIG_FILE
Brigit Rossbacheb611ac2020-09-24 14:55:24 -060049 logging.info('Fetching config from suite scheduler repo.')
Brigit Rossbachbdf25322020-10-21 11:54:25 -060050 try:
51 NEW_SUITE_SCHEDULER_CONFIG_FILE = _write_config('suite_scheduler.ini')
52 NEW_LAB_CONFIG_FILE = _write_config('lab_config.ini')
Jack Neus8f0edb42022-03-17 20:21:39 +000053 NEW_RUBIK_CONFIG_FILE = _write_config('rubik_config.ini')
Brigit Rossbachbdf25322020-10-21 11:54:25 -060054 except Exception as e:
55 logging.error(str(e))
Brigit Rossbach50d086f2020-09-17 13:29:49 -060056
Xixuan Wu26d06e02017-09-20 14:50:28 -070057# Service account secret json file used for staging project.
58STAGING_CLIENT_SECRETS_FILE = os.path.join(
Xixuan Wu865fa282017-09-05 15:23:19 -070059 CREDENTIALS_PATH,
60 'suite-scheduler-staging_client_secret_service_account.json')
Xixuan Wu26d06e02017-09-20 14:50:28 -070061
62# Service account secret json file used for prod project.
63PROD_CLIENT_SECRETS_FILE = os.path.join(
Prathmesh Prabhu8dff3e22020-06-23 13:49:45 -070064 CREDENTIALS_PATH, 'suite-scheduler_client_secret_service_account.json')