Skip to content

nd_log - playbook-side logging#283

Open
allenrobel wants to merge 8 commits into
developfrom
nd_log
Open

nd_log - playbook-side logging#283
allenrobel wants to merge 8 commits into
developfrom
nd_log

Conversation

@allenrobel
Copy link
Copy Markdown
Collaborator

Related Issue(s)

N/A

Proposed Changes

  • New cisco.nd.nd_log module: emits a Python logging record under the nd parent logger so playbook activity can be correlated with the nd.* records emitted internally by other modules in this collection.
  • Local-only — no HTTP/API calls. Logging is configured by the existing ND_LOGGING_CONFIG env var consumed by common/log.py (parent logger nd, setup_logging() helper).
  • Mirrors cisco.dcnm.dcnm_log in shape and argument surface (msg, severity with choices CRITICAL/DEBUG/ERROR/INFO/WARNING, default DEBUG).
  • supports_check_mode=True — deliberate deviation from dcnm_log parity; logging is a safe side effect during --check runs.
  • Strict config-error behavior via setup_logging(): a malformed/missing ND_LOGGING_CONFIG file calls module.fail_json rather than silently swallowing the error.
  • 9 unit tests under tests/unit/modules/ covering init defaults, missing-msg ValueError, parametrized severity dispatch via caplog, and default-vs-explicit DEBUG equivalence. New tests/unit/modules/__init__.py is empty (sanity empty-init rule).

Test Notes

  • Unit tests: python -m pytest tests/unit/modules/test_nd_log.py -v — 9/9 pass.
  • Lint: black --check, isort --check, pylint, mypy — clean (only the standard Ansible-module advisories that also appear on nd_version.py).
  • ansible-doc cisco.nd.nd_log renders correctly.
  • End-to-end smoke playbook: task completes with changed=0; record appended to /tmp/nd.log per the configured ND_LOGGING_CONFIG.

Cisco Nexus Dashboard Version

4.2 (module does not call ND APIs; tested against the 4.2 lab for parity with the rest of the collection).

Related ND API Resource Category

  • analyze
  • infra
  • manage
  • onemanage
  • other

Checklist

  • Latest commit is rebased from develop with merge conflicts resolved
  • New or updates to documentation has been made accordingly
  • Assigned the proper reviewers

🤖 Generated with Claude Code

Local-only module that emits a Python logging record under the `nd`
parent logger, configured via the existing `ND_LOGGING_CONFIG`
environment variable. Useful for correlating playbook task execution
with the `nd.*` records emitted internally by other cisco.nd modules.

- plugins/modules/nd_log.py: NDLog class with severity dispatch
  (CRITICAL/DEBUG/ERROR/INFO/WARNING); uses setup_logging() from
  common/log.py; supports check_mode.
- tests/unit/modules/test_nd_log.py: 9 tests covering init defaults,
  missing-msg ValueError, parametrized severity dispatch via caplog,
  and default-vs-explicit DEBUG equivalence.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 18, 2026 20:29
@allenrobel allenrobel changed the title Add nd_log module for playbook-side logging nd_log module for playbook-side logging May 18, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new local-only Ansible module (cisco.nd.nd_log) to emit playbook-side log records under the nd.* logger hierarchy, enabling correlation between playbook execution and the collection’s internal logging.

Changes:

  • Introduces plugins/modules/nd_log.py module with msg + severity parameters and supports_check_mode=True.
  • Adds unit tests validating initialization defaults, missing msg behavior, and severity-to-log-level dispatch.
  • Adds an (empty) tests/unit/modules/__init__.py to satisfy test package structure rules.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
plugins/modules/nd_log.py New nd_log module implementation and Ansible docs/examples.
tests/unit/modules/test_nd_log.py Unit tests for NDLog initialization and logging behavior.
tests/unit/modules/init.py Empty init file to establish the unit-test package.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/modules/nd_log.py
Comment thread plugins/modules/nd_log.py Outdated
Comment thread tests/unit/modules/test_nd_log.py
@allenrobel allenrobel changed the title nd_log module for playbook-side logging nd_log - playbook-side logging May 18, 2026
@allenrobel allenrobel self-assigned this May 19, 2026
@allenrobel allenrobel added the Ready for Review Submitter is requesting a PR review label May 19, 2026
Comment thread plugins/modules/nd_log.py
Comment thread plugins/modules/nd_log.py
Comment thread plugins/modules/nd_log.py Outdated
Comment thread plugins/modules/nd_log.py
Comment thread plugins/modules/nd_log.py Outdated
Comment thread tests/unit/modules/test_nd_log.py Outdated
allenrobel and others added 6 commits May 21, 2026 09:48
Co-authored-by: Akini Ross <akinross@cisco.com>
Co-authored-by: Akini Ross <akinross@cisco.com>
Co-authored-by: Samita B <samitab@cisco.com>
Per Samita’s comments.
Address review feedback on PR #283: the NDLog class coupled to the
Ansible params dict and carried unreachable `is None` checks (the
argument spec's `required`/`default` guarantee those values are never
None). Replace it with a module-level `log_message(severity, msg)`
helper that `main()` calls directly.

- Drop the 5-branch if/elif in favor of getattr dispatch, safe because
  the argspec `choices` constraint guarantees a valid Logger method.
- Rename logger nd.NDLog -> nd.nd_log to match the module name.
- Unit tests: keep the mock-free severity-dispatch test retargeted to
  log_message(); drop the three tests covering the removed constructor
  and the unreachable ValueError paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Address review feedback on PR #283: the nd_version task in the EXAMPLES
block used the param-style invocation (host/username/password as module
args) plus delegate_to: localhost, while the nd_log tasks did not. The
delegate_to is also misleading for cisco.nd modules, which run on the
control node by virtue of the httpapi connection plugin regardless.

Drop the inline credentials and delegate_to from the nd_version task so
all three example tasks are plain module calls that take their
connection from inventory/play vars.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@samiib samiib requested review from akinross and samiib May 21, 2026 23:34
Copy link
Copy Markdown
Collaborator

@samiib samiib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for Review Submitter is requesting a PR review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants