Quickstart
What is this?
Section titled “What is this?”Robot Framework tests are .robot files containing Jinja templating. nac-test renders each template with the merged data model, so a single template produces one test case per object defined in the data model, and then executes the rendered suites in parallel with Pabot. A simple template consists of a loop over a data model section, one API request per object, and one assertion per attribute.
Prerequisites
Section titled “Prerequisites”- nac-test (see Installation). It includes Robot Framework, Pabot and the libraries RequestsLibrary, JSONLibrary and JMESPathLibrary.
- Basic familiarity with Robot Framework syntax.
Project Layout
Section titled “Project Layout”tests/└── templates/ ├── common.resource # Shared keywords (login, assertions) └── tenants/ └── tenant.robot # Test templateThe Shared Resource File
Section titled “The Shared Resource File”nac-test doesn’t provide controller-specific keywords, so a test suite usually starts with a resource file that logs in to the controller and defines assertion keywords. A simplified example for ACI:
*** Settings ***Library RequestsLibraryLibrary JMESPathLibrary
*** Variables ***${login_json} {"aaaUser": {"attributes": {"name": "%{ACI_USERNAME}", "pwd": "%{ACI_PASSWORD}"}}}
*** Keywords ***Login APIC Create Session apic %{ACI_URL} POST On Session apic /api/aaaLogin.json data=${login_json}
Should Be Equal Json Value [Arguments] ${json} ${expression} ${value}=${EMPTY} ${actual}= JSON Search String ${json} ${expression} Run Keyword If $value Should Be Equal As Strings ${actual} ${value}The session keeps the login cookie for subsequent requests. Should Be Equal Json Value skips the comparison when the expected value is empty, so optional attributes are only checked when they are set in the data model (see Optional Attributes for other approaches).
Minimal Test Template
Section titled “Minimal Test Template”This template verifies every tenant defined in the data model:
*** Settings ***Documentation Verify TenantsSuite Setup Login APICDefault Tags apic tenantsResource ../common.resource
*** Test Cases ***{% for tenant in apic.tenants | default([]) %}
Verify Tenant {{ tenant.name }} ${r}= GET On Session apic /api/mo/uni/tn-{{ tenant.name }}.json Should Be Equal Json Value ${r.json()} imdata[0].fvTenant.attributes.name {{ tenant.name }} Should Be Equal Json Value ${r.json()} imdata[0].fvTenant.attributes.descr {{ tenant.description | default() }}
{% endfor %}{% for ... | default([]) %}loops over the data model section and renders nothing if it is absent.| default()renders an empty value for attributes that are not set, which the assertion keyword skips.- Each tenant becomes one test case named after the tenant.
How to Run
Section titled “How to Run”export ACI_URL=https://apic.example.comexport ACI_USERNAME=adminread -s ACI_PASSWORDexport ACI_PASSWORDnac-test --robot \ -d data/ \ -t tests/templates/ \ -o tests/results/--robot skips PyATS tests during development. Add --render-only to only render the templates and inspect the generated suites in tests/results/robot_results/. Open tests/results/combined_summary.html or tests/results/robot_results/log.html for the results.
Next Steps
Section titled “Next Steps”- Test Case Guide: See the Test Case Guide for templating techniques, assertions, tags and parallel execution
- Reference: See the Reference for the template context, rendering directives, custom Jinja filters and tests, and bundled libraries