Setup
pyATS
  • Introduction
  • Dev Setup
  • NX-API Overview
  • NX-API Python
  • Ansible NXOS
  • pyATS
  • NetDevOps
  • Configuration Session
  • Terraform
  • Bonus: YANG
  • Reference: Postman

pyATS Install & Setup


pyATS (Python Automated Test Systems) is a Python-based test automation infrastructure framework that was originally developed for internal Cisco engineering use. pyATS is at the core of Cisco's Test Automation Solution. It is the de-facto test framework for internal Cisco engineers across different platform/functions, running millions of CI/CD, sanity, regression, scale, HA, solution tests on a monthly basis; and by thousands of network engineers and developers worldwide, outside of Cisco.


Step 1 - Change Directories Back To Main Project Directory

While still at your VSCode terminal, change directories back to the main project directory:


cd /home/pod21/workspace/nxapilab


Step 2 - Install pyATS

pyATS is installed via pip. To install the full pyATS framework using the full keyword, as you'll do in this lab:


pip install 'pyats[full]'==26.3


Step 3 - Verify pyATS Install

Verify the pyATS install with the pyATS version checker:


pyats version check

    You are currently running pyATS version: 26.3
    Python: 3.11.14 [64bit]

    Package                      Version
    ---------------------------- -------
    genie                        26.3
    genie.libs.clean             26.3
    genie.libs.conf              26.3
    genie.libs.filetransferutils 26.3
    genie.libs.health            26.3
    genie.libs.ops               26.3
    genie.libs.parser            26.3
    genie.libs.robot             26.3
    genie.libs.sdk               26.3
    genie.telemetry              26.3
    genie.trafficgen             26.3
    pyats                        26.3
    pyats.aereport               26.3
    pyats.aetest                 26.3
    pyats.async                  26.3
    pyats.connections            26.3
    pyats.contrib                26.3
    pyats.datastructures         26.3
    pyats.easypy                 26.3
    pyats.kleenex                26.3
    pyats.log                    26.3
    pyats.reporter               26.3
    pyats.results                26.3
    pyats.robot                  26.3
    pyats.tcl                    26.3
    pyats.topology               26.3
    pyats.utils                  26.3
    rest.connector               26.3
    unicon                       26.3
    unicon.plugins               26.3
    yang.connector               26.3


Step 4 - Create Tests Directory

Create a tests directory in your project. This directory name is common for including tests.


mkdir tests
mkdir -p tests/results
touch tests/results/.keep
cd /home/pod21/workspace/nxapilab/tests


Step 5 - pyATS Testbed YAML File

pyATS offers a topology module for interacting with devices. This is primarily done through a topology or testbed YAML file that is loaded at runtime. This file has all the device information, connection information, metadata, etc for how to interact with devices in your environment.

While still in VSCode, create a testbed YAML file that includes the switches that are part of your staging or test fabric that you have programmatically been building out as a VXLAN EVPN fabric.


touch /home/pod21/workspace/nxapilab/tests/staging-testbed.yaml
code-server -r /home/pod21/workspace/nxapilab/tests/staging-testbed.yaml


Step 6 - pyATS Testbed YAML File

Populate the staging-testbed.yaml file with the connection information for interacting with your switches. You will notice the testbed file has a name on line 3. Starting on line 5, there are default credentials defined for device access. This can be made more secure in your own environment using environment variables or pyATS secret strings. Lines 10, 25, 40, 55, and 70 under the devices key are where your device information is defined. Under each device, the os key set to nxos and platform key set to n9k are the important pieces for pyATS to use the correct device connector, i.e. the correct connector that expects the correct type of CLI prompt.

Lastly, the actual connections are defined. The names for the connections used in this lab, ssh and rest, are arbitrary names and can be anything; however, it is good practice to align with the type of connection. Notice two things with the rest connection: it makes use of the rest connector package that was installed above, and it is set as the default connection.


---
testbed:
    name: NX-API Staging Lab
    alias: Staging
    credentials:
      default:
        username: admin
        password: cisco.123
devices:
  staging-spine1:
    alias: n9kv-s1
    type: switch
    os: nxos
    platform: n9k
    connections:
      defaults:
        via: rest
      ssh:
        protocol: ssh
        ip: 10.15.21.11
      rest:
        class: rest.connector.Rest
        protocol: https
        ip: 10.15.21.11
  staging-spine2:
    alias: n9kv-s2
    type: switch
    os: nxos
    platform: n9k
    connections:
      defaults:
        via: rest
      ssh:
        protocol: ssh
        ip: 10.15.21.12
      rest:
        class: rest.connector.Rest
        protocol: https
        ip: 10.15.21.12
  staging-leaf1:
    alias: n9kv-l1
    type: switch
    os: nxos
    platform: n9k
    connections:
      defaults:
        via: rest
      ssh:
        protocol: ssh
        ip: 10.15.21.21
      rest:
        class: rest.connector.Rest
        protocol: https
        ip: 10.15.21.21
  staging-leaf2:
    alias: n9kv-l2
    type: switch
    os: nxos
    platform: n9k
    connections:
      defaults:
        via: rest
      ssh:
        protocol: ssh
        ip: 10.15.21.22
      rest:
        class: rest.connector.Rest
        protocol: https
        ip: 10.15.21.22
  staging-leaf3:
    alias: n9kv-l3
    type: switch
    os: nxos
    platform: n9k
    connections:
      defaults:
        via: rest
      ssh:
        protocol: ssh
        ip: 10.15.21.23
      rest:
        class: rest.connector.Rest
        protocol: https
        ip: 10.15.21.23


Continue to the next section to create tests using pyATS AEtest.