refactor: use module.run_command instead of subprocess#856
Merged
richm merged 1 commit intolinux-system-roles:mainfrom Apr 2, 2026
Merged
refactor: use module.run_command instead of subprocess#856richm merged 1 commit intolinux-system-roles:mainfrom
richm merged 1 commit intolinux-system-roles:mainfrom
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors the NetworkManager connection cleanup helper to use Ansible's module.run_command API instead of invoking busctl via subprocess, aligning with ansible-test guidance and enabling better command handling within the module. Sequence diagram for forget_nm_connection using module_run_commandsequenceDiagram
actor AnsibleController
participant NetworkConnectionsModule
participant AnsibleModule
participant BusctlProcess
AnsibleController->>NetworkConnectionsModule: forget_nm_connection(path)
activate NetworkConnectionsModule
NetworkConnectionsModule->>AnsibleModule: run_command([busctl, --system, call, org.freedesktop.NetworkManager, /org/freedesktop/NetworkManager, org.freedesktop.NetworkManager, ActivateConnection, as, 1, path], handle_exceptions=False)
activate AnsibleModule
AnsibleModule->>BusctlProcess: exec busctl ... path
activate BusctlProcess
BusctlProcess-->>AnsibleModule: rc, stdout, stderr
deactivate BusctlProcess
AnsibleModule-->>NetworkConnectionsModule: rc, stdout, stderr
deactivate AnsibleModule
NetworkConnectionsModule-->>AnsibleController: return (ignores exceptions)
deactivate NetworkConnectionsModule
Class diagram for network_connections forget_nm_connection refactorclassDiagram
class NetworkConnectionsModule {
+AnsibleModule module
+forget_nm_connection(path)
}
class AnsibleModule {
+run_command(cmd_list, use_unsafe_shell, encoding, check_rc, close_fds, environ, executable, data, binary_data, cwd, umask, strict, diff, expands, prompt_regex, stdin_add_newline, preserve_rc, path_prefix, host, port, display, timeout, become, become_method, become_user, become_pass, ignore_invalid_certs, suppress_system_warnings, python_interpreter, handle_exceptions)
}
NetworkConnectionsModule --> AnsibleModule: uses run_command for busctl call
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The assigned variables
rc, stdout, stderrare never used; if you truly don't need them, either drop the assignment or use_/_rcto make the intent to ignore them explicit. - Since
handle_exceptions=Falseis now passed torun_command, consider whether the bareexcept Exception: passis still appropriate or if you should narrow the exception type or log failures before ignoring them.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The assigned variables `rc, stdout, stderr` are never used; if you truly don't need them, either drop the assignment or use `_`/`_rc` to make the intent to ignore them explicit.
- Since `handle_exceptions=False` is now passed to `run_command`, consider whether the bare `except Exception: pass` is still appropriate or if you should narrow the exception type or log failures before ignoring them.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #856 +/- ##
==========================================
+ Coverage 43.11% 43.16% +0.05%
==========================================
Files 12 12
Lines 3124 3125 +1
==========================================
+ Hits 1347 1349 +2
+ Misses 1777 1776 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
[citest] |
Ansible modules should use module.run_command instead of subprocess. This is flagged by the latest ansible-test Signed-off-by: Rich Megginson <rmeggins@redhat.com>
71b24b1 to
7d67e2c
Compare
Contributor
Author
done |
Contributor
Author
|
[citest] |
spetrosi
approved these changes
Apr 2, 2026
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.
Ansible modules should use module.run_command instead of subprocess.
This is flagged by the latest ansible-test
Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by Sourcery
Enhancements: