fix: more robust config file modifications in install-deadline-worker #512
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.
What was the problem/requirement? (What/Why)
Background
The worker agent provides a
install-deadline-worker
CLI command that is used for setting up a worker host. The command accepts configuration settings in its command-line arguments for configuration settings to be applied. Those settings are applied by modifying the worker agent configuration file (docs), which uses the TOML file format.Problem
The code for modifying the worker agent configuration file used simple pattern matching and replacement. For Linux, the
sed
command was used. On Windows, Python'sre.sub(...)
was used.This implementation is fragile and comes with multiple issues:
Any trailing inline TOML comments, for example:
could cause the pattern matching to fail
If the pattern matching allows for trailing comments, the replacement may not preserve them after modification.
The patterns may be overly-strict, for example:
deadline-cloud-worker-agent/src/deadline_worker_agent/installer/install.sh
Lines 411 to 412 in c26590d
Which is the root cause of Running install-deadline-worker with a previous farm and fleet configured fails #308
If the config file exists but some settings are not defined or commented out, the configuration cannot be applied. One example is when a new setting is introduced to the config file (feat: configurable session root directory #513). In such cases, the current implementation of
install-deadline-worker
will not be able to find an existing setting and fail.What was the solution? (How)
Added
tomlkit
as a dependency. This is a Python package that allows for modifying TOML documents while preserving style (comments, blank space, ordering, indentation, etc...).Functionality was added to
deadline_worker_agent.config.config_file.ConfigFile
to modify settings for a tomlkit document (or alternatively specifying a path to a config file andtomlkit
is used to modify it).The logic for modifying settings has the following algorithm:
This code was integrated into the
install-deadline-worker
logic. Of particular note, the Linux implementation ofinstall-deadline-worker
runs a bash script (install.sh
) in a subprocess which handles the installation logic. To integrate with the new Python logic for TOML config file modification, a command-line interface was added tosrc/deadline_worker_agent/config/__main__.py
.The path to the Python interpreter is passed as an argument to
install.sh
which is used to invoke this Python command-line interface:${python_interpreter_path} -m deadline_worker_agent.config ...
What is the impact of this change?
install-deadline-worker
command uses more robust code for modifying the worker agent configuration file and preserving style and comments of the TOML document.install-deadline-worker
to change the farm and fleet ID of an existing worker agent config file (fixes Running install-deadline-worker with a previous farm and fleet configured fails #308)How was this change tested?
deadline_worker_agent.config
command-line interface. I've expanded the GitHub workflows to also run integration tests on Ubuntu (they were previously just run on Windows)Was this change documented?
No, this is mostly fixing our implementation and has more robust behavior for edge cases.
Is this a breaking change?
No
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.