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

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 world-wide, outside of Cisco.


Step 1 - Change Directories Back To Main Project Directory

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


cd /home/pod14/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]'==25.4


Step 3 - Verify pyATS Install

Verify pyATS install with pyats version checker:


pyats version check

    You are currently running pyATS version: 25.4
    Python: 3.11.9 [64bit]

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


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/pod14/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/pod14/workspace/nxapilab/tests/staging-testbed.yaml
code-server -r /home/pod14/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, and 40 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 using the correct device connector, i.e. 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 the rest connection; it makes use of the rest connector package that was installed above, and it's 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.14.11
      rest:
        class: rest.connector.Rest
        protocol: https
        ip: 10.15.14.11
  staging-leaf1:
    alias: n9kv-l1
    type: switch
    os: nxos
    platform: n9k
    connections:
      defaults:
        via: rest
      ssh:
        protocol: ssh
        ip: 10.15.14.12
      rest:
        class: rest.connector.Rest
        protocol: https
        ip: 10.15.14.12
  staging-leaf2:
    alias: n9kv-l2
    type: switch
    os: nxos
    platform: n9k
    connections:
      defaults:
        via: rest
      ssh:
        protocol: ssh
        ip: 10.15.14.13
      rest:
        class: rest.connector.Rest
        protocol: https
        ip: 10.15.14.13


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