While PyATS may have a difficult pronunciation😀, it is a Swiss knife in networking with its ability to achieve amazing things.
Despite NetDevOps simplifying the way we work with a plethora of tools, some companies still have a culture of fear where they don't want to touch what's working.
But with PyATS, there's no need to fear as it can automate and simplify network engineering tasks.
I had my first hands-on experience with PyATS in 2020 and have since become an evangelist of the tool. Thanks to John Capobianco, also known as the Bob Ross of automation, I continue to explore PyATS's capabilities and possibilities.
PyATS has been made public in 2017 and stands for Python Automated Test System. It is a Python testing framework developed internally at Cisco, then made open source, and is now well-adopted worldwide for performing network tests. Cisco runs millions of tests monthly, including regression, sanity, and scale tests.
Additionally, the PyATS framework has a Python library called Genie, which contains all the network information and works on top of PyATS. Although some network engineers may have difficulty understanding the relationship between the two tools, it is crucial to note that where there is PyATS, Genie is present.
pyATS is the core framework and genie is the pyATS standard library. Genie is the SDK that contains everything we need for network test automation.
written in python,pyATS remains the most powerful testing framework for network engineers, some of the key features are :
the pyATS framework is composed of various layers, and here are the following:
The core framework plays a pivotal role in managing low-level mechanics, such as configuring device connections and executing device commands. Additionally, it serves as the foundation for an essential framework component known as the testbed, which outlines the topology to be tested. The testbed encompasses various objects, including devices, interfaces, and links, all represented as Python objects that can be interacted with. These objects offer multiple methods for carrying out actions and operations on them.
Have you explored all the awesome methods that the testbed offers? These nifty features make it super easy for us to perform various actions, such as:
device.connect()
device.ping("192.168.1.1")
device.execute("show version")
Here, the snippet does the following action:
Genie is a powerful tool that operates on the Pyats core layer, skillfully leveraging and abstracting the libraries and frameworks presented by the core. This is where the true magic takes place! With an impressive library and over 1500 parsers at its disposal, Genie expertly converts raw text into structured text.
Atop the genie layer, we have the integrations layer that provides a wide range of libraries and plugins to deeply abstract the underlying pyATS/genie layers. This enables network engineers to fully utilize pyats at a higher level and take advantage of its capabilities.
powerful and written in python,pyATS offers the following components :
With powerful and growing communities from internet and network junkies,pyATS can be found here :
Cisco Devnet offers the best documentation when it comes to pyATS, and it goes beyond Cisco!
to explore the documentation: PyATS and downloadable via PyPI
to install, there are some requirements follow and here are the following :
#Create a virtual environment
python3 -m venv pyATS_Test
#Activate the virtual environment
source pyATS_Tests/bin/activate
now, we are already inside our newly created virtual environment
pip3 install "pyats[full]==23.9"
pyATS 23.9 is the latest version to update to or install
How do we know if pyATS and Genie have been correctly installed? Here is the step:
$ pip3 freeze | grep -E "pyats=|genie="
genie==23.9
pyats==23.9
Version
let’s see a use case where we can get simple CLI output (show IP interface brief) from an IOS XR device.
All the snippets you see were runned on Cisco IOS
A great way to connect to a device is to create a testbed written in YAML, and the information will be used to connect to the device and send the requested commands.
# Step 0: list of devices
devices:
iosxr1:
# Step 1: OS and Type
type: iosxr-Prod
os: iosxr
# Step 2: credentials
credentials:
default:
username: admin
password: Hacker@204k
# Step 3: connection parameters
connections:
vty:
protocol: ssh
ip: test-mgmt.talesoftechnology.com
port: 8080
What is the testbed?
The testbed is ready; let’s make our first pyATS script:
What are we going to achieve?
we are going to connect to the device and collect a CLI output of the show IP interface brief command.
from pyats.topology import loader
# Step 0: load the testbed
testbed = loader.load(f'./testbed.yaml')
# Step 1: testbed is a dictionary. Extract the device iosxr1
iosxr1 = testbed.devices["iosxr1"]
# Step 2: Connect to the device
iosxr1.connect(init_exec_commands=[], init_config_commands=[], log_stdout=False)
# Step 3: saving the `show ip interface brief` output in a variable
show_interface = iosxr1.execute('show ip interface brief')
# Step 4:printing the `show interface brief` output
print(show_interface)
# Step 5: disconnect from the device
iosxr1.disconnect()
What does the script do?
This script is useful for automating tasks on network devices, such as gathering information or configuring settings. Please note that you need to have pyATS installed and a valid testbed.yaml file for this script to work.
in our example, the file is named pyats_cli_show.py
from the bash terminal, we can execute
python pyats_cli_show.py
Interface IP-Address Status Protocol Vrf-Name
Loopback99 1.1.1.99 Up Up default
Loopback100 1.1.1.100 Up Up default
Loopback999 unassigned Up Up default
MgmtEth0/RP0/CPU0/0 192.168.1.1 Up Up default
GigabitEthernet0/0/0/0 unassigned Shutdown Down default
GigabitEthernet0/0/0/1 unassigned Shutdown Down default
GigabitEthernet0/0/0/2 unassigned Shutdown Down default
GigabitEthernet0/0/0/3 unassigned Shutdown Down default
GigabitEthernet0/0/0/4 unassigned Shutdown Down default
GigabitEthernet0/0/0/5 unassigned Shutdown Down default
GigabitEthernet0/0/0/6 unassigned Shutdown Down default
Our short demo showed how to build a testbed and how to collect our first CLI output from the device.
pyATS plays a crucial role in NetDevOps by providing a framework for network test automation; it fits well in the stateful test & validation domain by observing each part of the slice, presented by Cisco Devnet during a tech conference in 2019.
In summary, pyATS is an essential tool in the NetDevOps toolbox that helps streamline and standardize network operations and testing.
pyATS is used worldwide! Here are some use cases where it shines :
PyATS is a network testing framework that was initially developed at Cisco, where it was used to run millions of tests every month. In 2017, Cisco made pyATS open source, though some core components are still proprietary to Cisco systems.
Today, pyATS has become the de facto standard for network tests and boasts a growing community of contributors. It is considered the most powerful tool in the industry and is essential for network engineers who want to simplify their work with a Swiss knife.
As the field of netdevOps continues to evolve, it's crucial for network engineers to adopt pyATS and stay ahead of the curve.
If you enjoyed this short introduction to pyATS, consider subscribing to my contributor page to stay up-to-date with the latest developments in the field.