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.
While still at your VSCode terminal, change directories back to main project directory:
cd /home/cisco/Documents/nxapilab/
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]'==24.1
Verify pyATS install with pyats version checker:
pyats version check
You are currently running pyATS version: 24.1 Python: 3.11.6 [64bit] Package Version ---------------------------- ------- genie 24.1 genie.libs.clean 24.1 genie.libs.conf 24.1 genie.libs.filetransferutils 24.1 genie.libs.health 24.1 genie.libs.ops 24.1 genie.libs.parser 24.1 genie.libs.robot 24.1 genie.libs.sdk 24.1 genie.telemetry 24.1 genie.trafficgen 24.1 pyats 24.1 pyats.aereport 24.1 pyats.aetest 24.1 pyats.async 24.1 pyats.connections 24.1 pyats.contrib 24.1 pyats.datastructures 24.1 pyats.easypy 24.1 pyats.kleenex 24.1 pyats.log 24.1 pyats.reporter 24.1 pyats.results 24.1 pyats.robot 24.1 pyats.tcl 24.1 pyats.topology 24.1 pyats.utils 24.1 rest.connector 24.1 unicon 24.1 unicon.plugins 24.1 yang.connector 24.1
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/cisco/Documents/nxapilab/tests/
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.
code -r /home/cisco/Documents/nxapilab/tests/staging-testbed.yaml
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.1.11
rest:
class: rest.connector.Rest
protocol: https
ip: 10.15.1.11
staging-leaf1:
alias: n9kv-l1
type: switch
os: nxos
platform: n9k
connections:
defaults:
via: rest
ssh:
protocol: ssh
ip: 10.15.1.12
rest:
class: rest.connector.Rest
protocol: https
ip: 10.15.1.12
staging-leaf2:
alias: n9kv-l2
type: switch
os: nxos
platform: n9k
connections:
defaults:
via: rest
ssh:
protocol: ssh
ip: 10.15.1.13
rest:
class: rest.connector.Rest
protocol: https
ip: 10.15.1.13
After successfully populating staging-testbed.yaml with the above connection information, save your staging-testbed.yml
file using Ctrl+s on the Windows keyboard or by clicking File then Save.
Be sure to save your file! Not saving will result in your code not executing.
Once saved, close staging-testbed.yaml by clicking the small x (close button) to the right of the file tab:
Continue to the next section to create tests using pyATS AEtest.