Network testing with pyATS and Genie: snapshots, diffs and automated checks
In short: pyATS is a Python test framework from Cisco, and Genie adds parsers and models that learn device features into structured data. Engineers use it to capture network state before a change, capture it again afterwards, and see exactly what differs. Test scripts can check conditions such as all BGP neighbours being established, making changes safer and verification repeatable.
What pyATS adds
Manual verification after a change means logging into devices and scanning output. pyATS automates it: connect to many devices, collect structured state, and compare it or check it against expectations.
The testbed file
devices:
core1:
os: iosxe
type: router
credentials:
default:
username: "%ENV{NET_USER}"
password: "%ENV{NET_PASS}"
connections:
cli:
protocol: ssh
ip: 10.0.0.1
Credentials come from environment variables rather than being stored in the file.
Learning and comparing state
From the command line, capture snapshots before and after a change:
pyats learn ospf bgp interface --testbed-file testbed.yaml --output before
# make the change
pyats learn ospf bgp interface --testbed-file testbed.yaml --output after
pyats diff before after
The diff shows added, removed and changed values, such as a BGP neighbour now idle or an interface address changed.
A simple check in Python
from genie.testbed import load
tb = load("testbed.yaml")
dev = tb.devices["core1"]
dev.connect(log_stdout=False)
bgp = dev.parse("show ip bgp summary")
for vrf in bgp["vrf"].values():
for nbr, data in vrf["neighbor"].items():
for af in data["address_family"].values():
state = af.get("state_pfxrcd", "")
if not str(state).isdigit():
print(f"Neighbour {nbr} not established: {state}")
Parser output structures differ by command and platform; explore them with a quick print first.
Where it fits
- Pre and post checks in change windows.
- Automated tests in CI pipelines before and after deploying configuration.
- Regular health checks across the estate.
- Lab testing of new software versions.
Real-world example: catching a quiet failure
After a routine QoS change on 30 routers, users noticed nothing, but the pyATS diff showed that one router had lost two OSPF neighbours because a typo applied a policy to the wrong interface. The team fixed it within minutes, before the redundant path was needed.
Practice
What is the testbed file in pyATS?
How can pyATS help in a change window?
Why use environment variables for credentials in the testbed?
Key takeaways
- pyATS and Genie collect structured network state from devices.
- Before and after snapshots with diffs show the effect of changes.
- Python tests can assert conditions such as neighbours being up.
- Use it for change checks, pipelines and regular health tests.
Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.