Free tech learning for everyone, from basics to pro

Network AutomationNetworking SecurityAdvanced

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.

Testing the network with pyATSLearnsnapshot beforeChangeapply configLearn againsnapshot afterDiffwhat changedReportpass or fail
Figure 1. Before and after snapshots show exactly what a change did to the network state.

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?
A YAML file describing devices, their OS, credentials and connection details.
How can pyATS help in a change window?
By learning state before and after the change and showing a diff of what changed.
Why use environment variables for credentials in the testbed?
To avoid storing passwords in files that may be shared or committed to Git.

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.
Tracks your learning on this device only. See your progress on the learning paths.
Verified author✓ Valid
Issued to
Mohamed Fayas
Role
Founder of FM TecHub
Credentials
CCNABTEC HND Network EngineeringBEng (Hons) Computer Networking & Cloud Security
Issuer
FM TecHub · fmtechub.com

He writes practical, plain-English guides on networking, security and cloud.

More about the author →

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.

Email updates: coming soon

New notes, tools and security news from FM TecHub by email, explained simply. Free. We're not collecting email addresses yet; see our privacy policy.

PortServiceStatus
SMTP/25Email updatesopening soon

Meanwhile, stay connected: