-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config: allow reading teuthology config from env var location #1998
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,12 @@ | |
from collections import MutableMapping | ||
|
||
|
||
# Configuration constants | ||
SYSTEM_CONFIG_PATH = '/etc/teuthology.yaml' | ||
USER_CONFIG_PATH = '~/.teuthology.yaml' | ||
CONFIG_PATH_VAR_NAME = 'TEUTHOLOGY_CONFIG' # name of env var to check | ||
|
||
|
||
def init_logging(): | ||
log = logging.getLogger(__name__) | ||
return log | ||
|
@@ -135,9 +141,9 @@ class TeuthologyConfig(YamlConfig): | |
""" | ||
This class is intended to unify teuthology's many configuration files and | ||
objects. Currently it serves as a convenient interface to | ||
~/.teuthology.yaml and nothing else. | ||
~/.teuthology.yaml or equivalent. | ||
""" | ||
yaml_path = os.path.join(os.path.expanduser('~/.teuthology.yaml')) | ||
yaml_path = USER_CONFIG_PATH # yaml_path is updated in _get_config_path | ||
_defaults = { | ||
'archive_base': '/home/teuthworker/archive', | ||
'archive_upload': None, | ||
|
@@ -285,10 +291,20 @@ def set_config_attr(obj): | |
|
||
|
||
def _get_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 | ||
"""Look for a teuthology config yaml and return it's path. | ||
Raises ValueError if no config yaml can be found. | ||
""" | ||
paths = [ | ||
os.path.join(os.path.expanduser(USER_CONFIG_PATH)), | ||
SYSTEM_CONFIG_PATH, | ||
] | ||
if CONFIG_PATH_VAR_NAME in os.environ: | ||
paths.insert(0, os.path.expanduser(os.environ[CONFIG_PATH_VAR_NAME])) | ||
for path in paths: | ||
if os.path.exists(path): | ||
return path | ||
log.warning(f"no teuthology config found, looked for: {paths}") | ||
return None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea was to always return a meaningful value, see usage of config constructor below. |
||
|
||
|
||
config = TeuthologyConfig(yaml_path=_get_config_path()) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess if drop this line you have to update the comment above about "interface to ~/.teuthology.yaml and nothing else".