Add Tier-A logging/verbosity tests; rename logger; fix JSON encoder bug#2
Merged
Conversation
- Rename logger 'ansible_pyapi' -> 'ansible_host' and env var
ANSIBLE_PYAPI_VERBOSITY -> ANSIBLE_HOST_VERBOSITY so both match the
package name. Stale 'pyapi' names predated the rename.
- Fix a TypeError in the verbosity logging path: json.dumps in the
v=2 task-fields log and the v=2/3/4 results/stats logs crashed on
non-serializable Task instances on ansible-core 2.19+. Added
default=str to all four call sites. Same family as the earlier
_check_failed_results fix; was hidden because the bug only triggers
when a DEBUG handler is attached to the ansible_host logger.
- Add 4 Tier-A tests in test_logging_and_verbosity.py:
- display.verbosity is restored after _run (regression guard)
- default verbosity emits the compact v=2 task line
- options={'verbosity': 0} silences all library logs
- options['verbosity'] overrides ANSIBLE_HOST_VERBOSITY env var
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xin Wang <wangxin.wang@gmail.com>
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.
Summary
Add 4 tests covering the verbosity/logging behavior, rename the logger and env var to match the package name, and fix a
TypeErrorin the verbosity logging path that the new tests surfaced.Renames
ansible_pyapi→ansible_hostANSIBLE_PYAPI_VERBOSITY→ANSIBLE_HOST_VERBOSITYBoth names were stale from before the package was renamed.
Bug fix
json.dumps()in the verbosity logging path crashed withTypeError: Object of type Task is not JSON serializableon ansible-core 2.19+ — same family as the earlier_check_failed_resultsfix. Hit four call sites in_run()(v=2 task fields, v=2/3 results, v=4 stats). All now usedefault=str.The bug was invisible until now because it only triggers when a DEBUG handler is attached to the
ansible_hostlogger at default-or-higher verbosity — exactly the path users hit when trying to debug a problem.Tests
test_display_verbosity_is_restored_after_rundisplay.verbositysave/restore — guards against silent stomp of global Ansible statetest_default_verbosity_emits_compact_jsontest_verbosity_zero_emits_no_library_logstest_options_verbosity_overrides_env_varoptions['verbosity']wins overANSIBLE_HOST_VERBOSITY; v=3 emits indented JSONValidation
37 tests pass locally (3 smoke + 30 tier-1 + 4 tier-A), ruff clean.