Skip to content

enhancement: exit cleanly with helpful error when required defaults are missing instead of Jinja2 traceback #523

@aitestino

Description

@aitestino

Problem Statement

When running nac-test for ACI/APIC without providing a defaults file (when defaults are required by templates), users encounter a confusing Jinja2 traceback instead of a clear, actionable error message.

Current Behavior

➜ uv run nac-test -d ./data -t ./tests/ -o ./nac-test-results -f tests/jinja_filters

Traceback (most recent call last):
  File ".venv/lib/python3.13/site-packages/nac_test/robot_writer.py", line 122, in render_template
    result = template.render(data, **kwargs)
  File ".venv/lib/python3.13/site-packages/jinja2/environment.py", line 1295, in render
    self.environment.handle_exception()
  File "tests/templates/apic/test/config/access_policies/cdp_policy.robot", line 9, in top-level template code
    {% set cdp_policy_name = policy.name ~ defaults.apic.access_policies.interface_policies.cdp_policies.name_suffix %}
jinja2.exceptions.UndefinedError: 'defaults' is undefined

Why This Happens

For nac-aci (ACI-as-Code), many templates rely on defaults to enforce naming conventions and organizational standards:

  • Name suffixes (e.g., _CDP, _LLDP)
  • Description templates
  • Default values for optional attributes

When users run nac-test without -d ./defaults/defaults.yaml, these templates fail during rendering.

Fixed by #525

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions