Skip to content

Quickstart

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.

tests/
└── templates/
├── common.resource # Shared keywords (login, assertions)
└── tenants/
└── tenant.robot # Test template

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 RequestsLibrary
Library 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).

This template verifies every tenant defined in the data model:

*** Settings ***
Documentation Verify Tenants
Suite Setup Login APIC
Default Tags apic tenants
Resource ../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.
Terminal window
export ACI_URL=https://apic.example.com
export ACI_USERNAME=admin
read -s ACI_PASSWORD
export ACI_PASSWORD
nac-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.

  • 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