refactor: generalize Distro add_user and shutdown_command#6800
refactor: generalize Distro add_user and shutdown_command#6800blackboxsw wants to merge 4 commits intocanonical:mainfrom
Conversation
|
@holmanb I think I have addressed your question. I'm uncertain if there is something else you would like me to address here. |
61c3aab to
b002dce
Compare
b002dce to
ec6144e
Compare
holmanb
left a comment
There was a problem hiding this comment.
I'd like to avoid using unnamed keyword args - being explicit is less verbose and easier to read.
|
@holmanb I dropped |
There was a problem hiding this comment.
Pull request overview
Preliminary refactor of distro user-creation and shutdown command construction to support upcoming security event logging work, along with corresponding test updates and some typing cleanups.
Changes:
- Refactors
Distro.add_userinto a wrapper + internal hooks (_add_user,_build_add_user_cmd,_post_add_user) and adjustscreate_usersemantics around existing users. - Introduces
_build_shutdown_commandto centralize shutdown command construction with distro overrides (e.g., Alpine). - Normalizes user
groupshandling incc_users_groupsand updates unit tests to pass list-basedgroupsexplicitly.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
cloudinit/distros/__init__.py |
Refactors user creation flow, adds hook methods, updates shutdown command building, adjusts snap-user handling. |
cloudinit/config/cc_users_groups.py |
Adds _normalize_user_groups and passes normalized groups into distro.create_user. |
cloudinit/distros/alpine.py |
Switches Alpine user creation to override _add_user and adds Alpine _build_shutdown_command. |
cloudinit/distros/raspberry_pi_os.py |
Moves Raspberry Pi OS post-user setup into _post_add_user. |
cloudinit/distros/netbsd.py |
Refactors NetBSD user creation to _build_add_user_cmd + _post_add_user. |
cloudinit/distros/freebsd.py |
Refactors FreeBSD user creation to _build_add_user_cmd + _post_add_user. |
cloudinit/distros/bsd.py |
Tightens type annotations for chpasswd. |
cloudinit/netinfo.py |
Corrects return type annotation for netdev_info. |
cloudinit/config/cc_set_passwords.py |
Tightens return type annotation for get_users_by_type. |
tests/unittests/config/test_cc_users_groups.py |
Adds coverage for group normalization/deprecation and updates expected calls. |
tests/unittests/distros/test_create_users.py |
Updates calls to create_user(..., groups=...) and adjusts deprecation-log assertions. |
tests/unittests/distros/test_alpine.py |
Updates Alpine user creation tests for new groups parameter and logstring expectations. |
tests/unittests/distros/test_raspberry_pi_os.py |
Updates Raspberry Pi OS user creation tests for new hook-based behavior. |
tests/unittests/distros/test_user_data_normalize.py |
Updates snap-user tests for new create_user call pattern and group list usage. |
tests/unittests/distros/test_openbsd.py |
Updates add_user calls to include groups=[]. |
tests/unittests/distros/test_netbsd.py |
Updates add_user calls to include groups=[]. |
tests/unittests/distros/test_freebsd.py |
Updates add_user calls to include groups=[]. |
tests/unittests/distros/test_dragonflybsd.py |
Updates add_user calls to include groups=[]. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Addressed all outstanding review comments from copilot as well as @holmanb. This is ready for re-review. |
| # or if the user is a system user | ||
| # Don't create the home directory if directed so or if the user is a | ||
| # system user | ||
| if kwargs.get("no_create_home") or kwargs.get("system"): |
There was a problem hiding this comment.
Done in alpine. Left freebsd, netbsd and init untyped because of the complexity of useradd_flags processing that would require a lot more work than I want to include in this PR.
0bda806 to
068439c
Compare
blackboxsw
left a comment
There was a problem hiding this comment.
@holmanb thanks for the review again.
I believe I have addressed all comments.
a42add6 to
480eae5
Compare
|
Alternate distros action expected fail. Success run seen with PR #6864 |
480eae5 to
71af0fc
Compare
|
Now that CI actions are happy and snap stores are back online, We are now ready for re-review. Note I rebased against update/main and squash merged into 4 logically separate commits to add visibility to the separate intent in each changeset. This helped me review any stray whitespace changes I introduced during this refactor. Should be ready for review @holmanb. Also failing Alpine/edge job is expected dueto missing dependency. #6864 should resolve that issue. |
Drop user group normalization from Distro.add_user because it is now performed in cc_user_groups. Move pre-existing user check outside of add_user and into create_user. Avoid util.logexc in favor of LOG.warning for known subp.ProcessExecutionErrors.
Distributions such as Alpine, *BSD and RPI can now specialize _add_user behavior with the following additional hooks: - _build_add_user_command: to provide unique useadd command switches - _post_add_user: for delayed password processing or user renames BREAKING_CHANGE: Distro.add_user no longer returns a bool indicating whether a user was created. This is not a public API for cloud-init.
…anup The hook _build_shutdown_command allows Alpine to override shutdown behavior without having to subclass the public method shutdown_command.
71af0fc to
664b32f
Compare
|
Rebased against main to get alpine workflow fix. |
Decomposed #6689 into part-1 and part-2 to aid reviewing.
Proposed Commit Message
Additional Context
Test Steps
tox -e py3
Merge type