-
Notifications
You must be signed in to change notification settings - Fork 112
refactor: use the warn module method on newer Ansible #835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Starting with Ansible 2.20, modules should not return the `warnings` key in the module return. Instead, modules should use the `warn` method to specify the warnings. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts how module warnings are handled to use Ansible’s module.warn API when available, while preserving legacy behavior for older Ansible versions. Sequence diagram for updated warning handling in _complete_kwargssequenceDiagram
participant Caller
participant NetworkConnections
participant AnsibleModule
Caller->>NetworkConnections: _complete_kwargs(connections, kwargs, traceback_msg, fail)
NetworkConnections->>NetworkConnections: collect warning_logs from _run_results
alt traceback_msg is not None
NetworkConnections->>NetworkConnections: warning_logs.append(traceback_msg)
end
NetworkConnections->>AnsibleModule: getattr(module, warn, None)
alt module.warn is callable
loop for each msg in warning_logs
NetworkConnections->>AnsibleModule: warn(msg)
end
Note right of NetworkConnections: warnings are emitted via module.warn
else module.warn not available
NetworkConnections->>NetworkConnections: kwargs[warnings] = warning_logs
Note right of NetworkConnections: legacy behavior using warnings in return
end
NetworkConnections->>NetworkConnections: kwargs[stderr] = joined debug logs
NetworkConnections->>NetworkConnections: kwargs[_invocation] = module.params
NetworkConnections-->>Caller: kwargs
Updated class diagram for warning handling in network_connections moduleclassDiagram
class NetworkConnections {
+module
+_run_results
+_complete_kwargs(connections, kwargs, traceback_msg, fail)
+_complete_kwargs_loglines(rr, connections, idx)
}
class AnsibleModule {
+params
+warn(msg)
}
NetworkConnections --> AnsibleModule : uses
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
fixes #830 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #835 +/- ##
==========================================
+ Coverage 43.11% 43.18% +0.06%
==========================================
Files 12 12
Lines 3124 3126 +2
==========================================
+ Hits 1347 1350 +3
+ Misses 1777 1776 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
[citest] |
Starting with Ansible 2.20, modules should not return the
warningskey in the modulereturn. Instead, modules should use the
warnmethod to specify the warnings.Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by Sourcery
Enhancements: