Conversation
When user_preserve_groups is set to an empty list, the code attempts to preserve all groups the user belongs to. However, if the user is not a member of any supplementary groups, the generated Dockerfile snippet would omit the usermod -aG command entirely, causing the test to fail. This fix moves the conditional check from the EmPy template level (@[if user_groups != '']@) to the shell script level (if [ -n "${user_groups}" ]; then), ensuring that the usermod command structure is always present in the generated output. The loop only executes if groups actually exist, maintaining the same runtime behavior while satisfying the test's expectation. Fixes osrf#339 | I've submitted a PR to fix this issue: #348 Summary of the fix: I moved the conditional check from the EmPy template level ( Testing:
|
tfoote left a comment
There was a problem hiding this comment.
There's some extraneous changes that are in here. Please remove them.
And please add a unit test which shows this failing, and then with the fix applied shows it working.
It's not clear to me that this change is going to resolve the referenced issue.
| raise | ||
| | ||
| def docker_build(docker_client = None, output_callback = None, **kwargs): | ||
| def docker_build(docker_client=None, output_callback=None, **kwargs): |
There was a problem hiding this comment.
The changes in this file look unrelated.
| fi; \ | ||
| done && \ | ||
| @[end if]@ | ||
| user_groups="@(user_groups)" && \ |
There was a problem hiding this comment.
Can you explain why checking if it's an empty string in bash is different than checking if it's empty in the template?
| Closing due to no response |
Description
Fixes #339
This PR resolves a test failure that occurs when the
user_preserve_groupsoption is used with a user who has no supplementary groups.Problem
When
user_preserve_groupsis set to an empty list[], the extension attempts to preserve all groups the current user belongs to. However, if the user has no supplementary groups (not a member of any groups), the template would skip generating theusermod -aGcommand block entirely, causing the test assertion to fail.The test was failing with:
Solution
Moved the conditional check from the EmPy template level to the shell script level:
Before (EmPy conditional):
After (Shell conditional):
This ensures:
usermod -aGcommand structure always appears in generated DockerfilesTesting
test/test_extension.pypasstest_user_extensionpasses with empty groups listRelated Issue
Closes #339