pyATS was (and still is) an in-house Cisco Python testing framework that has been made open source and is now available to you to perform your network testing. Cisco currently run over 2 million test runs per month!
It was released to Devnet in 2017.
Genie is the library that contains all the knowledge of network operations, which works on top of pyATS.
Pyats and Genie are often talked about together and make up a very powerful network testing application.
When you start using Pyats you will see a lot of the commands use Pyats and a lot use Genie.
pyATS and Genie is not Cisco specific and will run with most network platforms.
1. How to install pyATS
pyATS is a Python package which can be installed using pip install pyats
I would also recommend adding [full] to get all the optional extras.
I would also advise you install pyATS into a virtual environemnt (venv)
If you are unsure what a virtual environment is, check this post
First Create your Virtual Environment
Create a new directory for pyats
$ mkdir pyats
Go into your new directory
$ cd pyats
Initialise your virtual environment
$ python3 -m venv .
Now activate your virtual environment
$ source bin/activate .
You should now see your prompt change to your virtual environment
(pyats) [email protected]:~/pyats$
You can now install pyats into this venv
pip install pyats[full]
Check the version of Pyats and verify a correct installation
pyats version check
At the time of writing I have installed version 20.7
2. Setup your testbed file
pyATS uses a concept of a testbed to describe the network devices you want to test. This is a YAML file that can either be imported or created. In this example we are going to create our testbed file from scratch.
To do this you need to run the command
$ genie create testbed interactive --output testbed1.yml
NOTE: tesbed1.yml is the name of your testbed file and can be any name you want.
You will be prompted to enter your username and password and IP details for your network devices.
What is created is a standard YAML file like this.
This is the topology that I will be testing with pyATS / Genie and so far I have put CSR-1 and CSR-2 into the testbed file
So I have now defined CSR-1 and CSR-2 and I have enabled OSPF between the two devices.
3. Running your first pyATS / Genie test.
The beauty of pyATS / Genie is that is has a lot of built in knowledge of how networks operate. So we are just going to tell pyATS to learn everything about the OSFP topology. You do this with the command.
$ genie learn ospf --testbed-file testbed1.yml --output ospf-start
This is telling Pyats to learn everything about OSPF on the devices defined in the testbed1.yml file and send the output to a folder called ospf-start.
This folder will get created if it does not exist.
Once this runs, you will now have a folder that contains a lot of information about everything related to OSPF. Too much information for you to go through by hand.
The real benefit of Pyats is that you can run this baseline test and then if you get an issue with OSPF or are experiencing network issues, you can run this test again and specify a different output folder and then compare the two files.
So now we have our baseline file ospf-start. Let’s disable an interface
CSR-1#conf t Enter configuration commands, one per line. End with CNTL/Z. CSR-1(config)#int Gi1 CSR-1(config-if)#no ip ospf 10 area 0 CSR-1(config-if)#
We will now run the genie learn command again but specify a different output folder
$ genie learn ospf --testbed-file testbed1.yml --output ospf-issue
A folder is now created called ospf-issue containing all the information about current state of ospf.
All we have to do now is to compare the baseline folder to the folder when the issue occured.
To do this issue the command
$ pyats diff ospf-original ospf-issue
Pyats will now give you a diff file which you can go into and see what differences there are on the network.
pyATS Genie Parsers
To see a full list of all the parsers available check this link
For more information check the Cisco Documentation:
This is just the tip of the iceberg of what can be achieved with pyATS. I will be digging deeper into this amazing tool very soon. You can integrate it with Ansible and Nornir.
It’s used by Cisco to do all the testing on their network before and after deploying and code so it’s battle tested and updated regularly.