Modify the config.py to allow using env vars#2109
Open
Leaf-Lin wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates Rally’s configuration loading to support environment-variable-based substitution in rally.ini, enabling values like datastore.password to be sourced from env vars at load time.
Changes:
- Switches config template substitution to include all
os.environvariables. - Updates imports to use
osdirectly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| with open(self.location, encoding="utf-8") as src: | ||
| contents = src.read() | ||
| contents = Template(contents).substitute(CONFIG_DIR=self.config_dir) | ||
| contents = Template(contents).safe_substitute({"CONFIG_DIR": self.config_dir, **os.environ}) |
| with open(self.location, encoding="utf-8") as src: | ||
| contents = src.read() | ||
| contents = Template(contents).substitute(CONFIG_DIR=self.config_dir) | ||
| contents = Template(contents).safe_substitute({"CONFIG_DIR": self.config_dir, **os.environ}) |
Comment on lines
+64
to
65
| contents = Template(contents).safe_substitute({"CONFIG_DIR": self.config_dir, **os.environ}) | ||
| config.read_string(contents, source=self.location) |
Member
Author
Member
|
buildkite test this please (sorry, using this PR to test an unrelated webhook change) |
Member
|
buildkite test this please |
gbanasiak
reviewed
May 13, 2026
gbanasiak
left a comment
Contributor
There was a problem hiding this comment.
Thanks for this logical extension.
- Any specific reason for switching from
substitute()tosafe_substitute()? I think throwing an error if any of the identifiers is missing makes sense, so I would keepsubstitute(). - Regarding the order, I think
CONFIG_DIRfollowed by env vars makes sense, i.e. we want to be able to override the defaults. - Existing Rally env vars begin with
RALLY_(e.g.RALLY_HOMEor the mentionedRALLY_REPORTING_DATASTORE_PASSWORD). This change surfacesCONFIG_DIRin a sense. To keep some consistency I would renameCONFIG_DIRtoRALLY_CONFIG_DIR(please updateesrally/resources/rally.ini). - Please update
docs/configuration.rstmentioning the new feature.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A small change to allow the
datastore.passwordand any other values fromrally.inito take from environmental variable.