From 0410a2f3ee827482345a1be6cf89b0016e546949 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Fri, 9 Aug 2024 10:15:15 -0400 Subject: [PATCH] config: allow reading teuthology config from env var location Allow changing the default "user" location of the teuthology configuration yaml using the (optional) TEUTHOLOGY_CONFIG environment variable. This change aids my effort to run a customized local teuthology environment. Signed-off-by: John Mulligan --- teuthology/config.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/teuthology/config.py b/teuthology/config.py index 30204aa46..893a042d4 100644 --- a/teuthology/config.py +++ b/teuthology/config.py @@ -137,7 +137,6 @@ class TeuthologyConfig(YamlConfig): objects. Currently it serves as a convenient interface to ~/.teuthology.yaml and nothing else. """ - yaml_path = os.path.join(os.path.expanduser('~/.teuthology.yaml')) _defaults = { 'archive_base': '/home/teuthworker/archive', 'archive_upload': None, @@ -285,10 +284,13 @@ def set_config_attr(obj): def _get_config_path(): + config_path = os.environ.get('TEUTHOLOGY_CONFIG', '~/.teuthology.yaml') + config_path = os.path.join(os.path.expanduser(config_path)) system_config_path = '/etc/teuthology.yaml' - if not os.path.exists(TeuthologyConfig.yaml_path) and \ - os.path.exists(system_config_path): - return system_config_path - return TeuthologyConfig.yaml_path + for path in (config_path, system_config_path): + if os.path.exists(path): + return path + return None + config = TeuthologyConfig(yaml_path=_get_config_path())