blob: 20676beedf7bb139e3205a712151186edd51da6c [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
18# Suite scheduler event config file
Prathmesh Prabhu8dff3e22020-06-23 13:49:45 -070019SUITE_SCHEDULER_CONFIG_FILE = os.path.join(CONFIG_PATH, 'suite_scheduler.ini')
Xixuan Wu26d06e02017-09-20 14:50:28 -070020
21# The suite scheduler config file for testing.
Brigit Rossbach50d086f2020-09-17 13:29:49 -060022TEST_SUITE_SCHEDULER_CONFIG_FILE = os.path.join(CONFIG_PATH,
23 'fake_suite_scheduler.ini')
xixuanbea010f2017-03-27 10:10:19 -070024
25# Lab config file
26LAB_CONFIG_FILE = os.path.join(CONFIG_PATH, 'lab_config.ini')
27
Brigit Rossbach50d086f2020-09-17 13:29:49 -060028# Test lab config file
29TEST_LAB_CONFIG_FILE = os.path.join(CONFIG_PATH, 'fake_lab_config.ini')
30
31# Suite scheduler config repo
32NEW_SUITE_SCHEDULER_CONFIG_FILE = None
33NEW_LAB_CONFIG_FILE = None
34
Dhanya Ganesh643a49e2020-09-25 18:14:22 +000035def _write_config(config_name):
36 tot_response = urllib2.urlopen(
37 'https://chromium.googlesource.com/chromiumos/infra/suite_scheduler/+/refs/heads/master/generated_configs/{}?format=text'.format(config_name)
38 ).read()
Dhanya Ganesh626da112020-09-25 18:42:20 +000039 config_text = base64.b64decode(tot_response)
Dhanya Ganesh643a49e2020-09-25 18:14:22 +000040 logging.info('Writing %s as: %s', config_name, config_text)
41 print(config_text)
42 filename = '/tmp/{}'.format(config_name)
43 with open(filename, 'w') as f:
44 f.write(config_text)
45 return filename
Brigit Rossbach50d086f2020-09-17 13:29:49 -060046
47def clone_config():
Brigit Rossbacheb611ac2020-09-24 14:55:24 -060048 """Function to clone the config for suite scheduler from the current head."""
Brigit Rossbachf951d8d2020-09-22 11:22:01 -060049 global NEW_SUITE_SCHEDULER_CONFIG_FILE
50 global NEW_LAB_CONFIG_FILE
Brigit Rossbacheb611ac2020-09-24 14:55:24 -060051 logging.info('Fetching config from suite scheduler repo.')
Brigit Rossbach50d086f2020-09-17 13:29:49 -060052 if (NEW_SUITE_SCHEDULER_CONFIG_FILE is None or NEW_LAB_CONFIG_FILE is None):
53 try:
Dhanya Ganesh643a49e2020-09-25 18:14:22 +000054 NEW_SUITE_SCHEDULER_CONFIG_FILE = _write_config('suite_scheduler.ini')
55 NEW_LAB_CONFIG_FILE = _write_config('lab_config.ini')
Brigit Rossbach50d086f2020-09-17 13:29:49 -060056 except Exception as e:
57 logging.error(str(e))
58
Xixuan Wu26d06e02017-09-20 14:50:28 -070059# Service account secret json file used for staging project.
60STAGING_CLIENT_SECRETS_FILE = os.path.join(
Xixuan Wu865fa282017-09-05 15:23:19 -070061 CREDENTIALS_PATH,
62 'suite-scheduler-staging_client_secret_service_account.json')
Xixuan Wu26d06e02017-09-20 14:50:28 -070063
64# Service account secret json file used for prod project.
65PROD_CLIENT_SECRETS_FILE = os.path.join(
Prathmesh Prabhu8dff3e22020-06-23 13:49:45 -070066 CREDENTIALS_PATH, 'suite-scheduler_client_secret_service_account.json')